From d2f30562b396cb92a7dc27097fef7da99d53b13d Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 21 Apr 2023 18:45:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=B2=E8=A1=8C=E6=89=A7=E8=A1=8C=E5=81=B6?= =?UTF-8?q?=E5=8F=91=E5=BC=82=E5=B8=B8=E9=80=A0=E6=88=90=E9=98=BB=E5=A1=9E?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fit2-zhao --- .../api/exec/api/ApiCaseSerialService.java | 2 +- .../scenario/ApiScenarioSerialService.java | 5 ++++- .../commons/utils/GenerateHashTreeUtil.java | 18 ++++++------------ .../commons/utils/RequestParamsUtil.java | 13 ------------- .../service/ApiJMeterFileService.java | 2 +- 5 files changed, 12 insertions(+), 28 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java index ebaa0a0d46..62f9893a7e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java @@ -83,7 +83,7 @@ public class ApiCaseSerialService { runRequest.getExtendedParameters().put(PROJECT_ID, queue.getProjectIds()); jMeterService.run(runRequest); } catch (Exception e) { - RequestParamsUtil.rollback(runRequest, e); + LoggerUtil.error("串行执行用例失败", e); } } diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java index dc29881ed9..86cc66b619 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java @@ -18,6 +18,7 @@ import io.metersphere.commons.utils.GenerateHashTreeUtil; import io.metersphere.commons.utils.HashTreeUtil; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.RequestParamsUtil; +import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.JmeterRunRequestDTO; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.utils.LoggerUtil; @@ -30,6 +31,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import jakarta.annotation.Resource; + import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -60,6 +62,7 @@ public class ApiScenarioSerialService { reportId = queue.getReportId(); } JmeterRunRequestDTO runRequest = RequestParamsUtil.init(executionQueue, queue, reportId); + runRequest.setRunType(RunModeConstants.SERIAL.toString()); // 更新报告状态 updateReportToRunning(queue, runRequest); try { @@ -98,7 +101,7 @@ public class ApiScenarioSerialService { runRequest.getExtendedParameters().put("projectId", queue.getProjectIds()); jMeterService.run(runRequest); } catch (Exception e) { - RequestParamsUtil.rollback(runRequest, e); + LoggerUtil.error("串行执行失败", e); } } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java index 185a7b68c0..d44504a8b8 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java @@ -13,10 +13,12 @@ import io.metersphere.base.mapper.TestResourcePoolMapper; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.constants.RunModeConstants; -import io.metersphere.dto.*; +import io.metersphere.dto.BaseSystemConfigDTO; +import io.metersphere.dto.JmeterRunRequestDTO; +import io.metersphere.dto.ProjectJarConfig; +import io.metersphere.dto.RunModeConfigDTO; import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.plugin.core.MsTestElement; -import io.metersphere.service.ApiExecutionQueueService; import io.metersphere.service.RemakeReportService; import io.metersphere.utils.LoggerUtil; import io.metersphere.vo.BooleanPool; @@ -161,23 +163,15 @@ public class GenerateHashTreeUtil { LoggerUtil.info("场景资源:" + item.getName() + ", 生成执行脚本JMX成功", runRequest.getReportId()); } catch (Exception ex) { - remakeException(runRequest, ex); LoggerUtil.error("场景资源:" + item.getName() + ", 生成执行脚本失败", runRequest.getReportId(), ex); - return null; + RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); + remakeReportService.testEnded(runRequest, ex.getMessage()); } LogUtil.info(testPlan.getJmx(jmeterHashTree)); return jmeterHashTree; } - public static void remakeException(JmeterRunRequestDTO runRequest, Exception e) { - RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); - remakeReportService.testEnded(runRequest, e.getMessage()); - ResultDTO dto = new ResultDTO(); - BeanUtils.copyBean(dto, runRequest); - CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto); - } - public static boolean isSetReport(RunModeConfigDTO config) { return config != null && isSetReport(config.getReportType()) && StringUtils.isNotEmpty(config.getReportName()); } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/RequestParamsUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/RequestParamsUtil.java index 7c779ba8da..eda152c2a5 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/RequestParamsUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/RequestParamsUtil.java @@ -1,15 +1,11 @@ package io.metersphere.commons.utils; -import io.metersphere.service.ApiExecutionQueueService; -import io.metersphere.service.RemakeReportService; import io.metersphere.base.domain.ApiExecutionQueue; import io.metersphere.base.domain.ApiExecutionQueueDetail; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.dto.JmeterRunRequestDTO; -import io.metersphere.dto.ResultDTO; import io.metersphere.service.SystemParameterService; -import io.metersphere.utils.LoggerUtil; public class RequestParamsUtil { @@ -28,13 +24,4 @@ public class RequestParamsUtil { runRequest.setPlatformUrl(GenerateHashTreeUtil.getPlatformUrl(baseInfo, runRequest, queue.getId())); return runRequest; } - - public static void rollback(JmeterRunRequestDTO runRequest, Exception e) { - RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); - remakeReportService.testEnded(runRequest, e.getMessage()); - ResultDTO dto = new ResultDTO(); - BeanUtils.copyBean(dto, runRequest); - CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto); - LoggerUtil.error("执行队列[" + runRequest.getQueueId() + "]入队列失败:", runRequest.getReportId(), e); - } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java index 2294b3abda..2578ddb05a 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java @@ -138,6 +138,7 @@ public class ApiJMeterFileService { if (detail != null) { runRequest.setRetryEnable(detail.getRetryEnable()); runRequest.setRetryNum(detail.getRetryNumber()); + runRequest.setRunType(detail.getType()); } Map processEnvMap = new LinkedHashMap<>(); if (detail != null && StringUtils.isNotEmpty(detail.getEvnMap())) { @@ -165,7 +166,6 @@ public class ApiJMeterFileService { } catch (Exception e) { remakeReportService.testEnded(runRequest, "生成执行脚本异常:" + e.getMessage()); } - remakeReportService.testEnded(runRequest, "未找到测试资源【" + remoteTestId + "】,资源类型:" + runMode); return new byte[0]; }