From 5113b46ab08b65d52313b5d102367ab95b174336 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 2 Nov 2022 10:58:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=BC=80=E6=BA=90=E7=94=A8=E6=88=B7copy=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E6=8F=90=E7=A4=BAUI=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1019261 --user=陈建星 [测试跟踪]开源版-复制测试计划失败,提示UI服务异常 https://www.tapd.cn/55049933/s/1286005 --- .../io/metersphere/xpack/utils/XpackUtil.java | 17 +++++++++ .../plan/service/TestPlanReportService.java | 37 +++++++------------ .../plan/service/TestPlanService.java | 29 +++++++++++---- 3 files changed, 53 insertions(+), 30 deletions(-) create mode 100644 framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/utils/XpackUtil.java diff --git a/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/utils/XpackUtil.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/utils/XpackUtil.java new file mode 100644 index 0000000000..fe2f897209 --- /dev/null +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/utils/XpackUtil.java @@ -0,0 +1,17 @@ +package io.metersphere.xpack.utils; + +import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.xpack.license.service.LicenseService; + +public class XpackUtil { + + public static final String LICENSE_STATUS = "valid"; + + public static boolean validateLicense() { + LicenseService licenseService = CommonBeanFactory.getBean(LicenseService.class); + if (licenseService != null) { + return licenseService.validate().getStatus().equals(LICENSE_STATUS); + } + return false; + } +} 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 f740ea1095..e5dd458276 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 @@ -29,6 +29,7 @@ import io.metersphere.service.BaseUserService; import io.metersphere.service.ServiceUtils; import io.metersphere.utils.DiscoveryUtil; import io.metersphere.xpack.track.dto.IssuesDao; +import io.metersphere.xpack.utils.XpackUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -295,7 +296,7 @@ public class TestPlanReportService { } try { - if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { + if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) { // todo 远程调用失败处理逻辑 Map uiScenarioIdMap = new LinkedHashMap<>(); List testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId); @@ -362,33 +363,23 @@ public class TestPlanReportService { if (saveRequest.isCountResources()) { String planId = saveRequest.getPlanId(); - try { - if (serviceIdSet.contains(MicroServiceName.API_TEST)) { - // todo 远程调用失败处理逻辑 - testPlanReport.setIsApiCaseExecuting(planTestPlanApiCaseService.isCaseExecuting(planId)); - testPlanReport.setIsScenarioExecuting(planTestPlanScenarioCaseService.isCaseExecuting(planId)); - } - } catch (Exception e) { - LogUtil.error(e); + + if (serviceIdSet.contains(MicroServiceName.API_TEST)) { + + testPlanReport.setIsApiCaseExecuting(planTestPlanApiCaseService.isCaseExecuting(planId)); + testPlanReport.setIsScenarioExecuting(planTestPlanScenarioCaseService.isCaseExecuting(planId)); } - try { - if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { - // todo 远程调用失败处理逻辑 - testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId)); - } - } catch (Exception e) { - LogUtil.error(e); + + if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) { + testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId)); } - try { - if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { - // todo 远程调用失败处理逻辑 - testPlanReport.setIsPerformanceExecuting(planTestPlanLoadCaseService.isCaseExecuting(planId, testPlan.getProjectId())); - } - } catch (Exception e) { - LogUtil.error(e); + + if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { + testPlanReport.setIsPerformanceExecuting(planTestPlanLoadCaseService.isCaseExecuting(planId, testPlan.getProjectId())); } + } else { testPlanReport.setIsApiCaseExecuting(saveRequest.isApiCaseIsExecuting()); testPlanReport.setIsScenarioExecuting(saveRequest.isScenarioIsExecuting()); diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 00613221b8..2bfdd85db5 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -48,6 +48,7 @@ import io.metersphere.service.*; import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.LoggerUtil; import io.metersphere.xpack.track.dto.IssuesDao; +import io.metersphere.xpack.utils.XpackUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -363,7 +364,7 @@ public class TestPlanService { calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanLoadCaseService::getExecResultByPlanId); } - if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { + if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) { calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanUiScenarioCaseService::getExecResultByPlanId); } @@ -1004,7 +1005,6 @@ public class TestPlanService { return null; } - @Transactional(rollbackFor = Exception.class) public TestPlan copy(String planId) { TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId); if (testPlan == null) { @@ -1047,7 +1047,6 @@ public class TestPlanService { } } - @Transactional(rollbackFor = Exception.class) public void copyPlanCase(String sourcePlanId, String targetPlanId) { TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(sourcePlanId); @@ -1076,10 +1075,26 @@ public class TestPlanService { } sqlSession.flushStatements(); - planTestPlanApiCaseService.copyPlan(sourcePlanId, targetPlanId); - planTestPlanScenarioCaseService.copyPlan(sourcePlanId, targetPlanId); - planTestPlanLoadCaseService.copyPlan(sourcePlanId, targetPlanId); - planTestPlanUiScenarioCaseService.copyPlan(sourcePlanId, targetPlanId); + try { + planTestPlanApiCaseService.copyPlan(sourcePlanId, targetPlanId); + } catch (Exception e) { + LogUtil.error(e); + } + + Set serviceIdSet = DiscoveryUtil.getServiceIdSet(); + + if (serviceIdSet.contains(MicroServiceName.API_TEST)) { + planTestPlanApiCaseService.copyPlan(sourcePlanId, targetPlanId); + planTestPlanScenarioCaseService.copyPlan(sourcePlanId, targetPlanId); + } + + if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { + planTestPlanLoadCaseService.copyPlan(sourcePlanId, targetPlanId); + } + + if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) { + planTestPlanUiScenarioCaseService.copyPlan(sourcePlanId, targetPlanId); + } if (sqlSession != null && sqlSessionFactory != null) { SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);