From 6df644acbbd13b90d89e68ea105e6937c7ad0e04 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 23 Feb 2022 15:00:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E6=89=A7=E8=A1=8C=E5=BF=AB=E9=80=9F=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scenario/ApiScenarioParallelService.java | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioParallelService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioParallelService.java index 0650541756..a1d4a8145c 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioParallelService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioParallelService.java @@ -21,26 +21,33 @@ public class ApiScenarioParallelService { private JMeterService jMeterService; public void parallel(Map executeQueue, RunScenarioRequest request, String serialReportId, DBTestQueue executionQueue) { - for (String reportId : executeQueue.keySet()) { - RunModeDataDTO dataDTO = executeQueue.get(reportId); - JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(dataDTO.getTestId(), StringUtils.isNotEmpty(serialReportId) ? serialReportId : reportId, request.getRunMode(), null); - 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()); + 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); + 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)); - 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); - } + }); + thread.start(); } }