Merge branch 'v1.6' of https://github.com/metersphere/metersphere into v1.6
This commit is contained in:
commit
e89dcafd7e
|
@ -82,14 +82,14 @@ public class MsScenario extends MsTestElement {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
// 场景变量
|
||||
// 场景变量和环境变量
|
||||
tree.add(arguments(config));
|
||||
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
for (MsTestElement el : hashTree) {
|
||||
el.toHashTree(tree, el.getHashTree(), config);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Arguments arguments(ParameterConfig config) {
|
||||
|
|
|
@ -20,13 +20,17 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
|||
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||
import io.metersphere.api.dto.definition.request.timer.MsConstantTimer;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.jmeter.config.Arguments;
|
||||
import org.apache.jmeter.protocol.http.control.AuthManager;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
|
||||
|
@ -77,7 +81,7 @@ public abstract class MsTestElement {
|
|||
@JSONField(ordinal = 8)
|
||||
private boolean enable = true;
|
||||
@JSONField(ordinal = 9)
|
||||
private String refType ;
|
||||
private String refType;
|
||||
@JSONField(ordinal = 10)
|
||||
private LinkedList<MsTestElement> hashTree;
|
||||
|
||||
|
@ -133,6 +137,22 @@ public abstract class MsTestElement {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Arguments addArguments(ParameterConfig config) {
|
||||
if (config != null && config.getConfig() != null && config.getConfig().getCommonConfig() != null
|
||||
&& CollectionUtils.isNotEmpty(config.getConfig().getCommonConfig().getVariables())) {
|
||||
Arguments arguments = new Arguments();
|
||||
arguments.setEnabled(true);
|
||||
arguments.setName(name + "Variables");
|
||||
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
|
||||
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
|
||||
config.getConfig().getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
|
||||
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
|
||||
);
|
||||
return arguments;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -114,6 +114,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
config.setConfig(JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class));
|
||||
}
|
||||
}
|
||||
// 添加环境中的公共变量
|
||||
Arguments arguments = this.addArguments(config);
|
||||
if (arguments != null) {
|
||||
tree.add(this.addArguments(config));
|
||||
}
|
||||
try {
|
||||
if (config != null && config.getConfig() != null) {
|
||||
String url = config.getConfig().getHttpConfig().getProtocol() + "://" + config.getConfig().getHttpConfig().getSocket();
|
||||
|
@ -138,7 +143,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
envPath += this.getPath();
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
||||
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"), config);
|
||||
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"));
|
||||
sampler.setPath(envPath);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(this.getArguments())) {
|
||||
|
@ -155,7 +160,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
sampler.setProtocol(urlObject.getProtocol());
|
||||
|
||||
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
||||
sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8"), config));
|
||||
sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(this.getArguments())) {
|
||||
sampler.setPath(getPostQueryParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
|
||||
|
@ -198,7 +203,19 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
}
|
||||
}
|
||||
|
||||
private String getRestParameters(String path, ParameterConfig config) {
|
||||
private boolean isVariable(String path, String value) {
|
||||
Pattern p = Pattern.compile("(\\$\\{)([\\w]+)(\\})");
|
||||
Matcher m = p.matcher(path);
|
||||
while (m.find()) {
|
||||
String group = m.group(2);
|
||||
if (group.equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getRestParameters(String path) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(path);
|
||||
stringBuffer.append("/");
|
||||
|
@ -211,7 +228,9 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
Matcher m = p.matcher(path);
|
||||
while (m.find()) {
|
||||
String group = m.group(2);
|
||||
path = path.replace("{" + group + "}", keyValueMap.get(group));
|
||||
if (!isVariable(path, group)) {
|
||||
path = path.replace("{" + group + "}", keyValueMap.get(group));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
|
|
@ -296,7 +296,6 @@ public class ApiDefinitionService {
|
|||
if (StringUtils.isNotBlank(request.getType()) && StringUtils.equals(request.getType(), ApiRunMode.API_PLAN.name())) {
|
||||
runMode = ApiRunMode.API_PLAN.name();
|
||||
}
|
||||
request.getTestElement().getJmx(hashTree);
|
||||
// 调用执行方法
|
||||
jMeterService.runDefinition(request.getId(), hashTree, request.getReportId(), runMode);
|
||||
return request.getId();
|
||||
|
|
|
@ -878,6 +878,24 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
}
|
||||
|
||||
private void processVariableThroughputTimer(Element variableThroughputTimer) {
|
||||
Object durations = context.getProperty("duration");
|
||||
Integer duration;
|
||||
if (durations instanceof List) {
|
||||
Object o = ((List<?>) durations).get(0);
|
||||
duration = (Integer) o;
|
||||
((List<?>) durations).remove(0);
|
||||
} else {
|
||||
duration = (Integer) durations;
|
||||
}
|
||||
Object rpsLimits = context.getProperty("rpsLimit");
|
||||
String rpsLimit;
|
||||
if (rpsLimits instanceof List) {
|
||||
Object o = ((List<?>) rpsLimits).get(0);
|
||||
((List<?>) rpsLimits).remove(0);
|
||||
rpsLimit = o.toString();
|
||||
} else {
|
||||
rpsLimit = rpsLimits.toString();
|
||||
}
|
||||
if (variableThroughputTimer.getChildNodes().getLength() > 0) {
|
||||
final NodeList childNodes = variableThroughputTimer.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
|
@ -903,27 +921,9 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
stringPropCount++;
|
||||
} else {
|
||||
stringPropCount = 0;
|
||||
Object durations = context.getProperty("duration");// 传入的是分钟数, 需要转化成秒数
|
||||
Integer duration;
|
||||
if (durations instanceof List) {
|
||||
Object o = ((List<?>) durations).get(0);
|
||||
duration = (Integer) o;
|
||||
((List<?>) durations).remove(0);
|
||||
} else {
|
||||
duration = (Integer) durations;
|
||||
}
|
||||
prop.getFirstChild().setNodeValue(String.valueOf(duration));
|
||||
continue;
|
||||
}
|
||||
Object rpsLimits = context.getProperty("rpsLimit");
|
||||
String rpsLimit;
|
||||
if (rpsLimits instanceof List) {
|
||||
Object o = ((List<?>) rpsLimits).get(0);
|
||||
((List<?>) rpsLimits).remove(0);
|
||||
rpsLimit = o.toString();
|
||||
} else {
|
||||
rpsLimit = rpsLimits.toString();
|
||||
}
|
||||
prop.getFirstChild().setNodeValue(rpsLimit);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue