Merge branch 'v1.8' of github.com:metersphere/metersphere into v1.8
This commit is contained in:
commit
3b32c9854d
|
@ -160,14 +160,16 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
sampler.setProtocol(urlObject.getProtocol());
|
||||
sampler.setPath(urlObject.getPath());
|
||||
} else {
|
||||
String configStr = config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket();
|
||||
sampler.setDomain(configStr);
|
||||
if (config.getConfig().get(this.getProjectId()).getHttpConfig().getPort() > 0) {
|
||||
sampler.setDomain(config.getConfig().get(this.getProjectId()).getHttpConfig().getDomain());
|
||||
url = config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol() + "://" + config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket();
|
||||
URL urlObject = new URL(url);
|
||||
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
|
||||
if (StringUtils.isNotBlank(this.getPath())) {
|
||||
envPath += this.getPath();
|
||||
}
|
||||
sampler.setPort(config.getConfig().get(this.getProjectId()).getHttpConfig().getPort());
|
||||
sampler.setProtocol(config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol());
|
||||
sampler.setPath(this.getPath());
|
||||
sampler.setPath(envPath);
|
||||
}
|
||||
String envPath = sampler.getPath();
|
||||
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
||||
|
@ -187,7 +189,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
}
|
||||
} else {
|
||||
String url = this.getUrl();
|
||||
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
||||
if (StringUtils.isNotEmpty(url) && !url.startsWith("http://") && !url.startsWith("https://")) {
|
||||
url = "http://" + url;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(this.getPort()) && this.getPort().startsWith("${")) {
|
||||
|
|
|
@ -11,6 +11,7 @@ public class KafkaProperties {
|
|||
public static final String KAFKA_PREFIX = "kafka";
|
||||
|
||||
private String acks = "0"; // 不要设置all
|
||||
private String expectedDelayEndTime = "30000"; // 30s
|
||||
private String topic;
|
||||
private String fields;
|
||||
private String timestamp;
|
||||
|
|
|
@ -25,8 +25,9 @@ public class JmeterFileController {
|
|||
|
||||
@GetMapping("download")
|
||||
public ResponseEntity<byte[]> downloadJmeterFiles(@RequestParam("testId") String testId, @RequestParam("resourceId") String resourceId,
|
||||
@RequestParam("ratio") double ratio, @RequestParam("startTime") long startTime,
|
||||
@RequestParam("ratio") double ratio,
|
||||
@RequestParam("reportId") String reportId, @RequestParam("resourceIndex") int resourceIndex) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
byte[] bytes = jmeterFileService.downloadZip(testId, resourceId, ratio, startTime, reportId, resourceIndex);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
|
|
|
@ -29,6 +29,7 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
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 BOOL_PROP = "boolProp";
|
||||
private final static String COLLECTION_PROP = "collectionProp";
|
||||
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";
|
||||
|
@ -94,6 +95,7 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
processCheckoutDnsCacheManager(ele);
|
||||
processCheckoutArguments(ele);
|
||||
processCheckoutResponseAssertion(ele);
|
||||
processCheckoutSerializeThreadgroups(ele);
|
||||
} else if (nodeNameEquals(ele, CONCURRENCY_THREAD_GROUP)) {
|
||||
processThreadGroupName(ele);
|
||||
processCheckoutTimer(ele);
|
||||
|
@ -141,6 +143,21 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void processCheckoutSerializeThreadgroups(Element element) {
|
||||
NodeList childNodes = element.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node item = childNodes.item(i);
|
||||
if (nodeNameEquals(item, BOOL_PROP)) {
|
||||
String serializeName = ((Element) item).getAttribute("name");
|
||||
if (StringUtils.equals(serializeName, "TestPlan.serialize_threadgroups")) {
|
||||
// 保存线程组是否是顺序执行
|
||||
context.addProperty("serialize_threadgroups", item.getTextContent());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processArgumentFiles(Element element) {
|
||||
NodeList childNodes = element.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
|
@ -479,7 +496,7 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
item.appendChild(elementProp);
|
||||
}
|
||||
}
|
||||
if (item instanceof Element && nodeNameEquals(item, "boolProp")
|
||||
if (item instanceof Element && nodeNameEquals(item, BOOL_PROP)
|
||||
&& org.apache.commons.lang3.StringUtils.equals(((Element) item).getAttribute("name"), "DNSCacheManager.isCustomResolver")) {
|
||||
item.getFirstChild().setNodeValue("true");
|
||||
}
|
||||
|
@ -511,7 +528,7 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
}
|
||||
|
||||
private Element createBoolProp(Document document, String name, boolean value) {
|
||||
Element boolProp = document.createElement("boolProp");
|
||||
Element boolProp = document.createElement(BOOL_PROP);
|
||||
boolProp.setAttribute("name", name);
|
||||
boolProp.appendChild(document.createTextNode(String.valueOf(value)));
|
||||
return boolProp;
|
||||
|
@ -569,6 +586,8 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
collectionProp.appendChild(createKafkaProp(document, "test.name", context.getTestName()));
|
||||
collectionProp.appendChild(createKafkaProp(document, "test.startTime", context.getStartTime().toString()));
|
||||
collectionProp.appendChild(createKafkaProp(document, "test.reportId", context.getReportId()));
|
||||
collectionProp.appendChild(createKafkaProp(document, "test.expectedEndTime", (String) context.getProperty("expectedEndTime")));
|
||||
collectionProp.appendChild(createKafkaProp(document, "test.expectedDelayEndTime", kafkaProperties.getExpectedDelayEndTime())); // 30s
|
||||
|
||||
elementProp.appendChild(collectionProp);
|
||||
// set elementProp
|
||||
|
@ -710,6 +729,8 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
// 处理预计结束时间
|
||||
processExpectedEndTime(duration);
|
||||
|
||||
threadGroup.setAttribute("enabled", enabled);
|
||||
if (BooleanUtils.toBoolean(deleted)) {
|
||||
|
@ -815,6 +836,8 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
// 处理预计结束时间
|
||||
processExpectedEndTime(hold);
|
||||
|
||||
threadGroup.setAttribute("enabled", enabled);
|
||||
if (BooleanUtils.toBoolean(deleted)) {
|
||||
|
@ -835,6 +858,27 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
threadGroup.appendChild(createStringProp(document, "Unit", "S"));
|
||||
}
|
||||
|
||||
private void processExpectedEndTime(String duration) {
|
||||
long startTime = context.getStartTime();
|
||||
Long d = Long.parseLong(duration);
|
||||
Object serialize = context.getProperty("TestPlan.serialize_threadgroups");
|
||||
String expectedEndTime = (String) context.getProperty("expectedEndTime");
|
||||
if (StringUtils.isBlank(expectedEndTime)) {
|
||||
expectedEndTime = startTime + "";
|
||||
}
|
||||
long endTime = Long.parseLong(expectedEndTime);
|
||||
|
||||
if (BooleanUtils.toBoolean((String) serialize)) {
|
||||
// 顺序执行线程组
|
||||
context.addProperty("expectedEndTime", String.valueOf(endTime + d * 1000));
|
||||
} else {
|
||||
// 同时执行线程组
|
||||
if (endTime < startTime + d * 1000) {
|
||||
context.addProperty("expectedEndTime", String.valueOf(startTime + d * 1000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processIterationThreadGroup(Element threadGroup) {
|
||||
// 检查 threadgroup 后面的hashtree是否为空
|
||||
Node hashTree = threadGroup.getNextSibling();
|
||||
|
@ -903,8 +947,11 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
threadGroup.appendChild(createStringProp(document, "ThreadGroup.duration", "10"));
|
||||
threadGroup.appendChild(createStringProp(document, "ThreadGroup.delay", ""));
|
||||
threadGroup.appendChild(createBoolProp(document, "ThreadGroup.same_user_on_next_iteration", true));
|
||||
}
|
||||
|
||||
// 处理预计结束时间, (按照迭代次数 * 线程数)s
|
||||
String duration = String.valueOf(Long.parseLong(loops) * Long.parseLong(threads));
|
||||
processExpectedEndTime(duration);
|
||||
}
|
||||
|
||||
private void processCheckoutTimer(Element element) {
|
||||
/*
|
||||
|
|
|
@ -392,8 +392,8 @@
|
|||
}
|
||||
},
|
||||
runTest(data) {
|
||||
this.setTabTitle(data);
|
||||
this.handleTabsEdit(this.$t("commons.api"), "TEST", data);
|
||||
this.setTabTitle(data);
|
||||
},
|
||||
saveApi(data) {
|
||||
this.setTabTitle(data);
|
||||
|
|
|
@ -58,22 +58,26 @@
|
|||
}
|
||||
},
|
||||
run() {
|
||||
let testPlan = new TestPlan();
|
||||
let threadGroup = new ThreadGroup();
|
||||
threadGroup.hashTree = [];
|
||||
testPlan.hashTree = [threadGroup];
|
||||
this.runData.forEach(item => {
|
||||
threadGroup.hashTree.push(item);
|
||||
})
|
||||
|
||||
let projectId = "";
|
||||
let projectId = this.$store.state.projectId;
|
||||
// 如果envMap不存在,是单接口调用
|
||||
if (!this.envMap || this.envMap.size === 0) {
|
||||
projectId = this.$store.state.projectId;
|
||||
} else {
|
||||
// 场景步骤下接口调用
|
||||
if(this.runData.projectId){
|
||||
projectId = this.runData.projectId;
|
||||
}
|
||||
}
|
||||
|
||||
let testPlan = new TestPlan();
|
||||
let threadGroup = new ThreadGroup();
|
||||
threadGroup.hashTree = [];
|
||||
testPlan.hashTree = [threadGroup];
|
||||
this.runData.forEach(item => {
|
||||
item.projectId = projectId;
|
||||
threadGroup.hashTree.push(item);
|
||||
})
|
||||
|
||||
let reqObj = {id: this.reportId, testElement: testPlan, type: this.type,projectId: projectId, environmentMap: strMapToObj(this.envMap)};
|
||||
let bodyFiles = getBodyUploadFiles(reqObj, this.runData);
|
||||
let url = "";
|
||||
|
|
|
@ -306,6 +306,8 @@
|
|||
this.$warning(this.$t('api_test.environment.select_environment'));
|
||||
return;
|
||||
}
|
||||
this.envMap = new Map();
|
||||
this.envMap.set(this.$store.state.projectId,this.environment);
|
||||
this.runData = [];
|
||||
this.batchLoadingIds = [];
|
||||
this.selectdCases = [];
|
||||
|
|
Loading…
Reference in New Issue