From 6207c72d70b23ab514755dd0cb83f1b8c91e4269 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 14 Apr 2022 15:10:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=A2=9E=E5=8A=A0=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=88=90=E5=8A=9F=E5=92=8C=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 测试计划增加执行成功和失败的消息通知功能 --- .../api/service/ApiExecutionQueueService.java | 44 +++++++++- .../base/mapper/ext/ExtTestPlanMapper.xml | 5 +- .../commons/constants/ApiRunMode.java | 1 + .../commons/consumer/LoadTestConsumer.java | 8 +- .../notice/service/NoticeSendService.java | 12 --- .../track/service/TestPlanLoadCaseEvent.java | 39 --------- .../track/service/TestPlanReportService.java | 86 ++++++++++++------- .../track/service/TestPlanService.java | 83 +++++++++--------- .../track/TestPlanTaskNotification.vue | 4 +- 9 files changed, 149 insertions(+), 133 deletions(-) delete mode 100644 backend/src/main/java/io/metersphere/track/service/TestPlanLoadCaseEvent.java diff --git a/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java b/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java index 02ff42cf28..383de6d998 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java @@ -23,6 +23,7 @@ import io.metersphere.utils.LoggerUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -55,10 +56,9 @@ public class ApiExecutionQueueService { private ExtApiExecutionQueueMapper extApiExecutionQueueMapper; @Resource private ApiScenarioReportResultMapper apiScenarioReportResultMapper; + @Lazy @Resource - private TestPlanExecutionQueueMapper testPlanExecutionQueueMapper; - @Resource - private TestPlanReportMapper testPlanReportMapper; + private TestPlanReportService testPlanReportService; @Transactional(propagation = Propagation.REQUIRES_NEW) @@ -92,6 +92,22 @@ public class ApiExecutionQueueService { queueDetails.add(queue); detailMap.put(k, queue.getId()); }); + } else if (StringUtils.equalsIgnoreCase(type, ApiRunMode.TEST_PLAN_PERFORMANCE_TEST.name())) { + final int[] sort = {0}; + Map runMap = (Map) runObj; + if (config.getEnvMap() == null) { + config.setEnvMap(new LinkedHashMap<>()); + } + String envStr = JSON.toJSONString(config.getEnvMap()); + runMap.forEach((k, v) -> { + ApiExecutionQueueDetail queue = detail(v, k, "loadTest", sort[0], executionQueue.getId(), envStr); + if (sort[0] == 0) { + resQueue.setQueue(queue); + } + sort[0]++; + queueDetails.add(queue); + detailMap.put(k, queue.getId()); + }); } else { Map runMap = (Map) runObj; final int[] sort = {0}; @@ -304,7 +320,7 @@ public class ApiExecutionQueueService { // 计算一小时前的超时报告 final long timeout = System.currentTimeMillis() - (60 * MINUTE_MILLIS); ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample(); - example.createCriteria().andCreateTimeLessThan(timeout); + example.createCriteria().andCreateTimeLessThan(timeout).andTypeNotEqualTo("loadTest"); List queueDetails = executionQueueDetailMapper.selectByExample(example); for (ApiExecutionQueueDetail item : queueDetails) { @@ -416,4 +432,24 @@ public class ApiExecutionQueueService { } }); } + + public void checkExecutionQueneByLoadTest(LoadTestReport loadTestReport) { + + ApiExecutionQueueDetailExample detailExample = new ApiExecutionQueueDetailExample(); + detailExample.createCriteria().andReportIdEqualTo(loadTestReport.getId()); + List detailList = executionQueueDetailMapper.selectByExample(detailExample); + if (CollectionUtils.isNotEmpty(detailList)) { + List executionQueueIdList = new ArrayList<>(); + detailList.forEach(item -> { + executionQueueIdList.add(item.getQueueId()); + }); + executionQueueDetailMapper.deleteByExample(detailExample); + } + + List testPlanReportIdList = testPlanReportService.getTestPlanReportIdsByLoadTestReportId(loadTestReport.getId()); + for (String testPlanReportId : testPlanReportIdList) { + this.testPlanReportTestEnded(testPlanReportId); + } + + } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml index 055adb1d9c..e7cffd9aa2 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml @@ -317,9 +317,8 @@