refactor(性能测试): 性能测试显示setup和post线程组

This commit is contained in:
Captain.B 2021-05-17 14:42:55 +08:00 committed by 刘瑞斌
parent 0bb5503a1c
commit 7c75cc3738
4 changed files with 65 additions and 22 deletions

View File

@ -35,6 +35,8 @@ public class JmeterDocumentParser implements DocumentParser {
private final static String CONCURRENCY_THREAD_GROUP = "com.blazemeter.jmeter.threads.concurrency.ConcurrencyThreadGroup";
private final static String VARIABLE_THROUGHPUT_TIMER = "kg.apc.jmeter.timers.VariableThroughputTimer";
private final static String THREAD_GROUP = "ThreadGroup";
private final static String POST_THREAD_GROUP = "PostThreadGroup";
private final static String SETUP_THREAD_GROUP = "SetupThreadGroup";
private final static String BACKEND_LISTENER = "BackendListener";
private final static String CONFIG_TEST_ELEMENT = "ConfigTestElement";
private final static String DNS_CACHE_MANAGER = "DNSCacheManager";
@ -107,7 +109,9 @@ public class JmeterDocumentParser implements DocumentParser {
processCheckoutTimer(ele);
} else if (nodeNameEquals(ele, VARIABLE_THROUGHPUT_TIMER)) {
processVariableThroughputTimer(ele);
} else if (nodeNameEquals(ele, THREAD_GROUP)) {
} else if (nodeNameEquals(ele, THREAD_GROUP) ||
nodeNameEquals(ele, SETUP_THREAD_GROUP) ||
nodeNameEquals(ele, POST_THREAD_GROUP)) {
processThreadType(ele);
processThreadGroupName(ele);
processCheckoutTimer(ele);
@ -707,7 +711,13 @@ public class JmeterDocumentParser implements DocumentParser {
tgType = o.toString();
}
if (StringUtils.equals(tgType, THREAD_GROUP)) {
processBaseThreadGroup(threadGroup);
processBaseThreadGroup(threadGroup, THREAD_GROUP);
}
if (StringUtils.equals(tgType, SETUP_THREAD_GROUP)) {
processBaseThreadGroup(threadGroup, SETUP_THREAD_GROUP);
}
if (StringUtils.equals(tgType, POST_THREAD_GROUP)) {
processBaseThreadGroup(threadGroup, POST_THREAD_GROUP);
}
if (StringUtils.equals(tgType, CONCURRENCY_THREAD_GROUP)) {
processConcurrencyThreadGroup(threadGroup);
@ -715,11 +725,11 @@ public class JmeterDocumentParser implements DocumentParser {
}
private void processBaseThreadGroup(Element threadGroup) {
private void processBaseThreadGroup(Element threadGroup, String tgType) {
Document document = threadGroup.getOwnerDocument();
document.renameNode(threadGroup, threadGroup.getNamespaceURI(), THREAD_GROUP);
threadGroup.setAttribute("guiclass", THREAD_GROUP + "Gui");
threadGroup.setAttribute("testclass", THREAD_GROUP);
document.renameNode(threadGroup, threadGroup.getNamespaceURI(), tgType);
threadGroup.setAttribute("guiclass", tgType + "Gui");
threadGroup.setAttribute("testclass", tgType);
/*
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="登录" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
@ -918,9 +928,6 @@ public class JmeterDocumentParser implements DocumentParser {
private void processIterationThreadGroup(Element threadGroup) {
Document document = threadGroup.getOwnerDocument();
document.renameNode(threadGroup, threadGroup.getNamespaceURI(), THREAD_GROUP);
threadGroup.setAttribute("guiclass", THREAD_GROUP + "Gui");
threadGroup.setAttribute("testclass", THREAD_GROUP);
// 检查 threadgroup 后面的hashtree是否为空
Node hashTree = threadGroup.getNextSibling();
while (!(hashTree instanceof Element)) {
@ -929,6 +936,28 @@ 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)) {
document.renameNode(threadGroup, threadGroup.getNamespaceURI(), THREAD_GROUP);
threadGroup.setAttribute("guiclass", THREAD_GROUP + "Gui");
threadGroup.setAttribute("testclass", THREAD_GROUP);
}
if (StringUtils.equals(tgType, SETUP_THREAD_GROUP)) {
document.renameNode(threadGroup, threadGroup.getNamespaceURI(), SETUP_THREAD_GROUP);
threadGroup.setAttribute("guiclass", SETUP_THREAD_GROUP + "Gui");
threadGroup.setAttribute("testclass", SETUP_THREAD_GROUP);
}
if (StringUtils.equals(tgType, POST_THREAD_GROUP)) {
document.renameNode(threadGroup, threadGroup.getNamespaceURI(), POST_THREAD_GROUP);
threadGroup.setAttribute("guiclass", POST_THREAD_GROUP + "Gui");
threadGroup.setAttribute("testclass", POST_THREAD_GROUP);
}
removeChildren(threadGroup);
// 选择按照迭代次数处理线程组

View File

@ -98,7 +98,6 @@ import {getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils";
import MsTableHeader from "../../common/components/MsTableHeader";
import {TEST_CONFIGS} from "../../common/components/search/search-components";
import {LIST_CHANGE, PerformanceEvent} from "@/business/components/common/head/ListEvent";
import {PROJECT_ID, WORKSPACE_ID} from "@/common/js/constants";
import {_filter, _sort} from "@/common/js/tableUtils";
export default {
@ -151,6 +150,9 @@ export default {
},
watch: {
'$route'(to) {
if (to.name !== 'perPlan') {
return;
}
this.projectId = to.params.projectId;
this.initTableData();
}

View File

@ -31,7 +31,10 @@
<el-table-column
:label="$t('load_test.thread_group')">
<template v-slot:default="{row}">
<el-select v-model="row.tgType" :placeholder="$t('commons.please_select')" size="small"
<span v-if="row.tgType === 'PostThreadGroup' || row.tgType === 'SetupThreadGroup'">
{{ row.tgType }}
</span>
<el-select v-else v-model="row.tgType" :placeholder="$t('commons.please_select')" size="small"
@change="tgTypeChange(row)">
<el-option v-for="tg in threadGroupForSelect" :key="tg.tagName" :label="tg.name"
:value="tg.testclass"></el-option>
@ -171,13 +174,13 @@ export default {
},
created() {
if (this.test.id) {
this.getFileMetadata(this.test)
this.getFileMetadata(this.test);
}
},
watch: {
test() {
if (this.test.id) {
this.getFileMetadata(this.test)
this.getFileMetadata(this.test);
}
}
},
@ -199,7 +202,7 @@ export default {
this.tableData.map(f => {
f.size = (f.size / 1024).toFixed(2) + ' KB';
});
})
});
},
selectAttachFileById(metadataIdArr) {
this.metadataIdList = metadataIdArr;
@ -214,7 +217,7 @@ export default {
f.size = (f.size / 1024).toFixed(2) + ' KB';
});
}
})
});
}
},
handleDownload(file) {
@ -238,10 +241,10 @@ export default {
aTag.download = file.name;
aTag.href = URL.createObjectURL(blob);
aTag.click();
URL.revokeObjectURL(aTag.href)
URL.revokeObjectURL(aTag.href);
} else {
// IE10+
navigator.msSaveBlob(blob, this.filename)
navigator.msSaveBlob(blob, this.filename);
}
}).catch(e => {
Message.error({message: e.message, showClose: true});
@ -357,7 +360,7 @@ export default {
this.$refs.existScenarios.handleImport();
},
},
}
};
</script>
<style scoped>

View File

@ -6,6 +6,8 @@ let travel = function (elements, threadGroups) {
}
for (let element of elements) {
switch (element.name) {
case "SetupThreadGroup":
case "PostThreadGroup":
case "ThreadGroup":
case "kg.apc.jmeter.threads.UltimateThreadGroup":
case "com.blazemeter.jmeter.threads.concurrency.ConcurrencyThreadGroup":
@ -17,9 +19,9 @@ let travel = function (elements, threadGroups) {
default:
break;
}
travel(element.elements, threadGroups)
travel(element.elements, threadGroups);
}
}
};
export function findThreadGroup(jmxContent, handler) {
let jmxJson = JSON.parse(xml2json(jmxContent));
@ -30,9 +32,16 @@ export function findThreadGroup(jmxContent, handler) {
tg.handler = handler;
tg.enabled = tg.attributes.enabled;
tg.tgType = tg.name;
tg.threadType = 'DURATION';
if (tg.name === 'SetupThreadGroup' || tg.name === 'PostThreadGroup') {
tg.threadType = 'ITERATION';
tg.threadNumber = 1;
tg.iterateRampUp = 1;
} else {
tg.threadType = 'DURATION';
tg.threadNumber = 1;
}
tg.unit = 'S';
})
});
return threadGroups;
}