From c0b3a961a5b6eab7d2fb22b53571cd8efba9af0e Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 22 Jul 2021 14:39:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E9=AB=98=E7=BA=A7=E9=85=8D=E7=BD=AE=E6=94=AF=E6=8C=81=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../performance/engine/EngineFactory.java | 59 ++-- .../xml/reader/jmx/JmeterDocumentParser.java | 95 ------- .../components/PerformanceAdvancedConfig.vue | 259 +++++++++++------- 3 files changed, 209 insertions(+), 204 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java b/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java index e9b113ca9e..ac29660d3f 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java +++ b/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java @@ -158,23 +158,12 @@ public class EngineFactory { {"timeout":10,"statusCode":["302","301"],"params":[{"name":"param1","enable":true,"value":"0","edit":false}],"domains":[{"domain":"baidu.com","enable":true,"ip":"127.0.0.1","edit":false}]} */ Map testResourceFiles = new HashMap<>(); - StringBuilder props = new StringBuilder("# JMeter Properties\n"); - if (StringUtils.isNotEmpty(loadTest.getAdvancedConfiguration())) { - JSONObject advancedConfiguration = JSONObject.parseObject(loadTest.getAdvancedConfiguration()); - engineContext.addProperties(advancedConfiguration); - JSONArray properties = advancedConfiguration.getJSONArray("properties"); - if (properties != null) { - for (int i = 0; i < properties.size(); i++) { - JSONObject prop = properties.getJSONObject(i); - if (!prop.getBoolean("enable")) { - continue; - } - props.append(prop.getString("name")).append("=").append(prop.getString("value")).append("\n"); - } - } - } + byte[] props = getJMeterProperties(loadTest, engineContext); + byte[] hosts = getDNSConfig(loadTest, engineContext); // JMeter Properties - testResourceFiles.put("ms.properties", props.toString().getBytes(StandardCharsets.UTF_8)); + testResourceFiles.put("ms.properties", props); + // DNS + testResourceFiles.put("hosts", hosts); final EngineSourceParser engineSourceParser = EngineSourceParserFactory.createEngineSourceParser(engineContext.getFileType()); @@ -204,6 +193,44 @@ public class EngineFactory { return engineContext; } + private static byte[] getDNSConfig(LoadTestWithBLOBs loadTest, EngineContext engineContext) { + StringBuilder dns = new StringBuilder("# DNS Config\n"); + if (StringUtils.isNotEmpty(loadTest.getAdvancedConfiguration())) { + JSONObject advancedConfiguration = JSONObject.parseObject(loadTest.getAdvancedConfiguration()); + engineContext.addProperties(advancedConfiguration); + JSONArray domains = advancedConfiguration.getJSONArray("domains"); + if (domains != null) { + for (int i = 0; i < domains.size(); i++) { + JSONObject prop = domains.getJSONObject(i); + if (!prop.getBoolean("enable")) { + continue; + } + dns.append(prop.getString("ip")).append(" ").append(prop.getString("domain")).append("\n"); + } + } + } + return dns.toString().getBytes(StandardCharsets.UTF_8); + } + + private static byte[] getJMeterProperties(LoadTestWithBLOBs loadTest, EngineContext engineContext) { + StringBuilder props = new StringBuilder("# JMeter Properties\n"); + if (StringUtils.isNotEmpty(loadTest.getAdvancedConfiguration())) { + JSONObject advancedConfiguration = JSONObject.parseObject(loadTest.getAdvancedConfiguration()); + engineContext.addProperties(advancedConfiguration); + JSONArray properties = advancedConfiguration.getJSONArray("properties"); + if (properties != null) { + for (int i = 0; i < properties.size(); i++) { + JSONObject prop = properties.getJSONObject(i); + if (!prop.getBoolean("enable")) { + continue; + } + props.append(prop.getString("name")).append("=").append(prop.getString("value")).append("\n"); + } + } + } + return props.toString().getBytes(StandardCharsets.UTF_8); + } + public static byte[] mergeJmx(List jmxFiles) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 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 70fde6a9af..c9c248ee33 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 @@ -41,7 +41,6 @@ public class JmeterDocumentParser implements DocumentParser { 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"; private final static String ARGUMENTS = "Arguments"; private final static String RESPONSE_ASSERTION = "ResponseAssertion"; private final static String HTTP_SAMPLER_PROXY = "HTTPSamplerProxy"; @@ -96,7 +95,6 @@ public class JmeterDocumentParser implements DocumentParser { parseHashTree(ele); } else if (nodeNameEquals(ele, TEST_PLAN)) { processCheckoutConfigTestElement(ele); - processCheckoutDnsCacheManager(ele); processCheckoutArguments(ele); processCheckoutResponseAssertion(ele); processCheckoutSerializeThreadgroups(ele); @@ -118,9 +116,6 @@ public class JmeterDocumentParser implements DocumentParser { processBackendListener(ele); } else if (nodeNameEquals(ele, CONFIG_TEST_ELEMENT)) { processConfigTestElement(ele); - } else if (nodeNameEquals(ele, DNS_CACHE_MANAGER)) { - // todo dns cache manager bug: https://bz.apache.org/bugzilla/show_bug.cgi?id=63858 - // processDnsCacheManager(ele); } else if (nodeNameEquals(ele, ARGUMENTS)) { processArguments(ele); } else if (nodeNameEquals(ele, RESPONSE_ASSERTION)) { @@ -461,59 +456,6 @@ public class JmeterDocumentParser implements DocumentParser { hashTree.appendChild(document.createElement(HASH_TREE_ELEMENT)); } - private void processCheckoutDnsCacheManager(Element ele) { - if (context.getProperty("domains") == null || JSON.parseArray(context.getProperty("domains").toString()).size() == 0) { - return; - } - Node hashTree = ele.getNextSibling(); - while (!(hashTree instanceof Element)) { - hashTree = hashTree.getNextSibling(); - } - - NodeList childNodes = hashTree.getChildNodes(); - for (int i = 0, size = childNodes.getLength(); i < size; i++) { - Node item = childNodes.item(i); - if (nodeNameEquals(item, DNS_CACHE_MANAGER)) { - // 已经存在不再添加 - return; - } - } - /* - - - - - baiud.com - 172.16.10.187 - - - true - true - - */ - - Document document = ele.getOwnerDocument(); - Element element = document.createElement(DNS_CACHE_MANAGER); - element.setAttribute("guiclass", "DNSCachePanel"); - element.setAttribute("testclass", "DNSCacheManager"); - element.setAttribute("testname", "DNS Cache Manager"); - element.setAttribute("enabled", "true"); - Element collectionProp = document.createElement(COLLECTION_PROP); - collectionProp.setAttribute("name", "DNSCacheManager.servers"); - element.appendChild(collectionProp); - - Element collectionProp2 = document.createElement(COLLECTION_PROP); - collectionProp2.setAttribute("name", "DNSCacheManager.hosts"); - element.appendChild(collectionProp2); - - element.appendChild(createBoolProp(document, "DNSCacheManager.clearEachIteration", true)); - element.appendChild(createBoolProp(document, "DNSCacheManager.isCustomResolver", true)); - - hashTree.appendChild(element); - // 空的 hashTree - hashTree.appendChild(document.createElement(HASH_TREE_ELEMENT)); - } - private void processCheckoutConfigTestElement(Element ele) { if (context.getProperty("timeout") == null || StringUtils.isBlank(context.getProperty("timeout").toString())) { return; @@ -607,43 +549,6 @@ public class JmeterDocumentParser implements DocumentParser { } - private void processDnsCacheManager(Element ele) { - - Object domains = context.getProperty("domains"); - if (!(domains instanceof List)) { - return; - } - if (((List) domains).size() == 0) { - return; - } - NodeList childNodes = ele.getChildNodes(); - for (int i = 0, size = childNodes.getLength(); i < size; i++) { - Node item = childNodes.item(i); - if (item instanceof Element && nodeNameEquals(item, "collectionProp") - && org.apache.commons.lang3.StringUtils.equals(((Element) item).getAttribute("name"), "DNSCacheManager.hosts")) { - - Document document = item.getOwnerDocument(); - for (Object d : (List) domains) { - JSONObject jsonObject = JSON.parseObject(d.toString()); - if (!jsonObject.getBooleanValue("enable")) { - continue; - } - Element elementProp = document.createElement("elementProp"); - elementProp.setAttribute("name", jsonObject.getString("domain")); - elementProp.setAttribute("elementType", "StaticHost"); - elementProp.appendChild(createStringProp(document, "StaticHost.Name", jsonObject.getString("domain"))); - elementProp.appendChild(createStringProp(document, "StaticHost.Address", jsonObject.getString("ip"))); - item.appendChild(elementProp); - } - } - if (item instanceof Element && nodeNameEquals(item, BOOL_PROP) - && org.apache.commons.lang3.StringUtils.equals(((Element) item).getAttribute("name"), "DNSCacheManager.isCustomResolver")) { - item.getFirstChild().setNodeValue("true"); - } - } - - } - private void processConfigTestElement(Element ele) { NodeList childNodes = ele.getChildNodes(); diff --git a/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue b/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue index 1743765043..1c1a02da02 100644 --- a/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue @@ -9,8 +9,8 @@ + :disabled="readOnly" size="mini" v-model="timeout" + :min="0"/> ms @@ -24,8 +24,8 @@ + :disabled="readOnly" size="mini" :min="0" + v-model="responseTimeout"/> ms @@ -38,9 +38,9 @@
{{ $t('load_test.granularity') }} + placement="left" + width="300" + trigger="hover">