From 74fb26bd1d5dd1c046dec6cd476520a2b5905f5e Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Tue, 26 Mar 2024 13:40:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=89=8D=E7=BD=AE=E7=AD=89=E5=BE=85=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MsConstantTimerControllerConverter.java | 6 +-- .../parser/jmeter/MsScenarioConverter.java | 20 ++++++---- ...ScenarioTimeWaitingProcessorConverter.java | 40 +++++++++++++++++++ .../TimeWaitingProcessorConverter.java | 21 +--------- 4 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScenarioTimeWaitingProcessorConverter.java diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsConstantTimerControllerConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsConstantTimerControllerConverter.java index 8cd03fe72f..80d44fea8f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsConstantTimerControllerConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsConstantTimerControllerConverter.java @@ -1,8 +1,7 @@ package io.metersphere.api.parser.jmeter; import io.metersphere.api.dto.request.controller.MsConstantTimerController; -import io.metersphere.api.parser.jmeter.processor.MsProcessorConverter; -import io.metersphere.api.parser.jmeter.processor.MsProcessorConverterFactory; +import io.metersphere.api.parser.jmeter.processor.ScenarioTimeWaitingProcessorConverter; import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter; import io.metersphere.project.api.processor.TimeWaitingProcessor; @@ -19,8 +18,7 @@ public class MsConstantTimerControllerConverter extends AbstractJmeterElementCon LogUtils.info("MsConstantTimerController is disabled"); return; } - MsProcessorConverter timeWaitingConverter = MsProcessorConverterFactory.getPostConverter(TimeWaitingProcessor.class); TimeWaitingProcessor timeWaitingProcessor = BeanUtils.copyBean(new TimeWaitingProcessor(), element); - timeWaitingConverter.parse(tree, timeWaitingProcessor, config); + new ScenarioTimeWaitingProcessorConverter().parse(tree, timeWaitingProcessor, config); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java index 6566371768..3e1a3dc250 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java @@ -11,7 +11,7 @@ import io.metersphere.api.dto.scenario.ScenarioStepConfig; import io.metersphere.api.dto.scenario.ScenarioVariable; import io.metersphere.api.parser.jmeter.processor.MsProcessorConverter; import io.metersphere.api.parser.jmeter.processor.MsProcessorConverterFactory; -import io.metersphere.api.parser.jmeter.processor.TimeWaitingProcessorConverter; +import io.metersphere.api.parser.jmeter.processor.ScenarioTimeWaitingProcessorConverter; import io.metersphere.api.parser.jmeter.processor.assertion.AssertionConverterFactory; import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter; @@ -30,7 +30,6 @@ import org.apache.jmeter.config.Arguments; import org.apache.jmeter.protocol.http.control.CookieManager; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; -import org.apache.jmeter.timers.ConstantTimer; import org.apache.jorphan.collections.HashTree; import java.util.List; @@ -63,7 +62,7 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter { processor.setProjectId(msScenario.getProjectId()); - getConverterFunc.apply(processor.getClass()).parse(tree, processor, config); + MsProcessorConverter converter; + if (processor instanceof TimeWaitingProcessor) { + // 场景的的等待时间,需要包一层 debugSampler + converter = new ScenarioTimeWaitingProcessorConverter(); + } else { + converter = getConverterFunc.apply(processor.getClass()); + } + converter.parse(tree, processor, config); }); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScenarioTimeWaitingProcessorConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScenarioTimeWaitingProcessorConverter.java new file mode 100644 index 0000000000..2c6af53a14 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScenarioTimeWaitingProcessorConverter.java @@ -0,0 +1,40 @@ +package io.metersphere.api.parser.jmeter.processor; + +import io.metersphere.api.parser.jmeter.constants.JmeterAlias; +import io.metersphere.plugin.api.constants.ElementProperty; +import io.metersphere.plugin.api.dto.ParameterConfig; +import io.metersphere.project.api.processor.TimeWaitingProcessor; +import org.apache.jmeter.sampler.DebugSampler; +import org.apache.jmeter.save.SaveService; +import org.apache.jmeter.testelement.TestElement; +import org.apache.jorphan.collections.HashTree; + + +/** + * + * 场景的的等待时间,需要包一层 debugSampler + * @Author: jianxing + * @CreateTime: 2023-12-26 14:49 + */ +public class ScenarioTimeWaitingProcessorConverter extends TimeWaitingProcessorConverter { + @Override + public void parse(HashTree hashTree, TimeWaitingProcessor processor, ParameterConfig config) { + hashTree.add(getConstantTimerDebugSampler(), getConstantTimer(processor)); + } + + private DebugSampler getConstantTimerDebugSampler() { + // 添加 debugSampler 步骤间生效 + DebugSampler debugSampler = new DebugSampler(); + debugSampler.setEnabled(true); + debugSampler.setName(ElementProperty.SCENARIO_CONSTANT_TIMER.name()); + debugSampler.setProperty(TestElement.TEST_CLASS, DebugSampler.class.getName()); + debugSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI)); + + // 下面三行直接Set属性会导致DebugSampler构建时取不到值,可能是JMeter的Bug,需要SetProperty + debugSampler.setProperty("displayJMeterProperties", false); + debugSampler.setProperty("displayJMeterVariables", false); + debugSampler.setProperty("displaySystemProperties", false); + + return debugSampler; + } +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/TimeWaitingProcessorConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/TimeWaitingProcessorConverter.java index a1012fdb12..3447581425 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/TimeWaitingProcessorConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/TimeWaitingProcessorConverter.java @@ -1,11 +1,8 @@ package io.metersphere.api.parser.jmeter.processor; -import io.metersphere.api.parser.jmeter.constants.JmeterAlias; -import io.metersphere.plugin.api.constants.ElementProperty; import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.project.api.processor.TimeWaitingProcessor; import org.apache.commons.lang3.StringUtils; -import org.apache.jmeter.sampler.DebugSampler; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.timers.ConstantTimer; @@ -21,23 +18,7 @@ import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.CONSTANT_TI public class TimeWaitingProcessorConverter extends MsProcessorConverter { @Override public void parse(HashTree hashTree, TimeWaitingProcessor processor, ParameterConfig config) { - hashTree.add(getConstantTimerElement(),getConstantTimer(processor)); - } - - private DebugSampler getConstantTimerElement() { - // 添加 debugSampler 步骤间生效 - DebugSampler debugSampler = new DebugSampler(); - debugSampler.setEnabled(true); - debugSampler.setName(ElementProperty.SCENARIO_CONSTANT_TIMER.name()); - debugSampler.setProperty(TestElement.TEST_CLASS, DebugSampler.class.getName()); - debugSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI)); - - // 下面三行直接Set属性会导致DebugSampler构建时取不到值,可能是JMeter的Bug,需要SetProperty - debugSampler.setProperty("displayJMeterProperties", false); - debugSampler.setProperty("displayJMeterVariables", false); - debugSampler.setProperty("displaySystemProperties", false); - - return debugSampler; + hashTree.add(getConstantTimer(processor)); } public static ConstantTimer getConstantTimer(TimeWaitingProcessor processor) {