fix(测试跟踪): 开源用户保存测试计划报告报错

This commit is contained in:
chenjianxing 2022-11-10 17:57:29 +08:00 committed by jianxing
parent 091242bf09
commit 845ff07bdc
6 changed files with 55 additions and 82 deletions

View File

@ -30,6 +30,7 @@ import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.xpack.track.dto.IssuesDao; import io.metersphere.xpack.track.dto.IssuesDao;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -256,58 +257,45 @@ public class TestPlanReportService {
Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet(); Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
try { if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
if (serviceIdSet.contains(MicroServiceName.API_TEST)) { TestPlanApiReportInfoDTO testPlanApiReportInfoDTO = planTestPlanScenarioCaseService.genApiReportInfoForSchedule(planId, runModeConfigDTO);
// todo 远程调用失败处理逻辑 Map<String, String> planScenarioIdMap = testPlanApiReportInfoDTO.getPlanScenarioIdMap();
TestPlanApiReportInfoDTO testPlanApiReportInfoDTO = planTestPlanScenarioCaseService.genApiReportInfoForSchedule(planId, runModeConfigDTO); Map<String, String> planApiCaseIdMap = testPlanApiReportInfoDTO.getPlanApiCaseIdMap();
Map<String, String> planScenarioIdMap = testPlanApiReportInfoDTO.getPlanScenarioIdMap(); runInfoDTO = testPlanApiReportInfoDTO.getRunInfoDTO();
Map<String, String> planApiCaseIdMap = testPlanApiReportInfoDTO.getPlanApiCaseIdMap();
runInfoDTO = testPlanApiReportInfoDTO.getRunInfoDTO();
saveRequest.setApiCaseIsExecuting(!planApiCaseIdMap.isEmpty()); saveRequest.setApiCaseIsExecuting(!planApiCaseIdMap.isEmpty());
saveRequest.setScenarioIsExecuting(!planScenarioIdMap.isEmpty()); saveRequest.setScenarioIsExecuting(!planScenarioIdMap.isEmpty());
saveRequest.setApiCaseIdMap(planApiCaseIdMap); saveRequest.setApiCaseIdMap(planApiCaseIdMap);
saveRequest.setScenarioIdMap(planScenarioIdMap); saveRequest.setScenarioIdMap(planScenarioIdMap);
returnDTO.setPlanScenarioIdMap(planScenarioIdMap); returnDTO.setPlanScenarioIdMap(planScenarioIdMap);
returnDTO.setApiTestCaseDataMap(planApiCaseIdMap); returnDTO.setApiTestCaseDataMap(planApiCaseIdMap);
}
} catch (Exception e) {
LogUtil.error(e);
} }
try {
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
// todo 远程调用失败处理逻辑
Map<String, String> performanceIdMap = new LinkedHashMap<>();
List<TestPlanLoadCaseDTO> testPlanLoadCaseDTOList = planTestPlanLoadCaseService.list(planId);
for (TestPlanLoadCaseDTO dto : testPlanLoadCaseDTOList) {
performanceIdMap.put(dto.getId(), dto.getLoadCaseId());
}
saveRequest.setPerformanceIsExecuting(!performanceIdMap.isEmpty());
saveRequest.setPerformanceIdMap(performanceIdMap);
returnDTO.setPerformanceIdMap(performanceIdMap); if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
Map<String, String> performanceIdMap = new LinkedHashMap<>();
List<TestPlanLoadCaseDTO> testPlanLoadCaseDTOList = planTestPlanLoadCaseService.list(planId);
for (TestPlanLoadCaseDTO dto : testPlanLoadCaseDTOList) {
performanceIdMap.put(dto.getId(), dto.getLoadCaseId());
} }
} catch (Exception e) { saveRequest.setPerformanceIsExecuting(!performanceIdMap.isEmpty());
LogUtil.error(e); saveRequest.setPerformanceIdMap(performanceIdMap);
returnDTO.setPerformanceIdMap(performanceIdMap);
} }
try {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
// todo 远程调用失败处理逻辑
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
for (TestPlanUiScenario dto : testPlanUiScenarioList) {
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
}
saveRequest.setUiScenarioIsExecuting(!uiScenarioIdMap.isEmpty());
saveRequest.setUiScenarioIdMap(uiScenarioIdMap);
returnDTO.setUiScenarioIdMap(uiScenarioIdMap); if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
for (TestPlanUiScenario dto : testPlanUiScenarioList) {
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
} }
} catch (Exception e) { saveRequest.setUiScenarioIsExecuting(!uiScenarioIdMap.isEmpty());
LogUtil.error(e); saveRequest.setUiScenarioIdMap(uiScenarioIdMap);
returnDTO.setUiScenarioIdMap(uiScenarioIdMap);
} }
@ -385,10 +373,10 @@ public class TestPlanReportService {
testPlanReport.setIsUiScenarioExecuting(saveRequest.isUiScenarioIsExecuting()); testPlanReport.setIsUiScenarioExecuting(saveRequest.isUiScenarioIsExecuting());
} }
if (testPlanReport.getIsScenarioExecuting() if (BooleanUtils.isTrue(testPlanReport.getIsScenarioExecuting())
|| testPlanReport.getIsApiCaseExecuting() || BooleanUtils.isTrue(testPlanReport.getIsApiCaseExecuting())
|| testPlanReport.getIsPerformanceExecuting() || BooleanUtils.isTrue(testPlanReport.getIsPerformanceExecuting())
|| testPlanReport.getIsUiScenarioExecuting()) { || BooleanUtils.isTrue(testPlanReport.getIsUiScenarioExecuting())) {
testPlanReport.setStatus(TestPlanReportStatus.RUNNING.name()); testPlanReport.setStatus(TestPlanReportStatus.RUNNING.name());
} else { } else {
testPlanReport.setStatus(TestPlanReportStatus.COMPLETED.name()); testPlanReport.setStatus(TestPlanReportStatus.COMPLETED.name());
@ -1086,9 +1074,10 @@ public class TestPlanReportService {
private void generateEnvironmentInfo(TestPlanSimpleReportDTO testPlanReportDTO, String reportId) { private void generateEnvironmentInfo(TestPlanSimpleReportDTO testPlanReportDTO, String reportId) {
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId); TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId);
try { try {
// todo 调用失败处理 if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanScenarioCaseService.generateEnvironmentInfo(testPlanReport); TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanScenarioCaseService.generateEnvironmentInfo(testPlanReport);
BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo); BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo);
}
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
} }

View File

@ -1157,12 +1157,9 @@ public class TestPlanService {
request.setPlanId(planId); request.setPlanId(planId);
request.setSaveResponse(saveResponse); request.setSaveResponse(saveResponse);
request.setTestPlanExecuteReportDTO(testPlanExecuteReportDTO); request.setTestPlanExecuteReportDTO(testPlanExecuteReportDTO);
try { if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
// todo 调用失败处理
UiPlanReportDTO uiReport = planTestPlanUiScenarioCaseService.getUiReport(request); UiPlanReportDTO uiReport = planTestPlanUiScenarioCaseService.getUiReport(request);
BeanUtils.copyBean(report, uiReport); BeanUtils.copyBean(report, uiReport);
} catch (MSException e) {
LogUtil.error(e);
} }
} }
@ -1221,12 +1218,9 @@ public class TestPlanService {
ApiPlanReportRequest request = new ApiPlanReportRequest(); ApiPlanReportRequest request = new ApiPlanReportRequest();
request.setConfig(config); request.setConfig(config);
request.setTestPlanExecuteReportDTO(testPlanExecuteReportDTO); request.setTestPlanExecuteReportDTO(testPlanExecuteReportDTO);
try { if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
// todo 调用失败处理
ApiPlanReportDTO apiPlanReport = planTestPlanScenarioCaseService.getApiExecuteReport(request); ApiPlanReportDTO apiPlanReport = planTestPlanScenarioCaseService.getApiExecuteReport(request);
BeanUtils.copyBean(report, apiPlanReport); BeanUtils.copyBean(report, apiPlanReport);
} catch (Exception e) {
LogUtil.error(e);
} }
} }
@ -1239,12 +1233,9 @@ public class TestPlanService {
request.setConfig(config); request.setConfig(config);
request.setSaveResponse(saveResponse); request.setSaveResponse(saveResponse);
request.setReportIdMap(loadCaseReportMap); request.setReportIdMap(loadCaseReportMap);
try { if (DiscoveryUtil.hasService(MicroServiceName.PERFORMANCE_TEST)) {
// todo 调用失败处理
LoadPlanReportDTO loadPlanReport = planTestPlanLoadCaseService.getLoadExecuteReport(request); LoadPlanReportDTO loadPlanReport = planTestPlanLoadCaseService.getLoadExecuteReport(request);
BeanUtils.copyBean(report, loadPlanReport); BeanUtils.copyBean(report, loadPlanReport);
} catch (Exception e) {
LogUtil.error(e);
} }
} }
@ -1352,11 +1343,8 @@ public class TestPlanService {
public void runReportWithExceptionHandle(TestPlanSimpleReportDTO report, Function<TestPlanSimpleReportDTO, Object> getCaseFunc, public void runReportWithExceptionHandle(TestPlanSimpleReportDTO report, Function<TestPlanSimpleReportDTO, Object> getCaseFunc,
BiConsumer<TestPlanSimpleReportDTO, Object> setReportCaseFunc) { BiConsumer<TestPlanSimpleReportDTO, Object> setReportCaseFunc) {
try { if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
// todo 服务调用失败
setReportCaseFunc.accept(report, getCaseFunc.apply(report)); setReportCaseFunc.accept(report, getCaseFunc.apply(report));
} catch (Exception e) {
LogUtil.error(e);
} }
} }
@ -1561,12 +1549,9 @@ public class TestPlanService {
} }
public void setPlanCaseEnv(String planId, RunModeConfigDTO runModeConfig) { public void setPlanCaseEnv(String planId, RunModeConfigDTO runModeConfig) {
try { if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
// todo 调用失败
planTestPlanApiCaseService.setApiCaseEnv(planId, runModeConfig); planTestPlanApiCaseService.setApiCaseEnv(planId, runModeConfig);
planTestPlanScenarioCaseService.setScenarioEnv(planId, runModeConfig); planTestPlanScenarioCaseService.setScenarioEnv(planId, runModeConfig);
} catch (Exception e) {
LogUtil.error(e);
} }
} }

View File

@ -1,5 +1,6 @@
package io.metersphere.plan.service.remote.api; package io.metersphere.plan.service.remote.api;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.*; import io.metersphere.dto.*;
@ -7,6 +8,7 @@ import io.metersphere.plan.dto.*;
import io.metersphere.plan.request.api.ApiTestCaseRequest; import io.metersphere.plan.request.api.ApiTestCaseRequest;
import io.metersphere.plan.service.TestPlanService; import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -36,15 +38,13 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
* @return 接口用例的最新执行报告 * @return 接口用例的最新执行报告
*/ */
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) { public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
try { if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId); List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
//计算测试计划中接口用例的相关数据 //计算测试计划中接口用例的相关数据
calculatePlanReport(report, planReportCaseDTOS); calculatePlanReport(report, planReportCaseDTOS);
//记录接口用例的运行环境信息 //记录接口用例的运行环境信息
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
report.setProjectEnvMap(getPlanProjectEnvMap(idList)); report.setProjectEnvMap(getPlanProjectEnvMap(idList));
} catch (MSException e) {
LogUtil.error(e);
} }
} }

View File

@ -1,6 +1,7 @@
package io.metersphere.plan.service.remote.api; package io.metersphere.plan.service.remote.api;
import io.metersphere.base.domain.TestPlanReport; import io.metersphere.base.domain.TestPlanReport;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.*; import io.metersphere.dto.*;
@ -10,6 +11,7 @@ import io.metersphere.plan.request.api.ApiPlanReportRequest;
import io.metersphere.plan.request.api.ApiScenarioRequest; import io.metersphere.plan.request.api.ApiScenarioRequest;
import io.metersphere.plan.service.TestPlanService; import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -31,14 +33,12 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService {
PlanApiScenarioReportService planApiScenarioReportService; PlanApiScenarioReportService planApiScenarioReportService;
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) { public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
try { if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId); List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
calculatePlanReport(report, planReportCaseDTOS); calculatePlanReport(report, planReportCaseDTOS);
//记录接口用例的运行环境信息 //记录接口用例的运行环境信息
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
report.setProjectEnvMap(getPlanProjectEnvMap(idList)); report.setProjectEnvMap(getPlanProjectEnvMap(idList));
} catch (MSException e) {
LogUtil.error(e);
} }
} }

View File

@ -1,5 +1,6 @@
package io.metersphere.plan.service.remote.performance; package io.metersphere.plan.service.remote.performance;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.commons.constants.TestPlanLoadCaseStatus; import io.metersphere.commons.constants.TestPlanLoadCaseStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
@ -13,6 +14,7 @@ import io.metersphere.plan.request.performance.LoadCaseRequest;
import io.metersphere.plan.request.performance.LoadPlanReportDTO; import io.metersphere.plan.request.performance.LoadPlanReportDTO;
import io.metersphere.plan.service.TestPlanService; import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -34,11 +36,9 @@ public class PlanTestPlanLoadCaseService extends LoadTestService {
private TestPlanService testPlanService; private TestPlanService testPlanService;
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) { public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
try { if (DiscoveryUtil.hasService(MicroServiceName.PERFORMANCE_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId); List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
calculatePlanReport(report, planReportCaseDTOS); calculatePlanReport(report, planReportCaseDTOS);
} catch (MSException e) {
LogUtil.error(e);
} }
} }

View File

@ -1,6 +1,7 @@
package io.metersphere.plan.service.remote.ui; package io.metersphere.plan.service.remote.ui;
import io.metersphere.base.domain.TestPlanUiScenario; import io.metersphere.base.domain.TestPlanUiScenario;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.*; import io.metersphere.dto.*;
@ -16,6 +17,7 @@ import io.metersphere.plan.service.remote.api.PlanTestPlanScenarioCaseService;
import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService; import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService;
import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.request.ResetOrderRequest; import io.metersphere.request.ResetOrderRequest;
import io.metersphere.utils.DiscoveryUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -60,15 +62,12 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
} }
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) { public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
try { if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId); List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
TestPlanUiResultReportDTO uiResult = getUiResult(report, planReportCaseDTOS); TestPlanUiResultReportDTO uiResult = getUiResult(report, planReportCaseDTOS);
report.setUiResult(uiResult); report.setUiResult(uiResult);
} catch (MSException e) {
LogUtil.error(e);
} }
} }