From 26936d760d3754b28fb0d8982b81d71f0e537eca Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 10 Jan 2023 10:34:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=AC=E5=9C=B0=E6=89=A7=E8=A1=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=B5=84=E6=BA=90=E6=B1=A0=E7=9A=84=E7=BC=BA?= =?UTF-8?q?=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vConfigUtil.java => ApiReportEnvConfigDTO.java} | 2 +- .../io/metersphere/api/jmeter/JMeterService.java | 14 +++++++++----- .../io/metersphere/api/jmeter/MsDebugListener.java | 7 +++++++ .../definition/ApiDefinitionEnvService.java | 6 +++--- .../service/definition/ApiDefinitionService.java | 6 +++--- 5 files changed, 23 insertions(+), 12 deletions(-) rename api-test/backend/src/main/java/io/metersphere/api/dto/{ApiReportEnvConfigUtil.java => ApiReportEnvConfigDTO.java} (81%) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/ApiReportEnvConfigUtil.java b/api-test/backend/src/main/java/io/metersphere/api/dto/ApiReportEnvConfigDTO.java similarity index 81% rename from api-test/backend/src/main/java/io/metersphere/api/dto/ApiReportEnvConfigUtil.java rename to api-test/backend/src/main/java/io/metersphere/api/dto/ApiReportEnvConfigDTO.java index ed5b3aa5f1..a282ab3548 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/ApiReportEnvConfigUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/ApiReportEnvConfigDTO.java @@ -5,7 +5,7 @@ import lombok.Setter; @Setter @Getter -public class ApiReportEnvConfigUtil { +public class ApiReportEnvConfigDTO { private String envName; diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 985dac54cd..a2d0f7250e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -11,7 +11,10 @@ import io.metersphere.commons.config.KafkaConfig; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ExtendedParameter; import io.metersphere.commons.exception.MSException; -import io.metersphere.commons.utils.*; +import io.metersphere.commons.utils.FixedCapacityUtil; +import io.metersphere.commons.utils.GenerateHashTreeUtil; +import io.metersphere.commons.utils.HashTreeUtil; +import io.metersphere.commons.utils.JSON; import io.metersphere.config.JmeterProperties; import io.metersphere.constants.BackendListenerConstants; import io.metersphere.constants.RunModeConstants; @@ -21,9 +24,9 @@ import io.metersphere.dto.RunModeConfigDTO; import io.metersphere.engine.Engine; import io.metersphere.jmeter.JMeterBase; import io.metersphere.jmeter.LocalRunner; +import io.metersphere.service.ApiPoolDebugService; import io.metersphere.service.RemakeReportService; import io.metersphere.utils.LoggerUtil; -import io.metersphere.service.ApiPoolDebugService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.ArrayUtils; @@ -91,12 +94,13 @@ public class JMeterService { * @param testId * @param testPlan */ - private void addDebugListener(String testId, HashTree testPlan) { + private void addDebugListener(String testId, HashTree testPlan, String runMode) { MsDebugListener resultCollector = new MsDebugListener(); resultCollector.setName(testId); resultCollector.setProperty(TestElement.TEST_CLASS, MsDebugListener.class.getName()); resultCollector.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ViewResultsFullVisualizer")); resultCollector.setEnabled(true); + resultCollector.setRunMode(runMode); // 添加DEBUG标示 HashTree test = ArrayUtils.isNotEmpty(testPlan.getArray()) ? testPlan.getTree(testPlan.getArray()[0]) : null; @@ -127,12 +131,12 @@ public class JMeterService { && request.getExtendedParameters().containsKey(ExtendedParameter.SYNC_STATUS) && (Boolean) request.getExtendedParameters().get(ExtendedParameter.SYNC_STATUS)) { LoggerUtil.debug("为请求 [ " + request.getReportId() + " ] 添加Debug Listener"); - addDebugListener(request.getReportId(), request.getHashTree()); + addDebugListener(request.getReportId(), request.getHashTree(), request.getRunMode()); } if (request.isDebug()) { LoggerUtil.debug("为请求 [ " + request.getReportId() + " ] 添加Debug Listener"); - addDebugListener(request.getReportId(), request.getHashTree()); + addDebugListener(request.getReportId(), request.getHashTree(), request.getRunMode()); } else { LoggerUtil.debug("为请求 [ " + request.getReportId() + " ] 添加同步接收结果 Listener"); JMeterBase.addBackendListener(request, request.getHashTree(), MsApiBackendListener.class.getCanonicalName()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsDebugListener.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsDebugListener.java index 49a88805f1..7f233f1af9 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsDebugListener.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsDebugListener.java @@ -54,6 +54,8 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi public static final String TEST_END = "MS_TEST_END"; + private String runMode; + @Override public Object clone() { MsDebugListener clone = (MsDebugListener) super.clone(); @@ -64,6 +66,10 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi return getPropertyAsBoolean(ERROR_LOGGING); } + public void setRunMode(String runMode) { + this.runMode = runMode; + } + public final void setSuccessOnlyLogging(boolean value) { if (value) { setProperty(new BooleanProperty(SUCCESS_ONLY_LOGGING, true)); @@ -151,6 +157,7 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi dto.setExecEnd(false); dto.setReportId("send." + this.getName()); dto.setToReport(this.getName()); + dto.setRunMode(runMode); String console = FixedCapacityUtil.getJmeterLogger(this.getName(), false); ApiDefinitionEnvService apiDefinitionEnvService = CommonBeanFactory.getBean(ApiDefinitionEnvService.class); diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionEnvService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionEnvService.java index 7d5529e9ef..949490d940 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionEnvService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionEnvService.java @@ -1,6 +1,6 @@ package io.metersphere.service.definition; -import io.metersphere.api.dto.ApiReportEnvConfigUtil; +import io.metersphere.api.dto.ApiReportEnvConfigDTO; import io.metersphere.api.dto.MsgDTO; import io.metersphere.api.dto.RequestResultExpandDTO; import io.metersphere.base.domain.ApiDefinitionEnv; @@ -80,7 +80,7 @@ public class ApiDefinitionEnvService { if (StringUtils.isNotBlank(baseResult.getThreadName())) { ApiDefinitionExecResultWithBLOBs result = apiDefinitionExecResultMapper.selectByPrimaryKey(baseResult.getThreadName()); if (result != null && StringUtils.isNotEmpty(result.getEnvConfig())) { - ApiReportEnvConfigUtil envConfig = apiDefinitionService.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig()); + ApiReportEnvConfigDTO envConfig = apiDefinitionService.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig()); if (envConfig != null) { expandDTO.setEnvName(envConfig.getEnvName()); expandDTO.setPoolName(envConfig.getResourcePoolName()); @@ -93,7 +93,7 @@ public class ApiDefinitionEnvService { if (StringUtils.isNotBlank(dto.getToReport())) { ApiDefinitionExecResultWithBLOBs result = apiDefinitionExecResultMapper.selectByPrimaryKey(dto.getToReport()); if (result != null && StringUtils.isNotEmpty(result.getEnvConfig())) { - ApiReportEnvConfigUtil envConfig = apiDefinitionService.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig()); + ApiReportEnvConfigDTO envConfig = apiDefinitionService.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig()); if (envConfig != null) { Map map = JSON.parseObject(dto.getContent().substring(7), Map.class); map.put("envName", envConfig.getEnvName()); diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index 4f76c21954..6ca0f67127 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -960,7 +960,7 @@ public class ApiDefinitionService { if (StringUtils.isNotBlank(contentStr)) { JSONObject content = JSONUtil.parseObject(contentStr); if (StringUtils.isNotEmpty(result.getEnvConfig())) { - ApiReportEnvConfigUtil envNameByEnvConfig = this.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig()); + ApiReportEnvConfigDTO envNameByEnvConfig = this.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig()); if (envNameByEnvConfig != null) { content.put("envName", envNameByEnvConfig.getEnvName()); content.put("poolName", envNameByEnvConfig.getResourcePoolName()); @@ -975,8 +975,8 @@ public class ApiDefinitionService { return reportResult; } - public ApiReportEnvConfigUtil getEnvNameByEnvConfig(String projectId, String envConfig) { - ApiReportEnvConfigUtil apiReportEnvConfig = new ApiReportEnvConfigUtil(); + public ApiReportEnvConfigDTO getEnvNameByEnvConfig(String projectId, String envConfig) { + ApiReportEnvConfigDTO apiReportEnvConfig = new ApiReportEnvConfigDTO(); RunModeConfigDTO runModeConfigDTO = null; try { runModeConfigDTO = JSON.parseObject(envConfig, RunModeConfigDTO.class);