refactor(接口测试): 优化用例和场景批量执行
This commit is contained in:
parent
44bf144594
commit
6a9983903d
|
@ -116,17 +116,20 @@ public class ApiCaseExecuteService {
|
|||
DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.API_PLAN.name(), request.getPlanReportId(), reportType, runMode, request.getConfig());
|
||||
|
||||
// 开始选择执行模式
|
||||
if (deQueue != null && deQueue.getQueue() != null) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("PLAN-CASE:" + request.getPlanReportId());
|
||||
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
|
||||
LoggerUtil.debug("开始串行执行");
|
||||
if (deQueue != null && deQueue.getQueue() != null) {
|
||||
apiScenarioSerialService.serial(deQueue, deQueue.getQueue());
|
||||
}
|
||||
} else {
|
||||
LoggerUtil.debug("开始并发执行");
|
||||
if (deQueue != null && deQueue.getQueue() != null) {
|
||||
apiCaseParallelExecuteService.parallel(executeQueue, request.getConfig(), deQueue, runMode);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
return responseDTOS;
|
||||
}
|
||||
|
||||
|
@ -153,8 +156,8 @@ public class ApiCaseExecuteService {
|
|||
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
example.createCriteria().andIdIn(request.getIds());
|
||||
List<ApiTestCaseWithBLOBs> list = apiTestCaseMapper.selectByExampleWithBLOBs(example);
|
||||
LoggerUtil.debug("查询到执行数据:" + list.size());
|
||||
List<ApiTestCaseWithBLOBs> caseList = apiTestCaseMapper.selectByExampleWithBLOBs(example);
|
||||
LoggerUtil.debug("查询到执行数据:" + caseList.size());
|
||||
|
||||
// 集合报告设置
|
||||
String serialReportId = null;
|
||||
|
@ -164,7 +167,7 @@ public class ApiCaseExecuteService {
|
|||
APIScenarioReportResult report = apiScenarioReportService.init(request.getConfig().getReportId(), null, request.getConfig().getReportName(),
|
||||
ReportTriggerMode.MANUAL.name(), ExecuteType.Saved.name(), request.getProjectId(),
|
||||
null, request.getConfig());
|
||||
report.setVersionId(list.get(0).getVersionId());
|
||||
report.setVersionId(caseList.get(0).getVersionId());
|
||||
report.setName(request.getConfig().getReportName());
|
||||
report.setTestName(request.getConfig().getReportName());
|
||||
report.setId(serialReportId);
|
||||
|
@ -182,7 +185,7 @@ public class ApiCaseExecuteService {
|
|||
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
||||
fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
|
||||
BeanComparator beanComparator = new BeanComparator("id", fixedOrderComparator);
|
||||
Collections.sort(list, beanComparator);
|
||||
Collections.sort(caseList, beanComparator);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +198,7 @@ public class ApiCaseExecuteService {
|
|||
String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? APITestStatus.Waiting.name() : APITestStatus.Running.name();
|
||||
|
||||
String finalSerialReportId = serialReportId;
|
||||
list.forEach(caseWithBLOBs -> {
|
||||
caseList.forEach(caseWithBLOBs -> {
|
||||
ApiDefinitionExecResult report = ApiDefinitionExecResultUtil.initBase(caseWithBLOBs.getId(), APITestStatus.Running.name(), null, request.getConfig());
|
||||
report.setStatus(status);
|
||||
report.setName(caseWithBLOBs.getName());
|
||||
|
@ -214,17 +217,20 @@ public class ApiCaseExecuteService {
|
|||
String poolId = request.getConfig().getResourcePoolId();
|
||||
DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.DEFINITION.name(), finalSerialReportId, reportType, ApiRunMode.DEFINITION.name(), request.getConfig());
|
||||
// 开始选择执行模式
|
||||
if (deQueue != null && deQueue.getQueue() != null) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("API-CASE-RUN");
|
||||
if (request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
|
||||
LoggerUtil.debug("开始串行执行");
|
||||
if (deQueue != null && deQueue.getQueue() != null) {
|
||||
apiScenarioSerialService.serial(deQueue, deQueue.getQueue());
|
||||
}
|
||||
} else {
|
||||
LoggerUtil.debug("开始并发执行");
|
||||
if (deQueue != null && deQueue.getQueue() != null) {
|
||||
apiCaseParallelExecuteService.parallel(executeQueue, request.getConfig(), deQueue, ApiRunMode.DEFINITION.name());
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
return responseDTOS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,6 @@ public class ApiCaseParallelExecuteService {
|
|||
private JMeterService jMeterService;
|
||||
|
||||
public void parallel(Map<String, ApiDefinitionExecResult> executeQueue, RunModeConfigDTO config, DBTestQueue executionQueue, String runMode) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("API-CASE-THREAD");
|
||||
for (String testId : executeQueue.keySet()) {
|
||||
ApiDefinitionExecResult result = executeQueue.get(testId);
|
||||
String reportId = result.getId();
|
||||
|
@ -47,7 +43,4 @@ public class ApiCaseParallelExecuteService {
|
|||
jMeterService.run(runRequest);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,11 +173,20 @@ public class ApiScenarioExecuteService {
|
|||
apiScenarioReportService.batchSave(executeQueue, serialReportId, request.getRunMode(), responseDTOS);
|
||||
|
||||
// 开始执行
|
||||
String finalSerialReportId = serialReportId;
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("SCENARIO-PARALLEL-THREAD");
|
||||
if (StringUtils.equals(request.getConfig().getMode(), RunModeConstants.SERIAL.toString())) {
|
||||
serialService.serial(executionQueue, executionQueue.getQueue());
|
||||
} else {
|
||||
parallelService.parallel(executeQueue, request, serialReportId, executionQueue);
|
||||
parallelService.parallel(executeQueue, request, finalSerialReportId, executionQueue);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
|
||||
return responseDTOS;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,6 @@ public class ApiScenarioParallelService {
|
|||
private JMeterService jMeterService;
|
||||
|
||||
public void parallel(Map<String, RunModeDataDTO> executeQueue, RunScenarioRequest request, String serialReportId, DBTestQueue executionQueue) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("SCENARIO-PARALLEL-THREAD");
|
||||
for (String reportId : executeQueue.keySet()) {
|
||||
RunModeDataDTO dataDTO = executeQueue.get(reportId);
|
||||
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(dataDTO.getTestId(), StringUtils.isNotEmpty(serialReportId) ? serialReportId : reportId, request.getRunMode(), null);
|
||||
|
@ -47,7 +43,4 @@ public class ApiScenarioParallelService {
|
|||
jMeterService.run(runRequest);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue