diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 5c695226ea..bf200a4aa5 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -182,7 +182,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl apiDefinitionExecResultService.saveApiResultByScheduleTask(testResult, ApiRunMode.SCHEDULE_API_PLAN.name()); List testPlanReportIdList = new ArrayList<>(); testPlanReportIdList.add(debugReportId); - testPlanReportService.updateReport(testPlanReportIdList,ApiRunMode.SCHEDULE_API_PLAN.name()); + testPlanReportService.updateReport(testPlanReportIdList,ApiRunMode.SCHEDULE_API_PLAN.name(),ReportTriggerMode.SCHEDULE.name()); }else { apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.API_PLAN.name()); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index aa4c1a6d43..c95e120b44 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -16,6 +16,7 @@ import io.metersphere.base.mapper.ApiScenarioReportMapper; import io.metersphere.base.mapper.TestPlanApiScenarioMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.ReportTriggerMode; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.DateUtils; @@ -215,7 +216,7 @@ public class ApiScenarioReportService { } TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class); - testPlanReportService.updateReport(testPlanReportIdList,ApiRunMode.SCHEDULE_SCENARIO_PLAN.name()); + testPlanReportService.updateReport(testPlanReportIdList,ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ReportTriggerMode.SCHEDULE.name()); return lastReport; } 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 672c4f437b..1c7ab3e819 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 @@ -98,8 +98,9 @@ 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 f6587c7bea..a7727dd6f7 100644 --- a/backend/src/main/java/io/metersphere/commons/consumer/LoadTestConsumer.java +++ b/backend/src/main/java/io/metersphere/commons/consumer/LoadTestConsumer.java @@ -5,6 +5,7 @@ import io.metersphere.Application; import io.metersphere.base.domain.LoadTestReport; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.config.KafkaProperties; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.reflections8.Reflections; import org.springframework.kafka.annotation.KafkaListener; @@ -21,6 +22,8 @@ public class LoadTestConsumer { LoadTestReport loadTestReport = JSON.parseObject(record.value(), LoadTestReport.class); Reflections reflections = new Reflections(Application.class); Set> subTypes = reflections.getSubTypesOf(LoadTestFinishEvent.class); + LogUtil.info("Execute Over: LoadTestConsumer"); + System.out.println("Execute Over: LoadTestConsumer"); subTypes.forEach(s -> { try { CommonBeanFactory.getBean(s).execute(loadTestReport); diff --git a/backend/src/main/java/io/metersphere/job/sechedule/TestPlanTestJob.java b/backend/src/main/java/io/metersphere/job/sechedule/TestPlanTestJob.java index 5a930e0bac..b7fce2c7fd 100644 --- a/backend/src/main/java/io/metersphere/job/sechedule/TestPlanTestJob.java +++ b/backend/src/main/java/io/metersphere/job/sechedule/TestPlanTestJob.java @@ -12,7 +12,6 @@ import io.metersphere.base.domain.*; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ReportTriggerMode; import io.metersphere.commons.constants.ScheduleGroup; -import io.metersphere.commons.consumer.LoadTestFinishEvent; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import io.metersphere.performance.service.PerformanceTestService; @@ -25,6 +24,8 @@ import org.quartz.*; import javax.annotation.Resource; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * 情景测试Job @@ -102,7 +103,7 @@ public class TestPlanTestJob extends MsScheduleJob { void businessExecute(JobExecutionContext context) { LogUtil.info("-------------- start testplan schedule ----------"); //首先创建testPlanReport,然后返回的ID重新赋值为resourceID,作为后续的参数 - TestPlanReport testPlanReport = testPlanReportService.genTestPlanReport(this.resourceId,this.userId); + TestPlanReport testPlanReport = testPlanReportService.genTestPlanReport(this.resourceId,this.userId,ReportTriggerMode.SCHEDULE.name()); //执行接口案例任务 for (Map.Entry entry: this.apiTestCaseIdMap.entrySet()) { String apiCaseID = entry.getKey(); @@ -127,39 +128,38 @@ public class TestPlanTestJob extends MsScheduleJob { scenarioRequest.setTestPlanID(this.resourceId); scenarioRequest.setRunMode(ApiRunMode.SCHEDULE_SCENARIO_PLAN.name()); scenarioRequest.setTestPlanReportId(testPlanReport.getId()); - String reportID = apiAutomationService.run(scenarioRequest); + apiAutomationService.run(scenarioRequest); LogUtil.info("-------------- testplan schedule ---------- scenario case over -----------------"); //执行性能测试任务 - boolean havePerformanceTask = false; List performaneReportIDList = new ArrayList<>(); for (Map.Entry entry: this.performanceIdMap.entrySet()) { String id = entry.getKey(); String caseID = entry.getValue(); RunTestPlanRequest performanceRequest = new RunTestPlanRequest(); - performanceRequest.setId(id); + performanceRequest.setId(caseID); performanceRequest.setTestPlanLoadId(caseID); performanceRequest.setTriggerMode(ReportTriggerMode.SCHEDULE.name()); String reportId = null; - havePerformanceTask = true; - try { reportId = performanceTestService.run(performanceRequest); + if(reportId!=null){ + performaneReportIDList.add(reportId); + + TestPlanLoadCase testPlanLoadCase = new TestPlanLoadCase(); + testPlanLoadCase.setId(performanceRequest.getTestPlanLoadId()); + testPlanLoadCase.setLoadReportId(reportId); + testPlanLoadCaseService.update(testPlanLoadCase); + } }catch (Exception e){ - } - if(reportID!=null){ - TestPlanLoadCase testPlanLoadCase = new TestPlanLoadCase(); - testPlanLoadCase.setId(performanceRequest.getTestPlanLoadId()); - testPlanLoadCase.setLoadReportId(reportId); - testPlanLoadCaseService.update(testPlanLoadCase); - performaneReportIDList.add(reportID); + e.printStackTrace(); } } if(!performaneReportIDList.isEmpty()){ //性能测试时保存性能测试报告ID,在结果返回时用于捕捉并进行 - testPlanReportService.updatePerformanceInfo(testPlanReport,performaneReportIDList); + testPlanReportService.updatePerformanceInfo(testPlanReport,performaneReportIDList,ReportTriggerMode.SCHEDULE.name()); } } diff --git a/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeEvent.java b/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeEvent.java index 860e996d5f..d0f2cf2b83 100644 --- a/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeEvent.java +++ b/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeEvent.java @@ -5,6 +5,7 @@ import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.constants.ReportTriggerMode; import io.metersphere.commons.consumer.LoadTestFinishEvent; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.i18n.Translator; import io.metersphere.notice.sender.NoticeModel; @@ -70,6 +71,7 @@ public class PerformanceNoticeEvent implements LoadTestFinishEvent { @Override public void execute(LoadTestReport loadTestReport) { + LogUtil.info("PerformanceNoticeEvent OVER:" + loadTestReport.getTriggerMode()+";"+loadTestReport.getStatus()); if (StringUtils.equals(ReportTriggerMode.API.name(), loadTestReport.getTriggerMode()) || StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), loadTestReport.getTriggerMode())) { if (StringUtils.equalsAny(loadTestReport.getStatus(), diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanReportController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanReportController.java index a0e642af7e..3947e08cce 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanReportController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanReportController.java @@ -4,6 +4,7 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.TestCaseReport; import io.metersphere.base.domain.TestPlanReport; +import io.metersphere.commons.constants.ReportTriggerMode; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.SessionUtils; @@ -52,4 +53,10 @@ public class TestPlanReportController { public void delete(@RequestBody List testPlanReportIdList) { testPlanReportService.delete(testPlanReportIdList); } + + @GetMapping("/apiExecuteFinish/{planId}/{userId}") + public void apiExecuteFinish(@PathVariable String planId,@PathVariable String userId) { + TestPlanReport report = testPlanReportService.genTestPlanReport(planId,userId,ReportTriggerMode.API.name()); + testPlanReportService.countReportByTestPlanReportId(report.getId(),null, ReportTriggerMode.API.name()); + } } diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java index a809b751c2..43c01c23ba 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java @@ -12,4 +12,5 @@ public class TestPlanDTO extends TestPlan { private String projectName; private String userName; private List projectIds; + private String scheduleId; } diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanReportDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanReportDTO.java index 4db502b2b0..26faa67a8e 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanReportDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanReportDTO.java @@ -18,7 +18,7 @@ public class TestPlanReportDTO { private String name; private String testPlanName; private String creator; - private String createTime; + private long createTime; private String triggerMode; private TestCaseReportAdvanceStatusResultDTO executeResult; diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanLoadCaseEvent.java b/backend/src/main/java/io/metersphere/track/service/TestPlanLoadCaseEvent.java index d2b74158a6..0a9cb14d7a 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanLoadCaseEvent.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanLoadCaseEvent.java @@ -4,7 +4,9 @@ import io.metersphere.base.domain.LoadTestReport; import io.metersphere.base.domain.TestPlanReport; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.PerformanceTestStatus; +import io.metersphere.commons.constants.ReportTriggerMode; import io.metersphere.commons.consumer.LoadTestFinishEvent; +import io.metersphere.commons.utils.LogUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -22,10 +24,11 @@ public class TestPlanLoadCaseEvent implements LoadTestFinishEvent { @Override public void execute(LoadTestReport loadTestReport) { + LogUtil.info("PerformanceNoticeEvent OVER:" + loadTestReport.getTriggerMode()+";"+loadTestReport.getStatus()); if (StringUtils.equals(NoticeConstants.Mode.SCHEDULE, loadTestReport.getTriggerMode()) ) { if (StringUtils.equalsAny(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) { - testPlanReportService.updatePerformanceTestStatus(loadTestReport.getId()); + testPlanReportService.updatePerformanceTestStatus(loadTestReport.getId(), ReportTriggerMode.SCHEDULE.name()); } } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index ddd3586980..538cf14dc2 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -8,10 +8,7 @@ import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanMapper; import io.metersphere.base.mapper.ext.ExtTestPlanReportMapper; -import io.metersphere.commons.constants.ApiRunMode; -import io.metersphere.commons.constants.NoticeConstants; -import io.metersphere.commons.constants.ReportTriggerMode; -import io.metersphere.commons.constants.TestPlanStatus; +import io.metersphere.commons.constants.*; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.ServiceUtils; @@ -33,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.stream.Collectors; /** @@ -62,9 +61,12 @@ public class TestPlanReportService { ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; @Resource TestPlanLoadCaseService testPlanLoadCaseService; - @Resource TestPlanService testPlanService; + @Resource + LoadTestReportMapper loadTestReportMapper; + + private final ExecutorService executorService = Executors.newFixedThreadPool(20); public List list(QueryTestPlanReportRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); @@ -76,9 +78,7 @@ public class TestPlanReportService { return returnList; } - public TestPlanReport genTestPlanReport(String planId, String userId) { - TestPlanReportDTO returnDTO = new TestPlanReportDTO(); - + public TestPlanReport genTestPlanReport(String planId, String userId,String triggerMode) { TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId); TestPlanApiCaseExample apiExample = new TestPlanApiCaseExample(); @@ -107,7 +107,7 @@ public class TestPlanReportService { testPlanReport.setName(testPlan.getName() + "-" + DateUtils.getTimeString(new Date())); } catch (Exception e) { } - testPlanReport.setTriggerMode(ReportTriggerMode.SCHEDULE.name()); + testPlanReport.setTriggerMode(triggerMode); testPlanReport.setCreator(userId); testPlanReport.setStartTime(System.currentTimeMillis()); testPlanReport.setEndTime(System.currentTimeMillis()); @@ -145,77 +145,6 @@ public class TestPlanReportService { return testPlanReport; } - public TestPlanReportDTO updateTestPlanReport(String planId) throws Exception { - TestPlanReportDTO returnDTO = new TestPlanReportDTO(); - - QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest(); - queryTestPlanRequest.setId(planId); - TestPlanDTO testPlan = extTestPlanMapper.list(queryTestPlanRequest).get(0); - - JSONObject content = JSONObject.parseObject("{\"components\":[1,2,3,4,5]}"); - JSONArray componentIds = content.getJSONArray("components"); - - List components = ReportComponentFactory.createComponents(componentIds.toJavaList(String.class), testPlan); - List issues = testPlanService.buildFunctionalCaseReport(planId, components); - testPlanService.buildApiCaseReport(planId, components); - testPlanService.buildScenarioCaseReport(planId, components); - - TestCaseReportMetricDTO testCaseReportMetricDTO = new TestCaseReportMetricDTO(); - components.forEach(component -> { - component.afterBuild(testCaseReportMetricDTO); - }); - - String testPlanReportID = UUID.randomUUID().toString(); - TestPlanReport testPlanReport = new TestPlanReport(); - testPlanReport.setTestPlanId(planId); - testPlanReport.setId(testPlanReportID); - testPlanReport.setCreateTime(System.currentTimeMillis()); - testPlanReport.setUpdateTime(System.currentTimeMillis()); - testPlanReport.setName(testPlan.getName() + "-" + DateUtils.getTimeString(new Date())); - testPlanReport.setStatus("error"); - testPlanReport.setTriggerMode(ReportTriggerMode.MANUAL.name()); - testPlanReport.setCreator(SessionUtils.getUser().getId()); - testPlanReport.setStartTime(System.currentTimeMillis()); - testPlanReport.setEndTime(System.currentTimeMillis()); - testPlanReport.setIsApiCaseExecuting(false); - testPlanReport.setIsScenarioExecuting(false); - testPlanReport.setIsPerformanceExecuting(false); - testPlanReport.setPrincipal(testPlan.getPrincipal()); - - testPlanReportMapper.insert(testPlanReport); - - - TestPlanReportDataWithBLOBs testPlanReportData = new TestPlanReportDataWithBLOBs(); - testPlanReportData.setId(UUID.randomUUID().toString()); - testPlanReportData.setTestPlanReportId(testPlanReportID); - testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult())); - testPlanReportData.setFailurTestCases(JSONObject.toJSONString(testCaseReportMetricDTO.getFailureTestCases())); - testPlanReportData.setModuleExecuteResult(JSONArray.toJSONString(testCaseReportMetricDTO.getModuleExecuteResult())); - - TestPlanApiCaseExample apiExample = new TestPlanApiCaseExample(); - apiExample.createCriteria().andTestPlanIdEqualTo(planId); - List apiCaseIdList = testPlanApiCaseMapper.selectByExample(apiExample) - .stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); - - TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); - example.createCriteria().andTestPlanIdEqualTo(planId); - List scenarioIdList = testPlanScenarioCaseMapper.selectByExample(example) - .stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); - List performanceIdList = new ArrayList<>(); - testPlanReportData.setApiCaseInfo(JSONArray.toJSONString(apiCaseIdList)); - testPlanReportData.setScenarioInfo(JSONArray.toJSONString(scenarioIdList)); - testPlanReportData.setPerformanceInfo(JSONArray.toJSONString(performanceIdList)); - testPlanReportData.setIssuesInfo(JSONArray.toJSONString(issues)); - - testPlanReportDataMapper.insert(testPlanReportData); - - return returnDTO; - } - -// public TestCaseReport getTestCaseReport(String id) { -// return null; -// } - public TestPlanReportDTO getMetric(String reportId) { TestPlanReportDTO returnDTO = new TestPlanReportDTO(); TestPlanReport report = testPlanReportMapper.selectByPrimaryKey(reportId); @@ -252,64 +181,82 @@ public class TestPlanReportService { return returnDTO; } - public synchronized void updateReport(List testPlanReportIdList, String runMode) { - planReportForeach: + public synchronized void updateReport(List testPlanReportIdList, String runMode,String triggerMode) { for (String planReportId : testPlanReportIdList) { - TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(planReportId); - - QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest(); - queryTestPlanRequest.setId(testPlanReport.getTestPlanId()); - TestPlanDTO testPlan = extTestPlanMapper.list(queryTestPlanRequest).get(0); - - //因为接口案例是单个案例开线程运行, 所以要检查是否都执行完成。全部执行完成时才会进行统一整理 - if (StringUtils.equalsAny(runMode, ApiRunMode.SCHEDULE_API_PLAN.name())) { - List statusList = extTestPlanApiCaseMapper.getStatusByTestPlanId(testPlan.getId()); - for (String status : statusList) { - if (status == null) { - continue planReportForeach; - } - } - } - - testPlanReport.setEndTime(System.currentTimeMillis()); - testPlanReport.setUpdateTime(System.currentTimeMillis()); - - JSONObject content = JSONObject.parseObject("{\"components\":[1,2,3,4,5]}"); - JSONArray componentIds = content.getJSONArray("components"); - List components = ReportComponentFactory.createComponents(componentIds.toJavaList(String.class), testPlan); - testPlanService.buildApiCaseReport(testPlanReport.getTestPlanId(), components); - testPlanService.buildScenarioCaseReport(testPlanReport.getTestPlanId(), components); - testPlanService.buildLoadCaseReport(testPlanReport.getTestPlanId(), components); - - if (StringUtils.equals(runMode, ApiRunMode.SCHEDULE_API_PLAN.name())) { - testPlanReport.setIsApiCaseExecuting(false); - } else if (StringUtils.equals(runMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) { - testPlanReport.setIsScenarioExecuting(false); - } else if (StringUtils.equals(runMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) { - testPlanReport.setIsPerformanceExecuting(false); - } - TestCaseReportMetricDTO testCaseReportMetricDTO = new TestCaseReportMetricDTO(); - components.forEach(component -> { - component.afterBuild(testCaseReportMetricDTO); - }); - - this.update(testPlanReport); - - TestPlanReportDataExample example = new TestPlanReportDataExample(); - example.createCriteria().andTestPlanReportIdEqualTo(planReportId); - List testPlanReportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example); - if (!testPlanReportDataList.isEmpty()) { - TestPlanReportDataWithBLOBs testPlanReportData = testPlanReportDataList.get(0); - testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult())); - testPlanReportData.setFailurTestCases(JSONObject.toJSONString(testCaseReportMetricDTO.getFailureTestCases())); - testPlanReportData.setModuleExecuteResult(JSONArray.toJSONString(testCaseReportMetricDTO.getModuleExecuteResult())); - testPlanReportDataMapper.updateByPrimaryKeyWithBLOBs(testPlanReportData); - } - - + this.countReportByTestPlanReportId(planReportId,runMode,triggerMode); } } + /** + * + * @param planReportId 测试计划报告ID + * @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null + * @param triggerMode 触发方式 ReportTriggerMode.enum + */ + public void countReportByTestPlanReportId(String planReportId,String resourceRunMode,String triggerMode) { + TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(planReportId); + + QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest(); + queryTestPlanRequest.setId(testPlanReport.getTestPlanId()); + TestPlanDTO testPlan = extTestPlanMapper.list(queryTestPlanRequest).get(0); + + //因为接口案例的定时任务是单个案例开线程运行, 所以要检查是否都执行完成。全部执行完成时才会进行统一整理 + if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode) + &&StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) { + List statusList = extTestPlanApiCaseMapper.getStatusByTestPlanId(testPlan.getId()); + for (String status : statusList) { + if (status == null) { + return; + } + } + } + + testPlanReport.setEndTime(System.currentTimeMillis()); + testPlanReport.setUpdateTime(System.currentTimeMillis()); + + JSONObject content = JSONObject.parseObject("{\"components\":[1,2,3,4,5]}"); + JSONArray componentIds = content.getJSONArray("components"); + List components = ReportComponentFactory.createComponents(componentIds.toJavaList(String.class), testPlan); + testPlanService.buildApiCaseReport(testPlanReport.getTestPlanId(), components); + testPlanService.buildScenarioCaseReport(testPlanReport.getTestPlanId(), components); + testPlanService.buildLoadCaseReport(testPlanReport.getTestPlanId(), components); + + //只针对定时任务做处理 + if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode) + &&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) { + testPlanReport.setIsApiCaseExecuting(false); + } else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode) + &&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) { + testPlanReport.setIsScenarioExecuting(false); + } else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode) + &&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) { + testPlanReport.setIsPerformanceExecuting(false); + }else { + testPlanReport.setIsPerformanceExecuting(false); + testPlanReport.setIsScenarioExecuting(false); + testPlanReport.setIsApiCaseExecuting(false); + } + TestCaseReportMetricDTO testCaseReportMetricDTO = new TestCaseReportMetricDTO(); + components.forEach(component -> { + component.afterBuild(testCaseReportMetricDTO); + }); + + this.update(testPlanReport); + + TestPlanReportDataExample example = new TestPlanReportDataExample(); + example.createCriteria().andTestPlanReportIdEqualTo(planReportId); + List testPlanReportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example); + if (!testPlanReportDataList.isEmpty()) { + TestPlanReportDataWithBLOBs testPlanReportData = testPlanReportDataList.get(0); + testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult())); + testPlanReportData.setFailurTestCases(JSONObject.toJSONString(testCaseReportMetricDTO.getFailureTestCases())); + testPlanReportData.setModuleExecuteResult(JSONArray.toJSONString(testCaseReportMetricDTO.getModuleExecuteResult())); + testPlanReportDataMapper.updateByPrimaryKeyWithBLOBs(testPlanReportData); + } + + } + + public void update(TestPlanReport report) { if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting()) { try { @@ -381,7 +328,7 @@ public class TestPlanReportService { * @param testPlanReport * @param performaneReportIDList */ - public void updatePerformanceInfo(TestPlanReport testPlanReport, List performaneReportIDList) { + public void updatePerformanceInfo(TestPlanReport testPlanReport, List performaneReportIDList,String triggerMode) { TestPlanReportDataExample example = new TestPlanReportDataExample(); example.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getId()); List reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example); @@ -389,11 +336,54 @@ public class TestPlanReportService { models.setPerformanceInfo(JSONArray.toJSONString(performaneReportIDList)); testPlanReportDataMapper.updateByPrimaryKeyWithBLOBs(models); } + + /** + * 虽然kafka已经设置了topic推送,但是在1.18日测试时发现无法收到消息。 + * 由于Tapd为完成任务较多,无法抽时间查看问题,暂时先保留以下逻辑,解决完Tpad任务之后查看原因,再删除以下代码 + */ + executorService.submit(() -> { + //错误数据检查集合。 如果错误数据出现超过20次,则取消该条数据的检查 + Map errorDataCheckMap = new HashMap<>(); + while (performaneReportIDList.size()>0) { + List selectList = new ArrayList<>(performaneReportIDList); + for (String loadTestReportId:selectList) { + LoadTestReportWithBLOBs loadTestReportFromDatabase = loadTestReportMapper.selectByPrimaryKey(loadTestReportId); + if(loadTestReportFromDatabase == null){ + //检查错误数据 + if(errorDataCheckMap.containsKey(loadTestReportId)){ + if(errorDataCheckMap.get(loadTestReportId)>20){ + performaneReportIDList.remove(loadTestReportId); + }else { + errorDataCheckMap.put(loadTestReportId,errorDataCheckMap.get(loadTestReportId)+1); + } + }else { + errorDataCheckMap.put(loadTestReportId,1); + } + }else if (StringUtils.equalsAny(loadTestReportFromDatabase.getStatus(), + PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) { + performaneReportIDList.remove(loadTestReportId); + System.out.println("over"); + } + } + if(performaneReportIDList.isEmpty()){ + List testPlanReportList = new ArrayList<>(); + testPlanReportList.add(testPlanReport.getId()); + this.updateReport(testPlanReportList, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name(),triggerMode); + }else { + try { + //查询定时任务是否关闭 + Thread.sleep(1000 * 10);// 检查 loadtest 的状态 + } catch (InterruptedException e) { + } + } + } + return true; + }); } - public void updatePerformanceTestStatus(String reportId) { + public void updatePerformanceTestStatus(String reportId,String triggerMode) { List testPlanReportId = extTestPlanMapper.findIdByPerformanceReportId(reportId); - this.updateReport(testPlanReportId, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name()); + this.updateReport(testPlanReportId, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name(),triggerMode); } public void delete(List testPlanReportIdList) { diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 66bd39b490..7e84bc8c3e 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -12,7 +12,7 @@ diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index 71ba30950a..b146c8ef75 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -20,7 +20,7 @@ diff --git a/frontend/src/business/components/api/definition/components/list/ApiList.vue b/frontend/src/business/components/api/definition/components/list/ApiList.vue index 7cdb89802f..b89946e42e 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiList.vue @@ -19,7 +19,7 @@ diff --git a/frontend/src/business/components/track/plan/components/TestPlanList.vue b/frontend/src/business/components/track/plan/components/TestPlanList.vue index dea23c6d77..82f9d11f35 100644 --- a/frontend/src/business/components/track/plan/components/TestPlanList.vue +++ b/frontend/src/business/components/track/plan/components/TestPlanList.vue @@ -120,15 +120,18 @@ - + diff --git a/frontend/src/business/components/track/report/components/TestPlanReportList.vue b/frontend/src/business/components/track/report/components/TestPlanReportList.vue index 139b5a43ae..a12d9896c0 100644 --- a/frontend/src/business/components/track/report/components/TestPlanReportList.vue +++ b/frontend/src/business/components/track/report/components/TestPlanReportList.vue @@ -8,13 +8,21 @@ - + - - + + + + + + @@ -40,12 +44,14 @@ import {_filter, _sort, checkoutTestManagerOrTestUser} from "@/common/js/utils"; import {TEST_PLAN_REPORT_CONFIGS} from "../../../common/components/search/search-components"; import {getCurrentProjectID} from "../../../../../common/js/utils"; import TestPlanReportView from "@/business/components/track/report/components/TestPlanReportView"; +import ReportTriggerModeItem from "@/business/components/common/tableItem/ReportTriggerModeItem"; export default { name: "TestPlanReportList", components: { TestPlanReportView, - MsTableOperator, MsTableOperatorButton, MsTableHeader, MsTablePagination + MsTableOperator, MsTableOperatorButton, MsTableHeader, MsTablePagination, + ReportTriggerModeItem }, data() { return {