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

View File

@ -1157,12 +1157,9 @@ public class TestPlanService {
request.setPlanId(planId);
request.setSaveResponse(saveResponse);
request.setTestPlanExecuteReportDTO(testPlanExecuteReportDTO);
try {
// todo 调用失败处理
if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
UiPlanReportDTO uiReport = planTestPlanUiScenarioCaseService.getUiReport(request);
BeanUtils.copyBean(report, uiReport);
} catch (MSException e) {
LogUtil.error(e);
}
}
@ -1221,12 +1218,9 @@ public class TestPlanService {
ApiPlanReportRequest request = new ApiPlanReportRequest();
request.setConfig(config);
request.setTestPlanExecuteReportDTO(testPlanExecuteReportDTO);
try {
// todo 调用失败处理
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
ApiPlanReportDTO apiPlanReport = planTestPlanScenarioCaseService.getApiExecuteReport(request);
BeanUtils.copyBean(report, apiPlanReport);
} catch (Exception e) {
LogUtil.error(e);
}
}
@ -1239,12 +1233,9 @@ public class TestPlanService {
request.setConfig(config);
request.setSaveResponse(saveResponse);
request.setReportIdMap(loadCaseReportMap);
try {
// todo 调用失败处理
if (DiscoveryUtil.hasService(MicroServiceName.PERFORMANCE_TEST)) {
LoadPlanReportDTO loadPlanReport = planTestPlanLoadCaseService.getLoadExecuteReport(request);
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,
BiConsumer<TestPlanSimpleReportDTO, Object> setReportCaseFunc) {
try {
// todo 服务调用失败
if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
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) {
try {
// todo 调用失败
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
planTestPlanApiCaseService.setApiCaseEnv(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;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.*;
@ -7,6 +8,7 @@ import io.metersphere.plan.dto.*;
import io.metersphere.plan.request.api.ApiTestCaseRequest;
import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -36,15 +38,13 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
* @return 接口用例的最新执行报告
*/
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
try {
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
//计算测试计划中接口用例的相关数据
calculatePlanReport(report, planReportCaseDTOS);
//记录接口用例的运行环境信息
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
report.setProjectEnvMap(getPlanProjectEnvMap(idList));
} catch (MSException e) {
LogUtil.error(e);
}
}

View File

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

View File

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

View File

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