From 71c3e92332c13b1220b7d48e58d2192fb5dfef3c Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 6 Apr 2021 13:22:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xml/reader/jmx/JmeterDocumentParser.java | 55 +++++++++++++++---- .../components/PerformancePressureConfig.vue | 25 +++++++++ 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java index 5d1e7e345d..426e9dbd34 100644 --- a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java +++ b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java @@ -40,8 +40,8 @@ public class JmeterDocumentParser implements DocumentParser { private final static String ARGUMENTS = "Arguments"; private final static String RESPONSE_ASSERTION = "ResponseAssertion"; private final static String CSV_DATA_SET = "CSVDataSet"; + private final static String THREAD_GROUP_AUTO_STOP = "io.metersphere.jmeter.reporters.ThreadGroupAutoStop"; private EngineContext context; - private boolean containsIterationThread = false; @Override public String parse(EngineContext context, Document document) throws Exception { @@ -98,6 +98,7 @@ public class JmeterDocumentParser implements DocumentParser { processCheckoutResponseAssertion(ele); processCheckoutSerializeThreadgroups(ele); processCheckoutBackendListener(ele); + processCheckoutAutoStopListener(ele); } else if (nodeNameEquals(ele, CONCURRENCY_THREAD_GROUP)) { processThreadGroupName(ele); processCheckoutTimer(ele); @@ -113,7 +114,6 @@ public class JmeterDocumentParser implements DocumentParser { } if ("ITERATION".equals(o)) { processIterationThreadGroup(ele); - this.containsIterationThread = true; // 包括按照迭代次数的线程组 } } else { processThreadGroup(ele); @@ -134,6 +134,8 @@ public class JmeterDocumentParser implements DocumentParser { processResponseAssertion(ele); } else if (nodeNameEquals(ele, CSV_DATA_SET)) { processCsvDataSet(ele); + } else if (nodeNameEquals(ele, THREAD_GROUP_AUTO_STOP)) { + processAutoStopListener(ele); } // 处理http上传的附件 if (isHTTPFileArg(ele)) { @@ -144,6 +146,46 @@ public class JmeterDocumentParser implements DocumentParser { } } + private void processAutoStopListener(Element autoStopListener) { + Object autoStopDelays = context.getProperty("autoStopDelay"); + String autoStopDelay = "30"; + if (autoStopDelays instanceof List) { + Object o = ((List) autoStopDelays).get(0); + autoStopDelay = o.toString(); + } + Document document = autoStopListener.getOwnerDocument(); + // 清空child + removeChildren(autoStopListener); + autoStopListener.appendChild(createStringProp(document, "delay_seconds", autoStopDelay)); + } + + private void processCheckoutAutoStopListener(Element element) { + Object autoStops = context.getProperty("autoStop"); + String autoStop = "false"; + if (autoStops instanceof List) { + Object o = ((List) autoStops).get(0); + autoStop = o.toString(); + } + if (!BooleanUtils.toBoolean(autoStop)) { + return; + } + + Document document = element.getOwnerDocument(); + Node listenerParent = element.getNextSibling(); + while (!(listenerParent instanceof Element)) { + listenerParent = listenerParent.getNextSibling(); + } + + // add class name + Element autoStopListener = document.createElement(THREAD_GROUP_AUTO_STOP); + autoStopListener.setAttribute("guiclass", "io.metersphere.jmeter.reporters.ThreadGroupAutoStopGui"); + autoStopListener.setAttribute("testclass", "io.metersphere.jmeter.reporters.ThreadGroupAutoStop"); + autoStopListener.setAttribute("testname", "MeterSphere - AutoStop Listener"); + autoStopListener.setAttribute("enabled", "true"); + listenerParent.appendChild(autoStopListener); + listenerParent.appendChild(document.createElement(HASH_TREE_ELEMENT)); + } + private void processCheckoutSerializeThreadgroups(Element element) { Object serializeThreadGroups = context.getProperty("serializeThreadGroups"); String serializeThreadGroup = "false"; @@ -548,15 +590,6 @@ public class JmeterDocumentParser implements DocumentParser { } private void processBackendListener(Element backendListener) { - String duration = "0"; - Object expectedDurations = context.getProperty("expectedDuration"); - if (expectedDurations instanceof List) { - Object o = ((List) expectedDurations).get(0);// 预计执行时间已经计算好 - duration = o.toString() + "000"; // 转成 ms - } - if (this.containsIterationThread) { - duration = Integer.MAX_VALUE + ""; // 如果包含了按照迭代次数的线程组,预计执行时间很长 - } KafkaProperties kafkaProperties = CommonBeanFactory.getBean(KafkaProperties.class); Document document = backendListener.getOwnerDocument(); // 清空child diff --git a/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue b/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue index 733104d668..72e0600329 100644 --- a/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue @@ -16,6 +16,19 @@ +
+ + + + + + + @@ -181,6 +194,8 @@ import {findThreadGroup} from "@/business/components/performance/test/model/Thre const HANDLER = "handler"; const THREAD_GROUP_TYPE = "tgType"; const SERIALIZE_THREAD_GROUPS = "serializeThreadGroups"; +const AUTO_STOP = "autoStop"; +const AUTO_STOP_DELAY = "autoStopDelay"; const TARGET_LEVEL = "TargetLevel"; const RAMP_UP = "RampUp"; const ITERATE_RAMP_UP = "iterateRampUpTime"; @@ -236,6 +251,8 @@ export default { resourcePoolResourceLength: 1, maxThreadNumbers: 5000, serializeThreadGroups: false, + autoStop: false, + autoStopDelay: 30, } }, mounted() { @@ -325,6 +342,12 @@ export default { case SERIALIZE_THREAD_GROUPS: this.serializeThreadGroups = item.value;// 所有的线程组值一样 break; + case AUTO_STOP: + this.autoStop = item.value;// 所有的线程组值一样 + break; + case AUTO_STOP_DELAY: + this.autoStopDelay = item.value;// 所有的线程组值一样 + break; default: break; } @@ -670,6 +693,8 @@ export default { {key: DELETED, value: this.threadGroups[i].deleted}, {key: THREAD_GROUP_TYPE, value: this.threadGroups[i].tgType}, {key: SERIALIZE_THREAD_GROUPS, value: this.serializeThreadGroups}, + {key: AUTO_STOP, value: this.autoStop}, + {key: AUTO_STOP_DELAY, value: this.autoStopDelay}, ]); }