-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bd499f6
Showing
8 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.metersphere</groupId> | ||
<artifactId>metersphere-plugin-ParallelController</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
<custom.lib-path>${pom.basedir}/src/main/resources</custom.lib-path> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.metersphere</groupId> | ||
<artifactId>metersphere-plugin-core</artifactId> | ||
<version>1.0.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.blazemeter</groupId> | ||
<artifactId>jmeter-parallel</artifactId> | ||
<version>0.11</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-collections4</artifactId> | ||
<version>4.4</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>2.5.5</version> | ||
<configuration> | ||
<descriptors> | ||
<descriptor>${custom.lib-path}/xml/assembly.xml</descriptor><!-- 指定assembly配置文件路径 --> | ||
</descriptors> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
54 changes: 54 additions & 0 deletions
54
src/main/java/io/metersphere/plugin/parallel/UiScriptApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.metersphere.plugin.parallel; | ||
|
||
import io.metersphere.plugin.core.api.UiScriptApi; | ||
import io.metersphere.plugin.core.ui.PluginResource; | ||
import io.metersphere.plugin.core.ui.UiScript; | ||
import io.metersphere.plugin.core.utils.LogUtil; | ||
|
||
import java.io.InputStream; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class UiScriptApiImpl extends UiScriptApi { | ||
/** | ||
* 企业版插件增加 这个方法 | ||
* | ||
* @return 是否是企业版插件 | ||
*/ | ||
public boolean xpack() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public PluginResource init() { | ||
LogUtil.info("开始初始化脚本内容 "); | ||
List<UiScript> uiScripts = new LinkedList<>(); | ||
String scriptString = getJson("/json/ui_parallel.json"); | ||
UiScript script = new UiScript("parallel_controller", "并行控制器", "io.metersphere.plugin.parallel.controller.MsParallelController", scriptString); | ||
script.setJmeterClazz("GenericController"); | ||
|
||
// 添加可选参数 | ||
script.setFormOption(getJson("/json/ui_form.json")); | ||
|
||
uiScripts.add(script); | ||
LogUtil.info("初始化脚本内容结束 "); | ||
return new PluginResource("parallel-v1.0.0", uiScripts); | ||
} | ||
|
||
@Override | ||
public String customMethod(String req) { | ||
LogUtil.info("Parallel Controller 自定义方法"); | ||
return null; | ||
} | ||
|
||
public String getJson(String path) { | ||
try { | ||
InputStream in = UiScriptApiImpl.class.getResourceAsStream(path); | ||
String json = org.apache.commons.io.IOUtils.toString(in); | ||
return json; | ||
} catch (Exception ex) { | ||
LogUtil.error(ex.getMessage()); | ||
} | ||
return null; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/io/metersphere/plugin/parallel/controller/MsParallelController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package io.metersphere.plugin.parallel.controller; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.annotation.JSONField; | ||
import io.metersphere.plugin.core.MsParameter; | ||
import io.metersphere.plugin.core.MsTestElement; | ||
import io.metersphere.plugin.core.utils.LogUtil; | ||
import io.metersphere.plugin.parallel.utils.ElementUtil; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import org.apache.commons.collections.CollectionUtils; | ||
import org.apache.jmeter.testelement.TestElement; | ||
import org.apache.jorphan.collections.HashTree; | ||
import com.blazemeter.jmeter.controller.ParallelSampler; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class MsParallelController extends MsTestElement { | ||
public MsParallelController() { | ||
|
||
} | ||
private String clazzName = "io.metersphere.plugin.parallel.controller.MsParallelController"; | ||
|
||
@JSONField(ordinal = 21) | ||
private Boolean limitMaxThread; | ||
@JSONField(ordinal = 22) | ||
private String maxThreads; | ||
|
||
@Override | ||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter config) { | ||
LogUtil.info("===========开始转换MsDummySampler =================="); | ||
if (!this.isEnable()) { | ||
return; | ||
} | ||
ParallelSampler initParallelSampler = initParallelSampler(); | ||
if (initParallelSampler != null) { | ||
final HashTree groupTree = tree.add(initParallelSampler()); | ||
if (CollectionUtils.isNotEmpty(hashTree)) { | ||
hashTree.forEach(el -> { | ||
// 给所有孩子加一个父亲标志 | ||
el.setParent(this); | ||
el.toHashTree(groupTree, el.getHashTree(), config); | ||
}); | ||
} | ||
} | ||
else { | ||
LogUtil.error("Connect Sampler 生成失败"); | ||
throw new RuntimeException("Connect Sampler生成失败"); | ||
} | ||
} | ||
|
||
public ParallelSampler initParallelSampler() { | ||
try { | ||
ParallelSampler parallelSampler = new ParallelSampler(); | ||
// base 执行时需要的参数 | ||
parallelSampler.setProperty("MS-ID", this.getId()); | ||
String indexPath = this.getIndex(); | ||
parallelSampler.setProperty("MS-RESOURCE-ID", this.getResourceId() + "_" + ElementUtil.getFullIndexPath(this.getParent(), indexPath)); | ||
List<String> id_names = new LinkedList<>(); | ||
ElementUtil.getScenarioSet(this, id_names); | ||
parallelSampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names)); | ||
|
||
parallelSampler.setEnabled(this.isEnable()); | ||
parallelSampler.setName(this.getName()); | ||
parallelSampler.setProperty(TestElement.GUI_CLASS, "com.blazemeter.jmeter.controller.ParallelControllerGui"); | ||
parallelSampler.setProperty(TestElement.TEST_CLASS, "com.blazemeter.jmeter.controller.ParallelSampler"); | ||
|
||
parallelSampler.setProperty("PARENT_SAMPLE", false); | ||
parallelSampler.setProperty("LIMIT_MAX_THREAD_NUMBER", this.getLimitMaxThread()); | ||
if (this.getLimitMaxThread() != null && this.getLimitMaxThread()) { | ||
parallelSampler.setProperty("MAX_THREAD_NUMBER", this.getMaxThreads()); | ||
} | ||
|
||
return parallelSampler; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/io/metersphere/plugin/parallel/utils/ElementUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.metersphere.plugin.parallel.utils; | ||
|
||
import io.metersphere.plugin.core.MsTestElement; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
public class ElementUtil { | ||
public static void getScenarioSet(MsTestElement element, List<String> id_names) { | ||
if (StringUtils.equals(element.getType(), "scenario")) { | ||
id_names.add(element.getResourceId() + "_" + element.getName()); | ||
} | ||
if (element.getParent() == null) { | ||
return; | ||
} | ||
getScenarioSet(element.getParent(), id_names); | ||
} | ||
|
||
public static String getFullIndexPath(MsTestElement element, String path) { | ||
if (element == null || element.getParent() == null) { | ||
return path; | ||
} | ||
path = element.getIndex() + "_" + path; | ||
return getFullIndexPath(element.getParent(), path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"form": { | ||
"inline": false, | ||
"labelPosition": "left", | ||
"size": "mini", | ||
"labelWidth": "200px", | ||
"hideRequiredAsterisk": false, | ||
"showMessage": true, | ||
"inlineMessage": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
"type": "switch", | ||
"field": "limitMaxThread", | ||
"title": "Limit max thread number", | ||
"info": "", | ||
"_fc_drag_tag": "switch", | ||
"hidden": false, | ||
"display": true, | ||
"value": false, | ||
"props": { | ||
"activeText": "", | ||
"inactiveText": "" | ||
}, | ||
"control": [ | ||
{ | ||
"value": true, | ||
"rule": [ | ||
{ | ||
"type": "inputNumber", | ||
"field": "maxThreads", | ||
"title": "Max threads", | ||
"info": "", | ||
"_fc_drag_tag": "inputNumber", | ||
"hidden": false, | ||
"display": true, | ||
"value": 5 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
src/main/resources/metersphere-plugin-ParallelController-1.0.0-jar-with-all-dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.metersphere.plugin.parallel.UiScriptApiImpl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<assembly | ||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> | ||
<id>jar-with-all-dependencies</id> | ||
<formats> | ||
<format>jar</format> | ||
</formats> | ||
<includeBaseDirectory>false</includeBaseDirectory> | ||
<dependencySets> | ||
<dependencySet> | ||
<outputDirectory>/</outputDirectory> | ||
<useProjectArtifact>true</useProjectArtifact> | ||
<unpack>true</unpack> | ||
<scope>runtime</scope> | ||
<useTransitiveDependencies>false</useTransitiveDependencies> | ||
</dependencySet> | ||
<dependencySet> | ||
<outputDirectory>/</outputDirectory> | ||
<unpack>true</unpack> | ||
<scope>system</scope> | ||
<useTransitiveDependencies>false</useTransitiveDependencies> | ||
</dependencySet> | ||
</dependencySets> | ||
|
||
</assembly> |