From 7599c4c5fcec108e3fa99c1ecd878f30767aef4c Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Fri, 5 Mar 2021 15:57:25 +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=E9=80=89=E6=8B=A9=E7=BA=BF=E7=A8=8B=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xml/reader/jmx/JmeterDocumentParser.java | 75 +++++++++++++++++++ .../components/PerformanceBasicConfig.vue | 18 ++++- .../components/PerformancePressureConfig.vue | 57 +++++++++----- .../performance/test/model/ThreadGroup.js | 2 + 4 files changed, 132 insertions(+), 20 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 0af5537b3d..7b5cc8c44d 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 @@ -594,6 +594,81 @@ public class JmeterDocumentParser implements DocumentParser { if (!hashTree.hasChildNodes()) { MSException.throwException(Translator.get("jmx_content_valid")); } + Object tgTypes = context.getProperty("tgType"); + String tgType = "ThreadGroup"; + if (tgTypes instanceof List) { + Object o = ((List) tgTypes).get(0); + ((List) tgTypes).remove(0); + tgType = o.toString(); + } + if (StringUtils.equals(tgType, THREAD_GROUP)) { + processBaseThreadGroup(threadGroup); + } + if (StringUtils.equals(tgType, CONCURRENCY_THREAD_GROUP)) { + processConcurrencyThreadGroup(threadGroup); + } + + } + + private void processBaseThreadGroup(Element threadGroup) { + /* + + continue + + false + 1 + + 1 + 1 + false + + + true + + */ + removeChildren(threadGroup); + Document document = threadGroup.getOwnerDocument(); + Object targetLevels = context.getProperty("TargetLevel"); + String threads = "10"; + if (targetLevels instanceof List) { + Object o = ((List) targetLevels).get(0); + ((List) targetLevels).remove(0); + threads = o.toString(); + } + Object rampUps = context.getProperty("RampUp"); + String rampUp = "1"; + if (rampUps instanceof List) { + Object o = ((List) rampUps).get(0); + ((List) rampUps).remove(0); + rampUp = o.toString(); + } + Object holds = context.getProperty("Hold"); + String hold = "2"; + if (holds instanceof List) { + Object o = ((List) holds).get(0); + ((List) holds).remove(0); + hold = o.toString(); + } + Element elementProp = document.createElement("elementProp"); + elementProp.setAttribute("name", "ThreadGroup.main_controller"); + elementProp.setAttribute("elementType", "LoopController"); + elementProp.setAttribute("guiclass", "LoopControlPanel"); + elementProp.setAttribute("testclass", "LoopController"); + elementProp.setAttribute("testname", "Loop Controller"); + elementProp.setAttribute("enabled", "true"); + elementProp.appendChild(createBoolProp(document, "LoopController.continue_forever", false)); + elementProp.appendChild(createStringProp(document, "LoopController.loops", "-1")); + threadGroup.appendChild(elementProp); + threadGroup.appendChild(createStringProp(document, "ThreadGroup.on_sample_error", "continue")); + threadGroup.appendChild(createStringProp(document, "ThreadGroup.num_threads", threads)); + threadGroup.appendChild(createStringProp(document, "ThreadGroup.ramp_time", rampUp)); + threadGroup.appendChild(createStringProp(document, "ThreadGroup.duration", hold)); + threadGroup.appendChild(createStringProp(document, "ThreadGroup.delay", "0")); + threadGroup.appendChild(createBoolProp(document, "ThreadGroup.scheduler", true)); + threadGroup.appendChild(createBoolProp(document, "ThreadGroup.same_user_on_next_iteration", true)); + } + + private void processConcurrencyThreadGroup(Element threadGroup) { // 重命名 tagName Document document = threadGroup.getOwnerDocument(); document.renameNode(threadGroup, threadGroup.getNamespaceURI(), CONCURRENCY_THREAD_GROUP); diff --git a/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue b/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue index d78dbf9670..076c0df6a5 100644 --- a/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue @@ -46,7 +46,9 @@
- - - - - - - +
+ + + + + + + +
+ +
+ + + + +
+
@@ -131,6 +145,7 @@ import MsChart from "@/business/components/common/chart/MsChart"; import {findThreadGroup} from "@/business/components/performance/test/model/ThreadGroup"; const HANDLER = "handler"; +const THREAD_GROUP_TYPE = "tgType"; const TARGET_LEVEL = "TargetLevel"; const RAMP_UP = "RampUp"; const ITERATE_RAMP_UP = "iterateRampUpTime"; @@ -265,6 +280,9 @@ export default { case HANDLER: this.threadGroups[i].handler = item.value; break; + case THREAD_GROUP_TYPE: + this.threadGroups[i].tgType = item.value; + break; default: break; } @@ -535,6 +553,7 @@ export default { {key: ITERATE_RAMP_UP, value: this.threadGroups[i].iterateRampUp}, {key: ENABLED, value: this.threadGroups[i].enabled}, {key: DELETED, value: this.threadGroups[i].deleted}, + {key: THREAD_GROUP_TYPE, value: this.threadGroups[i].tgType}, ]); } return result; diff --git a/frontend/src/business/components/performance/test/model/ThreadGroup.js b/frontend/src/business/components/performance/test/model/ThreadGroup.js index d97368e831..b4656c8af5 100644 --- a/frontend/src/business/components/performance/test/model/ThreadGroup.js +++ b/frontend/src/business/components/performance/test/model/ThreadGroup.js @@ -29,6 +29,8 @@ export function findThreadGroup(jmxContent, handler) { tg.deleted = 'false'; tg.handler = handler; tg.enabled = tg.attributes.enabled; + tg.tgType = tg.name; + tg.threadType = 'DURATION'; }) return threadGroups; }