diff --git a/backend/src/main/java/io/metersphere/commons/consumer/LoadTestConsumer.java b/backend/src/main/java/io/metersphere/commons/consumer/LoadTestConsumer.java index abd8bfb964..97038f96b2 100644 --- a/backend/src/main/java/io/metersphere/commons/consumer/LoadTestConsumer.java +++ b/backend/src/main/java/io/metersphere/commons/consumer/LoadTestConsumer.java @@ -2,7 +2,6 @@ package io.metersphere.commons.consumer; import com.alibaba.fastjson.JSON; import io.metersphere.Application; -import io.metersphere.api.service.ApiExecutionQueueService; import io.metersphere.base.domain.LoadTestReport; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; @@ -12,7 +11,6 @@ import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; import java.util.Set; @Service @@ -20,9 +18,6 @@ import java.util.Set; public class LoadTestConsumer { public static final String CONSUME_ID = "load-test-data"; - @Resource - ApiExecutionQueueService apiExecutionQueueService; - @KafkaListener(id = CONSUME_ID, topics = "${kafka.test.topic}", groupId = "${spring.kafka.consumer.group-id}") public void consume(ConsumerRecord record) { LoadTestReport loadTestReport = JSON.parseObject(record.value(), LoadTestReport.class); @@ -35,7 +30,5 @@ public class LoadTestConsumer { LogUtil.error(e); } }); - //删除性能测试在执行队列中的数据 (在测试计划执行中会将性能测试执行添加到执行队列,用于判断整个测试计划到执行进度) - apiExecutionQueueService.checkExecutionQueneByLoadTest(loadTestReport); } } diff --git a/backend/src/main/java/io/metersphere/performance/notice/PerformanceQueueEvent.java b/backend/src/main/java/io/metersphere/performance/notice/PerformanceQueueEvent.java new file mode 100644 index 0000000000..afafe44c1c --- /dev/null +++ b/backend/src/main/java/io/metersphere/performance/notice/PerformanceQueueEvent.java @@ -0,0 +1,35 @@ +package io.metersphere.performance.notice; + +import com.alibaba.fastjson.JSONObject; +import io.metersphere.api.service.ApiExecutionQueueService; +import io.metersphere.base.domain.LoadTestReport; +import io.metersphere.commons.consumer.LoadTestFinishEvent; +import io.metersphere.commons.utils.LogUtil; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +public class PerformanceQueueEvent implements LoadTestFinishEvent { + @Resource + ApiExecutionQueueService apiExecutionQueueService; + + public void sendNotice(LoadTestReport loadTestReport) { + //删除性能测试在执行队列中的数据 (在测试计划执行中会将性能测试执行添加到执行队列,用于判断整个测试计划到执行进度) + try { + apiExecutionQueueService.checkExecutionQueneByLoadTest(loadTestReport); + } catch (Exception e) { + LogUtil.error("PerformanceQueueEvent error. id:" + loadTestReport.getId()); + } + } + + @Override + public void execute(LoadTestReport loadTestReport) { + LogUtil.info("PerformanceQueueEvent start. id:" + loadTestReport.getId() + ", DATA:" + JSONObject.toJSONString(loadTestReport)); + if (StringUtils.isNotEmpty(loadTestReport.getId())) { + sendNotice(loadTestReport); + } + LogUtil.info("PerformanceQueueEvent OVER. id:" + loadTestReport.getId()); + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index c03db2b729..c3561c19f3 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -1088,10 +1088,12 @@ public class TestPlanService { } } + if(MapUtils.isNotEmpty(loadCaseReportMap)){ + //将性能测试加入到队列中 + apiExecutionQueueService.add(loadCaseReportMap, null, ApiRunMode.TEST_PLAN_PERFORMANCE_TEST.name(), + planReportId, null, null, new RunModeConfigDTO()); + } - //将性能测试加入到队列中 - apiExecutionQueueService.add(loadCaseReportMap, null, ApiRunMode.TEST_PLAN_PERFORMANCE_TEST.name(), - planReportId, null, null, new RunModeConfigDTO()); return loadCaseReportMap; }