From 555a70d74509e28773325a02d056205b04d3d494 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 16 Jun 2021 19:12:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E6=B6=88=E6=81=AF=E6=9F=A5=E8=AF=A2=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiAutomationService.java | 74 ++++++++++--------- .../base/mapper/ext/ExtTaskMapper.xml | 4 +- .../business/components/task/TaskCenter.vue | 5 +- 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index a53d1908fe..4d8ae39214 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -980,48 +980,50 @@ public class ApiAutomationService { private void run(Map map, RunScenarioRequest request, String serialReportId) { // 开始选择执行模式 - ExecutorService executorService = Executors.newFixedThreadPool(map.size()); - if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) { - // 开始串行执行 - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - List reportIds = new LinkedList<>(); - for (APIScenarioReportResult key : map.keySet()) { - apiScenarioReportMapper.insert(key); - reportIds.add(key.getId()); - try { - Future future = executorService.submit(new SerialScenarioExecTask(jMeterService, apiScenarioReportMapper, map.get(key), request)); - ApiScenarioReport report = future.get(); - // 如果开启失败结束执行,则判断返回结果状态 - if (request.getConfig().isOnSampleError()) { - if (report == null || !report.getStatus().equals("Success")) { - break; + if (map != null && map.size() > 0) { + ExecutorService executorService = Executors.newFixedThreadPool(map.size()); + if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) { + // 开始串行执行 + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + List reportIds = new LinkedList<>(); + for (APIScenarioReportResult key : map.keySet()) { + apiScenarioReportMapper.insert(key); + reportIds.add(key.getId()); + try { + Future future = executorService.submit(new SerialScenarioExecTask(jMeterService, apiScenarioReportMapper, map.get(key), request)); + ApiScenarioReport report = future.get(); + // 如果开启失败结束执行,则判断返回结果状态 + if (request.getConfig().isOnSampleError()) { + if (report == null || !report.getStatus().equals("Success")) { + break; + } } + } catch (Exception e) { + LogUtil.error("执行终止:" + e.getMessage()); + break; } - } catch (Exception e) { - LogUtil.error("执行终止:" + e.getMessage()); - break; + } + // 更新集成报告 + if (StringUtils.isNotEmpty(serialReportId)) { + apiScenarioReportService.margeReport(serialReportId, reportIds); + map.clear(); } } - // 更新集成报告 - if (StringUtils.isNotEmpty(serialReportId)) { - apiScenarioReportService.margeReport(serialReportId, reportIds); - map.clear(); - } + }); + thread.start(); + } else { + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); + // 开始并发执行 + for (APIScenarioReportResult report : map.keySet()) { + //存储报告 + batchMapper.insert(report); + executorService.submit(new ParallelScenarioExecTask(jMeterService, map.get(report), request)); } - }); - thread.start(); - } else { - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); - // 开始并发执行 - for (APIScenarioReportResult report : map.keySet()) { - //存储报告 - batchMapper.insert(report); - executorService.submit(new ParallelScenarioExecTask(jMeterService, map.get(report), request)); + sqlSession.flushStatements(); } - sqlSession.flushStatements(); } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml index d4bc09966d..9398c0b1b3 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml @@ -4,14 +4,14 @@