From c426bb2064d85b475ef1ec06c1916ee7bc8c8afa Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Mon, 15 Mar 2021 16:55:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8E=8B=E6=B5=8B=E6=97=B6=E9=95=BF=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8D=95=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xml/reader/jmx/JmeterDocumentParser.java | 44 +++++++++++++++++-- .../components/PerformancePressureConfig.vue | 35 +++++++++++---- .../components/PerformanceAdvancedConfig.vue | 2 +- .../components/PerformancePressureConfig.vue | 41 ++++++++++++----- .../performance/test/model/ThreadGroup.js | 1 + frontend/src/i18n/en-US.js | 2 +- frontend/src/i18n/zh-CN.js | 6 +-- frontend/src/i18n/zh-TW.js | 2 +- 8 files changed, 105 insertions(+), 28 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 13ffc9a34e..09fbda18a5 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 @@ -676,6 +676,13 @@ public class JmeterDocumentParser implements DocumentParser { ((List) durations).remove(0); duration = o.toString(); } + Object units = context.getProperty("unit"); + String unit = "S"; + if (units instanceof List) { + Object o = ((List) units).get(0); + ((List) units).remove(0); + unit = o.toString(); + } Object deleteds = context.getProperty("deleted"); String deleted = "false"; if (deleteds instanceof List) { @@ -691,6 +698,17 @@ public class JmeterDocumentParser implements DocumentParser { enabled = o.toString(); } + switch (unit) { + case "M": + duration = String.valueOf(Long.parseLong(duration) * 60); + break; + case "H": + duration = String.valueOf(Long.parseLong(duration) * 60 * 60); + break; + default: + break; + } + threadGroup.setAttribute("enabled", enabled); if (BooleanUtils.toBoolean(deleted)) { threadGroup.setAttribute("enabled", "false"); @@ -761,6 +779,13 @@ public class JmeterDocumentParser implements DocumentParser { ((List) holds).remove(0); hold = o.toString(); } + Object units = context.getProperty("unit"); + String unit = "S"; + if (units instanceof List) { + Object o = ((List) units).get(0); + ((List) units).remove(0); + unit = o.toString(); + } Object deleteds = context.getProperty("deleted"); String deleted = "false"; if (deleteds instanceof List) { @@ -776,6 +801,17 @@ public class JmeterDocumentParser implements DocumentParser { enabled = o.toString(); } + switch (unit) { + case "M": + hold = String.valueOf(Long.parseLong(hold) * 60); + break; + case "H": + hold = String.valueOf(Long.parseLong(hold) * 60 * 60); + break; + default: + break; + } + threadGroup.setAttribute("enabled", enabled); if (BooleanUtils.toBoolean(deleted)) { threadGroup.setAttribute("enabled", "false"); @@ -928,10 +964,10 @@ public class JmeterDocumentParser implements DocumentParser { } private Element createStringProp(Document document, String name, String value) { - Element unit = document.createElement(STRING_PROP); - unit.setAttribute("name", name); - unit.appendChild(document.createTextNode(value)); - return unit; + Element element = document.createElement(STRING_PROP); + element.setAttribute("name", name); + element.appendChild(document.createTextNode(value)); + return element; } private void processThreadGroupName(Element threadGroup) { diff --git a/frontend/src/business/components/performance/report/components/PerformancePressureConfig.vue b/frontend/src/business/components/performance/report/components/PerformancePressureConfig.vue index 2157353b8d..633b28f122 100644 --- a/frontend/src/business/components/performance/report/components/PerformancePressureConfig.vue +++ b/frontend/src/business/components/performance/report/components/PerformancePressureConfig.vue @@ -37,6 +37,13 @@ @change="calculateChart(threadGroup)" size="mini"/> + + + {{ $t('schedule.cron.seconds') }} + {{ $t('schedule.cron.minutes') }} + {{ $t('schedule.cron.hours') }} + +
@@ -59,7 +66,7 @@ @change="calculateChart(threadGroup)" size="mini"/> - + - + @@ -112,7 +119,7 @@ @change="calculateChart(threadGroup)" size="mini"/> - + @@ -137,6 +144,7 @@ const TARGET_LEVEL = "TargetLevel"; const RAMP_UP = "RampUp"; const STEPS = "Steps"; const DURATION = "duration"; +const UNIT = "unit"; const RPS_LIMIT = "rpsLimit"; const RPS_LIMIT_ENABLE = "rpsLimitEnable"; const THREAD_TYPE = "threadType"; @@ -196,11 +204,10 @@ export default { this.threadGroups[i].iterateRampUp = item.value; break; case DURATION: - if (item.unit) { - this.threadGroups[i].duration = item.value; - } else { - this.threadGroups[i].duration = item.value * 60; - } + this.threadGroups[i].duration = item.value; + break; + case UNIT: + this.threadGroups[i].unit = item.value; break; case STEPS: this.threadGroups[i].step = item.value; @@ -506,6 +513,18 @@ export default { } this.calculateTotalChart(); }, + getUnitLabel(tg) { + if (tg.unit === 'S') { + return this.$t('schedule.cron.seconds'); + } + if (tg.unit === 'M') { + return this.$t('schedule.cron.minutes'); + } + if (tg.unit === 'H') { + return this.$t('schedule.cron.hours'); + } + return this.$t('schedule.cron.seconds'); + }, }, watch: { report: { diff --git a/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue b/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue index 5a835228bd..fcacb7434e 100644 --- a/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue @@ -130,7 +130,7 @@ diff --git a/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue b/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue index c800972a24..29df9f4e18 100644 --- a/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue @@ -47,10 +47,17 @@ :disabled="isReadOnly" v-model="threadGroup.duration" :min="1" - :max="172800" + :max="99999" @change="calculateChart(threadGroup)" size="mini"/> + + + {{ $t('schedule.cron.seconds') }} + {{ $t('schedule.cron.minutes') }} + {{ $t('schedule.cron.hours') }} + +
@@ -74,7 +81,7 @@ @change="calculateChart(threadGroup)" size="mini"/> - + - + @@ -128,7 +135,7 @@ v-model="threadGroup.iterateRampUp" size="mini"/> - + @@ -154,6 +161,7 @@ const RAMP_UP = "RampUp"; const ITERATE_RAMP_UP = "iterateRampUpTime"; const STEPS = "Steps"; const DURATION = "duration"; +const UNIT = "unit"; const RPS_LIMIT = "rpsLimit"; const RPS_LIMIT_ENABLE = "rpsLimitEnable"; const HOLD = "Hold"; @@ -253,11 +261,10 @@ export default { this.threadGroups[i].iterateRampUp = item.value; break; case DURATION: - if (item.unit) { - this.threadGroups[i].duration = item.value; - } else { - this.threadGroups[i].duration = item.value * 60; - } + this.threadGroups[i].duration = item.value; + break; + case UNIT: + this.threadGroups[i].unit = item.value; break; case STEPS: this.threadGroups[i].step = item.value; @@ -290,6 +297,7 @@ export default { break; } // + this.$set(this.threadGroups[i], "unit", this.threadGroups[i].unit || 'S'); this.$set(this.threadGroups[i], "threadType", this.threadGroups[i].threadType || 'DURATION'); this.$set(this.threadGroups[i], "iterateNum", this.threadGroups[i].iterateNum || 1); this.$set(this.threadGroups[i], "iterateRampUp", this.threadGroups[i].iterateRampUp || 10); @@ -576,6 +584,18 @@ export default { return true; }, + getUnitLabel(tg) { + if (tg.unit === 'S') { + return this.$t('schedule.cron.seconds'); + } + if (tg.unit === 'M') { + return this.$t('schedule.cron.minutes'); + } + if (tg.unit === 'H') { + return this.$t('schedule.cron.hours'); + } + return this.$t('schedule.cron.seconds'); + }, convertProperty() { /// todo:下面4个属性是jmeter ConcurrencyThreadGroup plugin的属性,这种硬编码不太好吧,在哪能转换这种属性? let result = []; @@ -585,7 +605,8 @@ export default { {key: TARGET_LEVEL, value: this.threadGroups[i].threadNumber}, {key: RAMP_UP, value: this.threadGroups[i].rampUpTime}, {key: STEPS, value: this.threadGroups[i].step}, - {key: DURATION, value: this.threadGroups[i].duration, unit: 'S'}, + {key: DURATION, value: this.threadGroups[i].duration, unit: this.threadGroups[i].unit}, + {key: UNIT, value: this.threadGroups[i].unit}, {key: RPS_LIMIT, value: this.threadGroups[i].rpsLimit}, {key: RPS_LIMIT_ENABLE, value: this.threadGroups[i].rpsLimitEnable}, {key: HOLD, value: this.threadGroups[i].duration - this.threadGroups[i].rampUpTime}, diff --git a/frontend/src/business/components/performance/test/model/ThreadGroup.js b/frontend/src/business/components/performance/test/model/ThreadGroup.js index b4656c8af5..2d44f13c5a 100644 --- a/frontend/src/business/components/performance/test/model/ThreadGroup.js +++ b/frontend/src/business/components/performance/test/model/ThreadGroup.js @@ -31,6 +31,7 @@ export function findThreadGroup(jmxContent, handler) { tg.enabled = tg.attributes.enabled; tg.tgType = tg.name; tg.threadType = 'DURATION'; + tg.unit = 'S'; }) return threadGroups; } diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 91e69c74ce..2e69834217 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -481,7 +481,7 @@ export default { delete_file: "The file already exists, please delete the file with the same name first!", thread_num: 'Concurrent users:', input_thread_num: 'Please enter the number of threads', - duration: 'Duration time (seconds)', + duration: 'Duration time', granularity: 'Aggregation time (seconds)', input_duration: 'Please enter a duration', rps_limit: 'RPS Limit:', diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index db08f19989..232b611f71 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -478,14 +478,14 @@ export default { delete_file: "文件已存在,请先删除同名文件!", thread_num: '并发用户数:', input_thread_num: '请输入线程数', - duration: '压测时长(秒)', + duration: '压测时长', granularity: '聚合时间(秒)', input_duration: '请输入时长', rps_limit: 'RPS上限:', input_rps_limit: '请输入限制', ramp_up_time_within: '在', - ramp_up_time_minutes: '秒内,分', - ramp_up_time_seconds: '秒内增加并发用户', + ramp_up_time_minutes: '{0}内,分', + ramp_up_time_seconds: '{0}内增加并发用户', iterate_num: '迭代次数 (次): ', by_iteration: '按迭代次数', by_duration: '按持续时间', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index ccbc5805d6..17cd3fb05e 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -478,7 +478,7 @@ export default { delete_file: "文件已存在,請先刪除同名文件!", thread_num: '並發用戶數:', input_thread_num: '請輸入線程數', - duration: '壓測時長(秒)', + duration: '壓測時長', granularity: '聚合時間(秒)', input_duration: '請輸入時長', rps_limit: 'RPS上限:',