Implementation:APIJSON APIJSON Demo AutoTestRegressionScheduler
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Testing, Automation, DevOps |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Concrete tool for scheduling and executing automated API regression tests via cron triggers, polling for results, and sending email notifications provided by the APIJSON Demo server.
Description
The AutoTestRegressionScheduler class is a Spring @Service that runs scheduled API regression tests against the APIAuto Node.js test runner. It:
- Schedules tests: Uses
@Scheduled(cron)to trigger at configured times (default: 10:00 and 20:00 Asia/Shanghai). - Prevents overlap: Uses
AtomicBoolean runningwithcompareAndSetto skip if a previous run is still active. - Starts the test runner: Calls
AutoTestNodeProcessSupervisor.ensureRunning()before starting. - Triggers test execution: Sends HTTP GET to the APIAuto
startUrlwith a unique session key. - Polls for completion: Loops calling
statusUrl, parsingprogress(BigDecimal 0-1) andreportIdfrom JSON response. - Handles timeouts: If
progressdoesn't reach 1.0 withintimeoutMinutes, sets an error message. - Sends email: Composes an HTML email with start/end time, duration, progress, report URL, and sends via
JavaMailSender. - Manages sessions: Uses
BackgroundHttpSessionwith cookie management for authenticated test runs.
Usage
- Automatic scheduling: Runs automatically based on cron expression — no manual invocation needed.
- Configuration: All parameters are injectable via
@Valuefromapplication.yml. - Disabling: Set
apijson.auto-test.enabled=falseto disable.
Code Reference
Source Location
- Repository: APIJSON-Demo
- File: APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/AutoTestRegressionScheduler.java
Signature
@Service
public class AutoTestRegressionScheduler {
@Value("${apijson.auto-test.enabled:true}") private boolean enabled;
@Value("${apijson.auto-test.start-url:...}") private String startUrl;
@Value("${apijson.auto-test.status-url:...}") private String statusUrl;
@Value("${apijson.auto-test.poll-interval-millis:15000}") private long pollIntervalMillis;
@Value("${apijson.auto-test.timeout-minutes:180}") private long timeoutMinutes;
@Value("${apijson.auto-test.mail.from:}") private String mailFrom;
@Value("${apijson.auto-test.mail.to:}") private String mailTo;
@Scheduled(cron = "${apijson.auto-test.cron:0 0 10,20 * * *}",
zone = "${apijson.auto-test.zone:Asia/Shanghai}")
public void runScheduledApiRegression();
private TestExecutionResult executeRegressionTest(ZoneId zoneId);
private String doGet(HttpSession session, String url);
private void sendReportEmail(TestExecutionResult result);
private String buildMailSubject(TestExecutionResult result);
private String buildMailHtml(TestExecutionResult result);
}
Import
import apijson.boot.AutoTestRegressionScheduler;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| cron | String | No | Cron expression (default: 0 0 10,20 * * *)
|
| startUrl | String | No | APIAuto test start endpoint |
| statusUrl | String | No | APIAuto test status endpoint |
| pollIntervalMillis | long | No | Polling interval (default: 15000ms) |
| timeoutMinutes | long | No | Max test duration (default: 180min) |
| mailTo | String | No | Comma-separated email recipients |
Outputs
| Name | Type | Description |
|---|---|---|
| MimeMessage | HTML email with test results summary | |
| TestExecutionResult | (internal) | Contains startedAt, finishedAt, progress, reportId, errorMessage |
Usage Examples
application.yml Configuration
apijson:
auto-test:
enabled: true
cron: "0 0 10,20 * * *"
zone: Asia/Shanghai
start-url: http://localhost:3000/test/start
status-url: http://localhost:3000/test/status
poll-interval-millis: 15000
timeout-minutes: 180
mail:
from: noreply@example.com
to: team@example.com, qa@example.com
subject-prefix: "[APIJSON]"
Polling Loop Logic
// executeRegressionTest:
long deadline = System.currentTimeMillis() + timeoutMinutes * 60_000L;
while (System.currentTimeMillis() < deadline) {
result.statusResponseBody = doGet(session, statusUrl);
result.status = parseObject(result.statusResponseBody);
result.progress = readDecimal(result.status, "progress");
result.reportId = readLong(result.status, "reportId");
if (result.progress != null && result.progress.compareTo(BigDecimal.ONE) >= 0) {
break; // Test complete
}
sleep(Math.max(pollIntervalMillis, 1000L));
}
Related Pages
Implements Principle
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment