Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
q4speed 2020-05-05 19:49:48 +08:00
commit 69586479ba
9 changed files with 3 additions and 717 deletions

1
backend/.gitignore vendored
View File

@ -26,6 +26,7 @@ yarn-error.log*
src/main/resources/static src/main/resources/static
src/main/resources/templates src/main/resources/templates
src/test/
target target
.settings .settings
.project .project

View File

@ -3,7 +3,7 @@
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" > "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration> <generatorConfiguration>
<!--配置数据库连接的位置--> <!--配置数据库连接的位置-->
<properties url="file:///opt/fit2cloud/conf/metersphere.properties"/> <properties url="file:///opt/metersphere/conf/metersphere.properties"/>
<!-- 设置mysql驱动路径 --> <!-- 设置mysql驱动路径 -->
<!--<classPathEntry location="/Users/liuruibin/.m2/repository/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar"/>--> <!--<classPathEntry location="/Users/liuruibin/.m2/repository/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar"/>-->
<!-- 此处指定生成针对MyBatis3的DAO --> <!-- 此处指定生成针对MyBatis3的DAO -->

View File

@ -1,54 +0,0 @@
package io.metersphere;
import io.metersphere.base.domain.SystemParameter;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.utils.CompressUtils;
import io.metersphere.service.RegistryParamService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ApplicationTests {
@Resource
UserMapper userMapper;
@Resource
private RegistryParamService registryParamService;
@Test
public void test1() {
final Object test = CompressUtils.zip("test".getBytes());
final Object unzip = CompressUtils.unzip(test);
System.out.println(new String((byte[]) unzip));
}
@Test
public void test2() {
List<SystemParameter> registry = registryParamService.getRegistry(ParamConstants.Classify.REGISTRY.getValue());
System.out.println(registry);
for (SystemParameter sp : registry) {
if ("registry.password".equals(sp.getParamKey())) {
sp.setParamValue("Calong@2015");
}
if ("registry.url".equals(sp.getParamKey())) {
sp.setParamValue("registry.fit2cloud.com");
}
if ("registry.repo".equals(sp.getParamKey())) {
sp.setParamValue("metersphere");
}
if ("registry.username".equals(sp.getParamKey())) {
sp.setParamValue("developer");
}
}
registryParamService.updateRegistry(registry);
}
}

View File

@ -1,34 +0,0 @@
package io.metersphere;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.junit.Before;
import org.junit.Test;
public class BaseTest {
protected KubernetesClient kubernetesClient;
@Before
public void before() {
try {
ConfigBuilder configBuilder = new ConfigBuilder();
configBuilder.withMasterUrl("https://172.16.10.93:6443");
kubernetesClient = new DefaultKubernetesClient(configBuilder.build());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
@Test
public void test1() {
PodList list = kubernetesClient.pods().list();
for (Pod item : list.getItems()) {
System.out.println(item);
}
}
}

View File

@ -1,536 +0,0 @@
package io.metersphere;
import io.metersphere.config.KafkaProperties;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.annotation.Resource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.FileInputStream;
import java.io.StringWriter;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class JmxFileParseTest {
private final static String HASH_TREE_ELEMENT = "hashTree";
private final static String TEST_PLAN = "TestPlan";
private final static String STRING_PROP = "stringProp";
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 BACKEND_LISTENER = "BackendListener";
private final static String THREAD_GROUP = "ThreadGroup";
private final static String CONFIG_TEST_ELEMENT = "ConfigTestElement";
private final static String DNS_CACHE_MANAGER = "DNSCacheManager";
private final static String ARGUMENTS = "Arguments";
@Resource
private KafkaProperties kafkaProperties;
@Test
public void testProperties() {
System.out.println(kafkaProperties.getSsl());
}
@Test
public void parse() throws Exception {
File file = new File("/Users/liuruibin/Downloads/blaze_meter_dev2.jmx");
file = new File("/Users/liuruibin/Desktop/041301.jmx");
final FileInputStream inputStream = new FileInputStream(file);
final InputSource inputSource = new InputSource(inputStream);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = factory.newDocumentBuilder();
final Document document = docBuilder.parse(inputSource);
final Element jmeterTestPlan = document.getDocumentElement();
NodeList childNodes = jmeterTestPlan.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof Element) {
Element ele = (Element) node;
// jmeterTestPlan的子元素肯定是<hashTree></hashTree>
parseHashTree(ele);
}
}
DOMSource domSource = new DOMSource(document);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
System.out.println("XML IN String format is: \n" + writer.toString());
// FileUtils.writeStringToFile(new File("/tmp/test-jmeter.jmx"), writer.toString(), StandardCharsets.UTF_8);
}
private void parseHashTree(Element hashTree) {
if (!valid(hashTree)) {
return;
}
if (hashTree.getChildNodes().getLength() > 0) {
final NodeList childNodes = hashTree.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof Element) {
Element ele = (Element) node;
if (!valid(ele)) {
continue;
}
if (nodeNameEquals(ele, HASH_TREE_ELEMENT)) {
parseHashTree(ele);
} else if (nodeNameEquals(ele, TEST_PLAN)) {
processTearDownTestPlan(ele);
} else if (nodeNameEquals(ele, CONCURRENCY_THREAD_GROUP)) {
processConcurrencyThreadGroup(ele);
processCheckoutTimer(ele);
processCheckoutBackendListener(ele);
} else if (nodeNameEquals(ele, THREAD_GROUP)) {
processThreadGroup(ele);
processConcurrencyThreadGroup(ele);
processCheckoutTimer(ele);
processCheckoutBackendListener(ele);
} else if (nodeNameEquals(ele, VARIABLE_THROUGHPUT_TIMER)) {
} else if (nodeNameEquals(ele, BACKEND_LISTENER)) {
// processBackendListener(ele);
} else if (nodeNameEquals(ele, CONFIG_TEST_ELEMENT)) {
// processConfigTestElement(ele);
} else if (nodeNameEquals(ele, DNS_CACHE_MANAGER)) {
// processDnsCacheManager(ele);
} else if (nodeNameEquals(ele, ARGUMENTS)) {
// processArguments(ele);
}
}
}
}
}
private void processArguments(Element ele) {
/*
<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="BASE_URL_1" elementType="Argument">
<stringProp name="Argument.name">BASE_URL_1</stringProp>
<stringProp name="Argument.value">rddev2.fit2cloud.com</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</Arguments>
*/
NodeList childNodes = ele.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node item = childNodes.item(i);
if (item instanceof Element && nodeNameEquals(item, "collectionProp")) {
removeChildren(item);
Document document = item.getOwnerDocument();
Element elementProp = document.createElement("elementProp");
elementProp.setAttribute("name", "");
elementProp.setAttribute("elementType", "");
elementProp.appendChild(createStringProp(document, "Argument.name", ""));
elementProp.appendChild(createStringProp(document, "Argument.value", ""));
elementProp.appendChild(createStringProp(document, "Argument.metadata", "="));
item.appendChild(elementProp);
}
}
}
private void processDnsCacheManager(Element ele) {
/*
<DNSCacheManager guiclass="DNSCachePanel" testclass="DNSCacheManager" testname="DNS Cache Manager" enabled="true">
<collectionProp name="DNSCacheManager.servers"/>
<collectionProp name="DNSCacheManager.hosts">
<elementProp name="baiud.com" elementType="StaticHost">
<stringProp name="StaticHost.Name">baiud.com</stringProp>
<stringProp name="StaticHost.Address">172.16.10.187</stringProp>
</elementProp>
</collectionProp>
<boolProp name="DNSCacheManager.clearEachIteration">true</boolProp>
<boolProp name="DNSCacheManager.isCustomResolver">true</boolProp>
</DNSCacheManager>
*/
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")
&& StringUtils.equals(((Element) item).getAttribute("name"), "DNSCacheManager.hosts")) {
Node childNode = item.getFirstChild();
// todo 绑定域名 多个
while (!(childNode instanceof Element)) {
childNode = childNode.getNextSibling();
}
Element elementProp = ((Element) childNode);
elementProp.setAttribute("name", "baidu.com");
elementProp.setAttribute("elementType", "StaticHost");
removeChildren(elementProp);
elementProp.appendChild(createStringProp(ele.getOwnerDocument(), "StaticHost.Name", ""));
elementProp.appendChild(createStringProp(ele.getOwnerDocument(), "StaticHost.Address", ""));
}
if (item instanceof Element && nodeNameEquals(item, "boolProp")
&& StringUtils.equals(((Element) item).getAttribute("name"), "DNSCacheManager.isCustomResolver")) {
item.getFirstChild().setNodeValue("true");
}
}
}
private void processConfigTestElement(Element ele) {
/*
<ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="HTTPSampler.domain"></stringProp>
<stringProp name="HTTPSampler.port"></stringProp>
<stringProp name="HTTPSampler.protocol"></stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path"></stringProp>
<boolProp name="HTTPSampler.image_parser">true</boolProp>
<boolProp name="HTTPSampler.concurrentDwn">true</boolProp>
<stringProp name="HTTPSampler.concurrentPool">6</stringProp>
<stringProp name="HTTPSampler.connect_timeout">30000</stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
</ConfigTestElement>
*/
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, STRING_PROP)
&& StringUtils.equals(((Element) item).getAttribute("name"), "HTTPSampler.connect_timeout")) {
item.getFirstChild().setNodeValue("30000");
}
}
}
private void processTearDownTestPlan(Element ele) {
/*<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>*/
Document document = ele.getOwnerDocument();
Element tearDownSwitch = createBoolProp(document, "TestPlan.tearDown_on_shutdown", true);
ele.appendChild(tearDownSwitch);
Node hashTree = ele.getNextSibling();
while (!(hashTree instanceof Element)) {
hashTree = hashTree.getNextSibling();
}
/*
<PostThreadGroup guiclass="PostThreadGroupGui" testclass="PostThreadGroup" testname="tearDown Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</PostThreadGroup>
*/
Element tearDownElement = document.createElement("PostThreadGroup");
tearDownElement.setAttribute("guiclass", "PostThreadGroupGui");
tearDownElement.setAttribute("testclass", "PostThreadGroup");
tearDownElement.setAttribute("testname", "tearDown Thread Group");
tearDownElement.setAttribute("enabled", "true");
tearDownElement.appendChild(createStringProp(document, "ThreadGroup.on_sample_error", "continue"));
tearDownElement.appendChild(createStringProp(document, "ThreadGroup.num_threads", "1"));
tearDownElement.appendChild(createStringProp(document, "ThreadGroup.ramp_time", "1"));
tearDownElement.appendChild(createStringProp(document, "ThreadGroup.duration", ""));
tearDownElement.appendChild(createStringProp(document, "ThreadGroup.delay", ""));
tearDownElement.appendChild(createBoolProp(document, "ThreadGroup.scheduler", false));
tearDownElement.appendChild(createBoolProp(document, "ThreadGroup.same_user_on_next_iteration", true));
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"));
tearDownElement.appendChild(elementProp);
hashTree.appendChild(tearDownElement);
Element tearDownHashTree = document.createElement(HASH_TREE_ELEMENT);
/*
<OnceOnlyController guiclass="OnceOnlyControllerGui" testclass="OnceOnlyController" testname="Once Only Controller" enabled="true"/>
*/
Element onceOnlyController = document.createElement("OnceOnlyController");
onceOnlyController.setAttribute("guiclass", "OnceOnlyControllerGui");
onceOnlyController.setAttribute("testclass", "OnceOnlyController");
onceOnlyController.setAttribute("testname", "Once Only Controller");
onceOnlyController.setAttribute("enabled", "true");
tearDownHashTree.appendChild(onceOnlyController);
/*
<hashTree>
<DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="Debug Sampler" enabled="true">
<boolProp name="displayJMeterProperties">false</boolProp>
<boolProp name="displayJMeterVariables">true</boolProp>
<boolProp name="displaySystemProperties">false</boolProp>
</DebugSampler>
<hashTree/>
</hashTree>
*/
Element onceOnlyHashTree = document.createElement(HASH_TREE_ELEMENT);
Element debugSampler = document.createElement("DebugSampler");
debugSampler.setAttribute("guiclass", "TestBeanGUI");
debugSampler.setAttribute("testclass", "DebugSampler");
debugSampler.setAttribute("testname", "Debug Sampler");
debugSampler.setAttribute("enabled", "true");
debugSampler.appendChild(createBoolProp(document, "displayJMeterProperties", false));
debugSampler.appendChild(createBoolProp(document, "displayJMeterVariables", true));
debugSampler.appendChild(createBoolProp(document, "displaySystemProperties", false));
onceOnlyHashTree.appendChild(debugSampler);
// 添加空的 hashTree
onceOnlyHashTree.appendChild(document.createElement(HASH_TREE_ELEMENT));
tearDownHashTree.appendChild(onceOnlyHashTree);
hashTree.appendChild(tearDownHashTree);
// 添加backend listener
processCheckoutBackendListener(tearDownElement);
}
private Element createBoolProp(Document document, String name, boolean value) {
Element tearDownSwitch = document.createElement("boolProp");
tearDownSwitch.setAttribute("name", name);
tearDownSwitch.appendChild(document.createTextNode(String.valueOf(value)));
return tearDownSwitch;
}
private void processBackendListener(Element backendListener) {
Document document = backendListener.getOwnerDocument();
// 清空child
removeChildren(backendListener);
backendListener.appendChild(createStringProp(document, "classname", "io.github.rahulsinghai.jmeter.backendlistener.kafka.KafkaBackendClient"));
backendListener.appendChild(createStringProp(document, "QUEUE_SIZE", "5000"));
// elementProp
Element elementProp = document.createElement("elementProp");
elementProp.setAttribute("name", "arguments");
elementProp.setAttribute("elementType", "Arguments");
elementProp.setAttribute("guiclass", "ArgumentsPanel");
elementProp.setAttribute("testclass", "Arguments");
elementProp.setAttribute("enabled", "true");
Element collectionProp = document.createElement("collectionProp");
collectionProp.setAttribute("name", "Arguments.arguments");
collectionProp.appendChild(createKafkaProp(document, "kafka.acks", kafkaProperties.getAcks()));
collectionProp.appendChild(createKafkaProp(document, "kafka.bootstrap.servers", kafkaProperties.getBootstrapServers()));
collectionProp.appendChild(createKafkaProp(document, "kafka.topic", kafkaProperties.getTopic()));
collectionProp.appendChild(createKafkaProp(document, "kafka.sample.filter", kafkaProperties.getSampleFilter()));
collectionProp.appendChild(createKafkaProp(document, "kafka.fields", kafkaProperties.getFields()));
collectionProp.appendChild(createKafkaProp(document, "kafka.test.mode", kafkaProperties.getTestMode()));
collectionProp.appendChild(createKafkaProp(document, "kafka.parse.all.req.headers", kafkaProperties.getParseAllReqHeaders()));
collectionProp.appendChild(createKafkaProp(document, "kafka.parse.all.res.headers", kafkaProperties.getParseAllResHeaders()));
collectionProp.appendChild(createKafkaProp(document, "kafka.timestamp", kafkaProperties.getTimestamp()));
collectionProp.appendChild(createKafkaProp(document, "kafka.compression.type", kafkaProperties.getCompressionType()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.enabled", kafkaProperties.getSsl().getEnabled()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.key.password", kafkaProperties.getSsl().getKeyPassword()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.keystore.location", kafkaProperties.getSsl().getKeystoreLocation()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.keystore.password", kafkaProperties.getSsl().getKeystorePassword()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.truststore.location", kafkaProperties.getSsl().getTruststoreLocation()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.truststore.password", kafkaProperties.getSsl().getTruststorePassword()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.enabled.protocols", kafkaProperties.getSsl().getEnabledProtocols()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.keystore.type", kafkaProperties.getSsl().getKeystoreType()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.protocol", kafkaProperties.getSsl().getProtocol()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.provider", kafkaProperties.getSsl().getProvider()));
collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.truststore.type", kafkaProperties.getSsl().getTruststoreType()));
collectionProp.appendChild(createKafkaProp(document, "kafka.batch.size", kafkaProperties.getBatchSize()));
collectionProp.appendChild(createKafkaProp(document, "kafka.client.id", kafkaProperties.getClientId()));
collectionProp.appendChild(createKafkaProp(document, "kafka.connections.max.idle.ms", kafkaProperties.getConnectionsMaxIdleMs()));
// 添加关联关系 test.id test.name
collectionProp.appendChild(createKafkaProp(document, "test.id", ""));
collectionProp.appendChild(createKafkaProp(document, "test.name", ""));
elementProp.appendChild(collectionProp);
// set elementProp
backendListener.appendChild(elementProp);
}
private void processCheckoutBackendListener(Element element) {
Document document = element.getOwnerDocument();
Node listenerParent = element.getNextSibling();
while (!(listenerParent instanceof Element)) {
listenerParent = listenerParent.getNextSibling();
}
NodeList childNodes = listenerParent.getChildNodes();
for (int i = 0, l = childNodes.getLength(); i < l; i++) {
Node item = childNodes.item(i);
if (nodeNameEquals(item, BACKEND_LISTENER)) {
// 如果已经存在不再添加
return;
}
}
// add class name
Element backendListener = document.createElement(BACKEND_LISTENER);
backendListener.setAttribute("guiclass", "BackendListenerGui");
backendListener.setAttribute("testclass", "BackendListener");
backendListener.setAttribute("testname", "Backend Listener");
backendListener.setAttribute("enabled", "true");
listenerParent.appendChild(backendListener);
listenerParent.appendChild(document.createElement(HASH_TREE_ELEMENT));
}
private Element createKafkaProp(Document document, String name, String value) {
Element eleProp = document.createElement("elementProp");
eleProp.setAttribute("name", name);
eleProp.setAttribute("elementType", "Argument");
eleProp.appendChild(createStringProp(document, "Argument.name", name));
eleProp.appendChild(createStringProp(document, "Argument.value", value));
eleProp.appendChild(createStringProp(document, "Argument.metadata", "="));
return eleProp;
}
private void processThreadGroup(Element threadGroup) {
// 重命名 tagName
Document document = threadGroup.getOwnerDocument();
document.renameNode(threadGroup, threadGroup.getNamespaceURI(), CONCURRENCY_THREAD_GROUP);
threadGroup.setAttribute("guiclass", CONCURRENCY_THREAD_GROUP + "Gui");
threadGroup.setAttribute("testclass", CONCURRENCY_THREAD_GROUP);
/*
<elementProp name="ThreadGroup.main_controller" elementType="com.blazemeter.jmeter.control.VirtualUserController"/>
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<stringProp name="TargetLevel">2</stringProp>
<stringProp name="RampUp">12</stringProp>
<stringProp name="Steps">2</stringProp>
<stringProp name="Hold">3</stringProp>
<stringProp name="LogFilename"></stringProp>
<stringProp name="Iterations">1</stringProp>
<stringProp name="Unit">S</stringProp>
*/
removeChildren(threadGroup);
// elementProp
Element elementProp = document.createElement("elementProp");
elementProp.setAttribute("name", "ThreadGroup.main_controller");
elementProp.setAttribute("elementType", "com.blazemeter.jmeter.control.VirtualUserController");
threadGroup.appendChild(elementProp);
threadGroup.appendChild(createStringProp(document, "ThreadGroup.on_sample_error", "continue"));
threadGroup.appendChild(createStringProp(document, "TargetLevel", "2"));
threadGroup.appendChild(createStringProp(document, "RampUp", "12"));
threadGroup.appendChild(createStringProp(document, "Steps", "2"));
threadGroup.appendChild(createStringProp(document, "Hold", "12"));
threadGroup.appendChild(createStringProp(document, "LogFilename", ""));
threadGroup.appendChild(createStringProp(document, "Iterations", "1"));
threadGroup.appendChild(createStringProp(document, "Unit", "S"));
}
private void processCheckoutTimer(Element element) {
/*
<kg.apc.jmeter.timers.VariableThroughputTimer guiclass="kg.apc.jmeter.timers.VariableThroughputTimerGui" testclass="kg.apc.jmeter.timers.VariableThroughputTimer" testname="jp@gc - Throughput Shaping Timer" enabled="true">
<collectionProp name="load_profile">
<collectionProp name="140409499">
<stringProp name="49">1</stringProp>
<stringProp name="49">1</stringProp>
<stringProp name="1570">13</stringProp>
</collectionProp>
</collectionProp>
</kg.apc.jmeter.timers.VariableThroughputTimer>
*/
Document document = element.getOwnerDocument();
Node timerParent = element.getNextSibling();
while (!(timerParent instanceof Element)) {
timerParent = timerParent.getNextSibling();
}
NodeList childNodes = timerParent.getChildNodes();
for (int i = 0, l = childNodes.getLength(); i < l; i++) {
Node item = childNodes.item(i);
if (nodeNameEquals(item, VARIABLE_THROUGHPUT_TIMER)) {
// 如果已经存在不再添加
return;
}
}
Element timer = document.createElement(VARIABLE_THROUGHPUT_TIMER);
timer.setAttribute("guiclass", VARIABLE_THROUGHPUT_TIMER + "Gui");
timer.setAttribute("testclass", VARIABLE_THROUGHPUT_TIMER);
timer.setAttribute("testname", "jp@gc - Throughput Shaping Timer");
timer.setAttribute("enabled", "true");
Element collectionProp = document.createElement("collectionProp");
collectionProp.setAttribute("name", "load_profile");
Element childCollectionProp = document.createElement("collectionProp");
childCollectionProp.setAttribute("name", "140409499");
childCollectionProp.appendChild(createStringProp(document, "49", "1"));
childCollectionProp.appendChild(createStringProp(document, "49", "1"));
childCollectionProp.appendChild(createStringProp(document, "1570", "10"));
collectionProp.appendChild(childCollectionProp);
timer.appendChild(collectionProp);
timerParent.appendChild(timer);
// 添加一个空的hashTree
timerParent.appendChild(document.createElement(HASH_TREE_ELEMENT));
}
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;
}
private void processConcurrencyThreadGroup(Element concurrencyThreadGroup) {
if (concurrencyThreadGroup.getChildNodes().getLength() > 0) {
final NodeList childNodes = concurrencyThreadGroup.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof Element) {
Element ele = (Element) node;
if (!valid(ele)) {
continue;
}
if (nodeNameEquals(ele, STRING_PROP)) {
parseStringProp(ele);
}
}
}
}
}
private void parseStringProp(Element stringProp) {
if (stringProp.getChildNodes().getLength() > 0) {
stringProp.getFirstChild().setNodeValue("1");
}
}
private boolean nodeNameEquals(Node node, String desiredName) {
return desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName());
}
private boolean valid(Element ele) {
return StringUtils.isBlank(ele.getAttribute("enabled")) || Boolean.parseBoolean(ele.getAttribute("enabled"));
}
private void removeChildren(Node node) {
while (node.hasChildNodes()) {
node.removeChild(node.getFirstChild());
}
}
}

View File

@ -1,36 +0,0 @@
package io.metersphere;
import io.metersphere.report.base.Statistics;
import org.junit.Test;
import java.lang.reflect.Field;
public class ResultDataParseTest {
String[] s = {"1","2","3","4","5","6","7","8","9","10","11","12","13"};
public static <T> T setParam(Class<T> clazz, Object[] args)
throws Exception {
if (clazz == null || args == null) {
throw new IllegalArgumentException();
}
T t = clazz.newInstance();
Field[] fields = clazz.getDeclaredFields();
if (fields == null || fields.length > args.length) {
throw new IndexOutOfBoundsException();
}
for (int i = 0; i < fields.length; i++) {
fields[i].setAccessible(true);
fields[i].set(t, args[i]);
}
return t;
}
@Test
public void test() throws Exception {
Statistics statistics = setParam(Statistics.class, s);
System.out.println(statistics.toString());
}
}

View File

@ -1,30 +0,0 @@
package io.metersphere.service;
import io.metersphere.base.domain.TestCaseNode;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TestCaseTest {
@Resource
TestCaseNodeService testCaseNodeService;
@Test
public void addNode() {
TestCaseNode node = new TestCaseNode();
node.setName("node01");
node.setProjectId("2ade216b-01a6-43d0-b48c-4a3898306096");
node.setCreateTime(System.currentTimeMillis());
node.setUpdateTime(System.currentTimeMillis());
testCaseNodeService.addNode(node);
}
}

View File

@ -1,25 +0,0 @@
package io.metersphere.service;
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.dto.TestResourcePoolDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TestResourcePoolServiceTest {
@Resource
private TestResourcePoolService testResourcePoolService;
@Test
public void listResourcePools() {
List<TestResourcePoolDTO> list = testResourcePoolService.listResourcePools(new QueryResourcePoolRequest());
System.out.println(list.size());
}
}

View File

@ -39,7 +39,7 @@
.logging-content { .logging-content {
white-space: pre-line; white-space: pre-line;
overflow: auto; overflow: auto;
height: calc(100vh - 400px); height: calc(100vh - 420px);
} }
</style> </style>