refactor(测试计划): 优化测试计划并发执行快速生成测试计划报告

This commit is contained in:
fit2-zhao 2022-02-23 15:00:46 +08:00 committed by fit2-zhao
parent f7bc3afaa1
commit 6df644acbb
1 changed files with 27 additions and 20 deletions

View File

@ -21,26 +21,33 @@ public class ApiScenarioParallelService {
private JMeterService jMeterService; private JMeterService jMeterService;
public void parallel(Map<String, RunModeDataDTO> executeQueue, RunScenarioRequest request, String serialReportId, DBTestQueue executionQueue) { public void parallel(Map<String, RunModeDataDTO> executeQueue, RunScenarioRequest request, String serialReportId, DBTestQueue executionQueue) {
for (String reportId : executeQueue.keySet()) { Thread thread = new Thread(new Runnable() {
RunModeDataDTO dataDTO = executeQueue.get(reportId); @Override
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(dataDTO.getTestId(), StringUtils.isNotEmpty(serialReportId) ? serialReportId : reportId, request.getRunMode(), null); public void run() {
runRequest.setReportType(StringUtils.isNotEmpty(serialReportId) ? RunModeConstants.SET_REPORT.toString() : RunModeConstants.INDEPENDENCE.toString()); Thread.currentThread().setName("SCENARIO-PARALLEL-THREAD");
runRequest.setQueueId(executionQueue.getId()); for (String reportId : executeQueue.keySet()) {
if (request.getConfig() != null) { RunModeDataDTO dataDTO = executeQueue.get(reportId);
runRequest.setPool(GenerateHashTreeUtil.isResourcePool(request.getConfig().getResourcePoolId())); JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(dataDTO.getTestId(), StringUtils.isNotEmpty(serialReportId) ? serialReportId : reportId, request.getRunMode(), null);
runRequest.setPoolId(request.getConfig().getResourcePoolId()); runRequest.setReportType(StringUtils.isNotEmpty(serialReportId) ? RunModeConstants.SET_REPORT.toString() : RunModeConstants.INDEPENDENCE.toString());
runRequest.setQueueId(executionQueue.getId());
if (request.getConfig() != null) {
runRequest.setPool(GenerateHashTreeUtil.isResourcePool(request.getConfig().getResourcePoolId()));
runRequest.setPoolId(request.getConfig().getResourcePoolId());
}
runRequest.setTestPlanReportId(request.getTestPlanReportId());
runRequest.setPlatformUrl(executionQueue.getDetailMap().get(reportId));
runRequest.setRunType(RunModeConstants.PARALLEL.toString());
if (LoggerUtil.getLogger().isDebugEnabled()) {
LoggerUtil.debug("Scenario run-开始并发执行:" + JSON.toJSONString(request));
}
// 本地执行生成hashTree
if (request.getConfig() != null && !runRequest.getPool().isPool()) {
runRequest.setHashTree(GenerateHashTreeUtil.generateHashTree(dataDTO.getScenario(), dataDTO.getPlanEnvMap(), runRequest));
}
jMeterService.run(runRequest);
}
} }
runRequest.setTestPlanReportId(request.getTestPlanReportId()); });
runRequest.setPlatformUrl(executionQueue.getDetailMap().get(reportId)); thread.start();
runRequest.setRunType(RunModeConstants.PARALLEL.toString());
if (LoggerUtil.getLogger().isDebugEnabled()) {
LoggerUtil.debug("Scenario run-开始并发执行:" + JSON.toJSONString(request));
}
// 本地执行生成hashTree
if (request.getConfig() != null && !runRequest.getPool().isPool()) {
runRequest.setHashTree(GenerateHashTreeUtil.generateHashTree(dataDTO.getScenario(), dataDTO.getPlanEnvMap(), runRequest));
}
jMeterService.run(runRequest);
}
} }
} }