fix(性能测试): 修复启动性能测试计算线程数的问题

This commit is contained in:
Captain.B 2021-05-13 11:25:41 +08:00 committed by 刘瑞斌
parent e1adc9f3b7
commit 621c98b792
1 changed files with 22 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package io.metersphere.performance.engine;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.LoadTestWithBLOBs; import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.base.domain.TestResource; import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourcePool; import io.metersphere.base.domain.TestResourcePool;
@ -20,7 +19,6 @@ import org.apache.commons.lang3.StringUtils;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public abstract class AbstractEngine implements Engine { public abstract class AbstractEngine implements Engine {
protected String JMETER_IMAGE; protected String JMETER_IMAGE;
@ -105,23 +103,32 @@ public abstract class AbstractEngine implements Engine {
Integer s = 0; Integer s = 0;
String loadConfiguration = t.getLoadConfiguration(); String loadConfiguration = t.getLoadConfiguration();
JSONArray jsonArray = JSON.parseArray(loadConfiguration); JSONArray jsonArray = JSON.parseArray(loadConfiguration);
outer:
for (int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
if (jsonArray.get(i) instanceof List) { if (jsonArray.get(i) instanceof List) {
JSONArray o = jsonArray.getJSONArray(i); JSONArray o = jsonArray.getJSONArray(i);
List<JSONObject> enabledConfig = o.stream() for (int j = 0; j < o.size(); j++) {
.filter(b -> { if (StringUtils.equals(o.getJSONObject(j).getString("deleted"), "true")) {
JSONObject c = JSON.parseObject(b.toString()); jsonArray.remove(i);
if (StringUtils.equals(c.getString("deleted"), "true")) { continue outer;
return false; }
} }
return !StringUtils.equals(c.getString("enabled"), "false"); for (int j = 0; j < o.size(); j++) {
}) if (!StringUtils.equals(o.getJSONObject(j).getString("enabled"), "true")) {
.map(b -> JSON.parseObject(b.toString())) jsonArray.remove(i);
.collect(Collectors.toList()); continue outer;
}
}
}
}
for (JSONObject b : enabledConfig) { for (int i = 0; i < jsonArray.size(); i++) {
if (StringUtils.equals(b.getString("key"), "TargetLevel")) { if (jsonArray.get(i) instanceof List) {
s += b.getInteger("value"); JSONArray o = jsonArray.getJSONArray(i);
for (int j = 0; j < o.size(); j++) {
if (StringUtils.equals(o.getJSONObject(j).getString("key"), "TargetLevel")) {
s += o.getJSONObject(j).getInteger("value");
break; break;
} }
} }