添加setup thread group

This commit is contained in:
Captain.B 2020-06-16 15:57:09 +08:00
parent 74eacb1bd4
commit 204d01ee97
2 changed files with 82 additions and 1 deletions

View File

@ -85,6 +85,7 @@ public class JmeterDocumentParser implements DocumentParser {
if (nodeNameEquals(ele, HASH_TREE_ELEMENT)) {
parseHashTree(ele);
} else if (nodeNameEquals(ele, TEST_PLAN)) {
processSetupTestPlan(ele);
processTearDownTestPlan(ele);
processCheckoutConfigTestElement(ele);
processCheckoutDnsCacheManager(ele);
@ -436,6 +437,87 @@ public class JmeterDocumentParser implements DocumentParser {
}
}
private void processSetupTestPlan(Element ele) {
Document document = ele.getOwnerDocument();
Node hashTree = ele.getNextSibling();
while (!(hashTree instanceof Element)) {
hashTree = hashTree.getNextSibling();
}
KafkaProperties kafkaProperties = CommonBeanFactory.getBean(KafkaProperties.class);
String bootstrapServers = kafkaProperties.getBootstrapServers();
String[] servers = StringUtils.split(bootstrapServers, ",");
for (String s : servers) {
String[] ipAndPort = StringUtils.split(s, ":");
Element setupElement = document.createElement("SetupThreadGroup");
setupElement.setAttribute("guiclass", "SetupThreadGroupGui");
setupElement.setAttribute("testclass", "SetupThreadGroup");
setupElement.setAttribute("testname", "setUp Thread Group");
setupElement.setAttribute("enabled", "true");
setupElement.appendChild(createStringProp(document, "ThreadGroup.on_sample_error", "stoptestnow"));
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(createIntProp(document, "LoopController.loops", -1));
setupElement.appendChild(elementProp);
setupElement.appendChild(createStringProp(document, "ThreadGroup.num_threads", "1"));
setupElement.appendChild(createStringProp(document, "ThreadGroup.ramp_time", "1"));
setupElement.appendChild(createStringProp(document, "ThreadGroup.duration", ""));
setupElement.appendChild(createStringProp(document, "ThreadGroup.delay", ""));
setupElement.appendChild(createBoolProp(document, "ThreadGroup.scheduler", false));
setupElement.appendChild(createBoolProp(document, "ThreadGroup.same_user_on_next_iteration", true));
hashTree.appendChild(setupElement);
Element setupHashTree = document.createElement(HASH_TREE_ELEMENT);
Element tcpSampler = document.createElement("TCPSampler");
tcpSampler.setAttribute("guiclass", "TCPSamplerGui");
tcpSampler.setAttribute("testclass", "TCPSampler");
tcpSampler.setAttribute("testname", "TCP Sampler");
tcpSampler.setAttribute("enabled", "true");
tcpSampler.appendChild(createStringProp(document, "TCPSampler.classname", "TCPClientImpl"));
tcpSampler.appendChild(createStringProp(document, "TCPSampler.server", ipAndPort[0]));
tcpSampler.appendChild(createBoolProp(document, "TCPSampler.reUseConnection", true));
tcpSampler.appendChild(createStringProp(document, "TCPSampler.port", ipAndPort[1]));
tcpSampler.appendChild(createBoolProp(document, "TCPSampler.nodelay", false));
tcpSampler.appendChild(createStringProp(document, "TCPSampler.timeout", "100"));
tcpSampler.appendChild(createStringProp(document, "TCPSampler.ctimeout", "100"));
tcpSampler.appendChild(createStringProp(document, "TCPSampler.request", "1010"));
tcpSampler.appendChild(createBoolProp(document, "TCPSampler.closeConnection", false));
tcpSampler.appendChild(createStringProp(document, "TCPSampler.EolByte", "0"));
tcpSampler.appendChild(createStringProp(document, "ConfigTestElement.username", ""));
tcpSampler.appendChild(createStringProp(document, "ConfigTestElement.password", ""));
Element tcpSamplerHashTree = document.createElement(HASH_TREE_ELEMENT);
Element responseAssertion = document.createElement("ResponseAssertion");
responseAssertion.setAttribute("guiclass", "AssertionGui");
responseAssertion.setAttribute("testclass", "ResponseAssertion");
responseAssertion.setAttribute("testname", "Response Assertion");
responseAssertion.setAttribute("enabled", "true");
Element collectionProp = document.createElement("collectionProp");
collectionProp.setAttribute("name", "Asserion.test_strings");
collectionProp.appendChild(createStringProp(document, "49586", "200"));
responseAssertion.appendChild(collectionProp);
responseAssertion.appendChild(createStringProp(document, "Assertion.custom_message", ""));
responseAssertion.appendChild(createStringProp(document, "Assertion.test_field", "Assertion.response_code"));
responseAssertion.appendChild(createBoolProp(document, "Assertion.assume_success", false));
responseAssertion.appendChild(createIntProp(document, "Assertion.test_type", 8));
tcpSamplerHashTree.appendChild(responseAssertion);
// 添加空的hashtree
tcpSamplerHashTree.appendChild(document.createElement(HASH_TREE_ELEMENT));
setupHashTree.appendChild(tcpSampler);
setupHashTree.appendChild(tcpSamplerHashTree);
hashTree.appendChild(setupHashTree);
}
}
private void processTearDownTestPlan(Element ele) {
/*<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>*/

View File

@ -64,5 +64,4 @@ kafka.ssl.provider=
kafka.ssl.truststore-type=
# jmeter
jmeter.image=registry.fit2cloud.com/metersphere/jmeter-master:0.0.4
jmeter.home=/opt/jmeter