diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.java index b9507152ee..20ca461c98 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.java +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.java @@ -2,9 +2,10 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.TestPlanExecutionQueue; import io.metersphere.base.domain.TestPlanExecutionQueueExample; -import java.util.List; import org.apache.ibatis.annotations.Param; +import java.util.List; + public interface TestPlanExecutionQueueMapper { long countByExample(TestPlanExecutionQueueExample example); @@ -27,4 +28,5 @@ public interface TestPlanExecutionQueueMapper { int updateByPrimaryKeySelective(TestPlanExecutionQueue record); int updateByPrimaryKey(TestPlanExecutionQueue record); + } diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiExecutionQueueMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiExecutionQueueMapper.java new file mode 100644 index 0000000000..7c6e24e8f6 --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiExecutionQueueMapper.java @@ -0,0 +1,8 @@ +package io.metersphere.base.mapper.ext; + +import java.util.List; + +public interface ExtApiExecutionQueueMapper { + List selectIdByReportIdIsNull(); +} + diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiExecutionQueueMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiExecutionQueueMapper.xml new file mode 100644 index 0000000000..ded0a57ce5 --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiExecutionQueueMapper.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java index f8ebb28101..418f957f5d 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java @@ -2,7 +2,6 @@ package io.metersphere.plan.service; import io.metersphere.base.domain.TestPlanWithBLOBs; import io.metersphere.base.mapper.TestPlanMapper; -import io.metersphere.base.mapper.ext.ExtTestPlanMapper; import io.metersphere.commons.constants.TestPlanReportStatus; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; @@ -10,12 +9,10 @@ import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.*; import io.metersphere.plan.dto.ExecutionWay; import io.metersphere.plan.request.api.TestPlanRunRequest; -import io.metersphere.plan.service.remote.api.PlanApiAutomationService; import io.metersphere.plan.service.remote.api.PlanTestPlanApiCaseService; import io.metersphere.plan.service.remote.api.PlanTestPlanScenarioCaseService; import io.metersphere.plan.service.remote.performance.PerfExecService; import io.metersphere.plan.service.remote.ui.PlanTestPlanUiScenarioCaseService; -import io.metersphere.plan.service.remote.ui.PlanUiAutomationService; import io.metersphere.plan.utils.TestPlanRequestUtil; import io.metersphere.utils.LoggerUtil; import jakarta.annotation.Resource; @@ -45,15 +42,9 @@ public class TestPlanExecuteService { private PerfExecService perfExecService; @Resource private PlanTestPlanUiScenarioCaseService planTestPlanUiScenarioCaseService; - @Resource - private PlanApiAutomationService planApiAutomationService; - @Resource - private PlanUiAutomationService planUiAutomationService; @Resource private TestPlanMapper testPlanMapper; - @Resource - private ExtTestPlanMapper extTestPlanMapper; /** * 执行测试计划流程是会调用其它服务的执行方法,并通过kafka传递信息给test-track服务来判断测试计划是否执行结束 diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index 8ad5882c5f..b876d4e95e 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -124,6 +124,12 @@ public class TestPlanReportService { @Lazy @Resource private IssuesService issuesService; + @Resource + private ApiExecutionQueueMapper apiExecutionQueueMapper; + @Resource + private ApiExecutionQueueDetailMapper apiExecutionQueueDetailMapper; + @Resource + private ExtApiExecutionQueueMapper extApiExecutionQueueMapper; private final String GROUP = "GROUP"; @@ -872,7 +878,6 @@ public class TestPlanReportService { TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); contentExample.createCriteria().andTestPlanReportIdIn(testPlanReportIdList); testPlanReportContentMapper.deleteByExample(contentExample); - // todo 删除场景、接口的报告 BatchProcessingUtil.batchDeleteApiReport(testPlanReportIdList, this::deleteApiCaseReportByTestPlanExecute, this::deleteScenarioReportByTestPlanExecute, this::deleteUiReportByTestPlanExecute); } } @@ -1687,6 +1692,39 @@ public class TestPlanReportService { LogUtil.info("开始处理服务重启导致执行未完成的报告状态"); extTestPlanReportMapper.updateAllStatus(); LogUtil.info("处理服务重启导致执行未完成的报告状态完成"); + LogUtil.info("开始清除测试计划相关的执行队列"); + this.deleteAllQueue(); + LogUtil.info("清除测试计划相关的执行队列完成"); + } + + public void deleteAllQueue() { + LogUtil.info("开始清除测试计划的资源执行队列"); + //删除测试计划资源执行队列 + List queueDeleteIdList = extApiExecutionQueueMapper.selectIdByReportIdIsNull(); + if (CollectionUtils.isNotEmpty(queueDeleteIdList)) { + BatchProcessingUtil.consumerByStringList(queueDeleteIdList, this::deleteApiExecutionQueueDetail); + BatchProcessingUtil.consumerByStringList(queueDeleteIdList, this::deleteApiExecutionQueue); + } + LogUtil.info("开始清除测试计划的批量串行执行队列"); + //删除测试计划串行队列 + TestPlanExecutionQueueExample example = new TestPlanExecutionQueueExample(); + testPlanExecutionQueueMapper.deleteByExample(example); + } + + public void deleteApiExecutionQueue(List queueIdList) { + if (CollectionUtils.isNotEmpty(queueIdList)) { + ApiExecutionQueueExample example = new ApiExecutionQueueExample(); + example.createCriteria().andIdIn(queueIdList); + apiExecutionQueueMapper.deleteByExample(example); + } + } + + public void deleteApiExecutionQueueDetail(List queueIdList) { + if (CollectionUtils.isNotEmpty(queueIdList)) { + ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample(); + example.createCriteria().andQueueIdIn(queueIdList); + apiExecutionQueueDetailMapper.deleteByExample(example); + } } public String getLastReportByPlanId(String planId) { diff --git a/test-track/backend/src/main/java/io/metersphere/utils/BatchProcessingUtil.java b/test-track/backend/src/main/java/io/metersphere/utils/BatchProcessingUtil.java index ba669d5688..3864c785d9 100644 --- a/test-track/backend/src/main/java/io/metersphere/utils/BatchProcessingUtil.java +++ b/test-track/backend/src/main/java/io/metersphere/utils/BatchProcessingUtil.java @@ -16,11 +16,29 @@ public class BatchProcessingUtil { private static final int BATCH_PROCESS_QUANTITY = 100; + //批量处理参数是List的函数 + public static void consumerByStringList(List stringList, Consumer> consumer) { + if (CollectionUtils.isNotEmpty(stringList)) { + int foreachIndex = 0; + int foreachCount = stringList.size() / BATCH_PROCESS_QUANTITY; + while (BATCH_PROCESS_QUANTITY < stringList.size() || (foreachIndex > foreachCount)) { + List handleList = stringList.subList(0, BATCH_PROCESS_QUANTITY); + consumer.accept(handleList); + stringList.removeAll(handleList); + + //记录循环次数,防止出现死循环 + foreachIndex++; + } + //处理剩余数据 + if (CollectionUtils.isNotEmpty(stringList)) { + consumer.accept(stringList); + } + } + } + public static void batchDeleteApiReport(List testPlanReportIdList, Consumer> deleteApiCaseReportFunc, Consumer> deleteScenarioReportFunc, Consumer> deleteUiReportFunc) { if (CollectionUtils.isNotEmpty(testPlanReportIdList)) { - int unDeleteReportIdCount = testPlanReportIdList.size(); - while (BATCH_PROCESS_QUANTITY < testPlanReportIdList.size()) { List deleteReportIds = testPlanReportIdList.subList(0, BATCH_PROCESS_QUANTITY); deleteApiCaseReportFunc.accept(deleteReportIds);