refactor(性能测试): 增加压力参数校验

--bug=1024918 --user=刘瑞斌 【性能测试】执行性能测试空指针错误 https://www.tapd.cn/55049933/s/1356639
This commit is contained in:
CaptainB 2023-03-29 14:00:10 +08:00 committed by 刘瑞斌
parent 4747691abc
commit d16a80cef7
6 changed files with 75 additions and 32 deletions

View File

@ -120,9 +120,6 @@ public class EngineFactory {
} }
if (values instanceof List) { if (values instanceof List) {
Object value = b.get("value"); Object value = b.get("value");
if (value == null) {
MSException.throwException(Translator.get("load_configuration_value_is_null") + ", key:" + key);
}
if ("TargetLevel".equals(key)) { if ("TargetLevel".equals(key)) {
switch (strategy) { switch (strategy) {
default: default:

View File

@ -133,8 +133,10 @@ public class JmeterDocumentParser implements EngineSourceParser {
String autoStopDelay = "30"; String autoStopDelay = "30";
if (autoStopDelays instanceof List) { if (autoStopDelays instanceof List) {
Object o = ((List<?>) autoStopDelays).get(0); Object o = ((List<?>) autoStopDelays).get(0);
if (o != null) {
autoStopDelay = o.toString(); autoStopDelay = o.toString();
} }
}
// 清空child // 清空child
removeChildren(autoStopListener); removeChildren(autoStopListener);
// 添加子元素 // 添加子元素
@ -146,8 +148,10 @@ public class JmeterDocumentParser implements EngineSourceParser {
String autoStop = "false"; String autoStop = "false";
if (autoStops instanceof List) { if (autoStops instanceof List) {
Object o = ((List<?>) autoStops).get(0); Object o = ((List<?>) autoStops).get(0);
if (o != null) {
autoStop = o.toString(); autoStop = o.toString();
} }
}
if (!BooleanUtils.toBoolean(autoStop)) { if (!BooleanUtils.toBoolean(autoStop)) {
return; return;
} }
@ -166,8 +170,10 @@ public class JmeterDocumentParser implements EngineSourceParser {
String serializeThreadGroup = "false"; String serializeThreadGroup = "false";
if (serializeThreadGroups instanceof List) { if (serializeThreadGroups instanceof List) {
Object o = ((List<?>) serializeThreadGroups).get(0); Object o = ((List<?>) serializeThreadGroups).get(0);
if (o != null) {
serializeThreadGroup = o.toString(); serializeThreadGroup = o.toString();
} }
}
List<Element> childNodes = element.elements(); List<Element> childNodes = element.elements();
for (Element item : childNodes) { for (Element item : childNodes) {
if (nodeNameEquals(item, BOOL_PROP)) { if (nodeNameEquals(item, BOOL_PROP)) {
@ -654,8 +660,10 @@ public class JmeterDocumentParser implements EngineSourceParser {
if (tgTypes instanceof List) { if (tgTypes instanceof List) {
Object o = ((List<?>) tgTypes).get(0); Object o = ((List<?>) tgTypes).get(0);
((List<?>) tgTypes).remove(0); ((List<?>) tgTypes).remove(0);
if (o != null) {
tgType = o.toString(); tgType = o.toString();
} }
}
if (StringUtils.equals(tgType, THREAD_GROUP)) { if (StringUtils.equals(tgType, THREAD_GROUP)) {
processBaseThreadGroup(threadGroup, THREAD_GROUP); processBaseThreadGroup(threadGroup, THREAD_GROUP);
} }
@ -713,29 +721,37 @@ public class JmeterDocumentParser implements EngineSourceParser {
if (targetLevels instanceof List) { if (targetLevels instanceof List) {
Object o = ((List<?>) targetLevels).get(0); Object o = ((List<?>) targetLevels).get(0);
((List<?>) targetLevels).remove(0); ((List<?>) targetLevels).remove(0);
if (o != null) {
threads = o.toString(); threads = o.toString();
} }
}
Object rampUps = context.getProperty("RampUp"); Object rampUps = context.getProperty("RampUp");
String rampUp = "1"; String rampUp = "1";
if (rampUps instanceof List) { if (rampUps instanceof List) {
Object o = ((List<?>) rampUps).get(0); Object o = ((List<?>) rampUps).get(0);
((List<?>) rampUps).remove(0); ((List<?>) rampUps).remove(0);
if (o != null) {
rampUp = o.toString(); rampUp = o.toString();
} }
}
Object durations = context.getProperty("duration"); Object durations = context.getProperty("duration");
String duration = "2"; String duration = "2";
if (durations instanceof List) { if (durations instanceof List) {
Object o = ((List<?>) durations).get(0); Object o = ((List<?>) durations).get(0);
((List<?>) durations).remove(0); ((List<?>) durations).remove(0);
if (o != null) {
duration = o.toString(); duration = o.toString();
} }
}
Object onSampleErrors = context.getProperty("onSampleError"); Object onSampleErrors = context.getProperty("onSampleError");
String onSampleError = "continue"; String onSampleError = "continue";
if (onSampleErrors instanceof List) { if (onSampleErrors instanceof List) {
Object o = ((List<?>) onSampleErrors).get(0); Object o = ((List<?>) onSampleErrors).get(0);
((List<?>) onSampleErrors).remove(0); ((List<?>) onSampleErrors).remove(0);
if (o != null) {
onSampleError = o.toString(); onSampleError = o.toString();
} }
}
Object units = context.getProperty("unit"); Object units = context.getProperty("unit");
if (units instanceof List) { if (units instanceof List) {
Object o = ((List<?>) units).get(0); Object o = ((List<?>) units).get(0);
@ -746,15 +762,19 @@ public class JmeterDocumentParser implements EngineSourceParser {
if (deleteds instanceof List) { if (deleteds instanceof List) {
Object o = ((List<?>) deleteds).get(0); Object o = ((List<?>) deleteds).get(0);
((List<?>) deleteds).remove(0); ((List<?>) deleteds).remove(0);
if (o != null) {
deleted = o.toString(); deleted = o.toString();
} }
}
Object enableds = context.getProperty("enabled"); Object enableds = context.getProperty("enabled");
String enabled = "true"; String enabled = "true";
if (enableds instanceof List) { if (enableds instanceof List) {
Object o = ((List<?>) enableds).get(0); Object o = ((List<?>) enableds).get(0);
((List<?>) enableds).remove(0); ((List<?>) enableds).remove(0);
if (o != null) {
enabled = o.toString(); enabled = o.toString();
} }
}
threadGroup.addAttribute("enabled", enabled); threadGroup.addAttribute("enabled", enabled);
if (BooleanUtils.toBoolean(deleted)) { if (BooleanUtils.toBoolean(deleted)) {
@ -814,36 +834,46 @@ public class JmeterDocumentParser implements EngineSourceParser {
if (targetLevels instanceof List) { if (targetLevels instanceof List) {
Object o = ((List<?>) targetLevels).get(0); Object o = ((List<?>) targetLevels).get(0);
((List<?>) targetLevels).remove(0); ((List<?>) targetLevels).remove(0);
if (o != null) {
threads = o.toString(); threads = o.toString();
} }
}
Object rampUps = context.getProperty("RampUp"); Object rampUps = context.getProperty("RampUp");
String rampUp = "1"; String rampUp = "1";
if (rampUps instanceof List) { if (rampUps instanceof List) {
Object o = ((List<?>) rampUps).get(0); Object o = ((List<?>) rampUps).get(0);
((List<?>) rampUps).remove(0); ((List<?>) rampUps).remove(0);
if (o != null) {
rampUp = o.toString(); rampUp = o.toString();
} }
}
Object steps = context.getProperty("Steps"); Object steps = context.getProperty("Steps");
String step = "2"; String step = "2";
if (steps instanceof List) { if (steps instanceof List) {
Object o = ((List<?>) steps).get(0); Object o = ((List<?>) steps).get(0);
((List<?>) steps).remove(0); ((List<?>) steps).remove(0);
if (o != null) {
step = o.toString(); step = o.toString();
} }
}
Object holds = context.getProperty("Hold"); Object holds = context.getProperty("Hold");
String hold = "2"; String hold = "2";
if (holds instanceof List) { if (holds instanceof List) {
Object o = ((List<?>) holds).get(0); Object o = ((List<?>) holds).get(0);
((List<?>) holds).remove(0); ((List<?>) holds).remove(0);
if (o != null) {
hold = o.toString(); hold = o.toString();
} }
}
Object onSampleErrors = context.getProperty("onSampleError"); Object onSampleErrors = context.getProperty("onSampleError");
String onSampleError = "continue"; String onSampleError = "continue";
if (onSampleErrors instanceof List) { if (onSampleErrors instanceof List) {
Object o = ((List<?>) onSampleErrors).get(0); Object o = ((List<?>) onSampleErrors).get(0);
((List<?>) onSampleErrors).remove(0); ((List<?>) onSampleErrors).remove(0);
if (o != null) {
onSampleError = o.toString(); onSampleError = o.toString();
} }
}
Object units = context.getProperty("unit"); Object units = context.getProperty("unit");
if (units instanceof List) { if (units instanceof List) {
Object o = ((List<?>) units).get(0); Object o = ((List<?>) units).get(0);
@ -854,15 +884,19 @@ public class JmeterDocumentParser implements EngineSourceParser {
if (deleteds instanceof List) { if (deleteds instanceof List) {
Object o = ((List<?>) deleteds).get(0); Object o = ((List<?>) deleteds).get(0);
((List<?>) deleteds).remove(0); ((List<?>) deleteds).remove(0);
if (o != null) {
deleted = o.toString(); deleted = o.toString();
} }
}
Object enableds = context.getProperty("enabled"); Object enableds = context.getProperty("enabled");
String enabled = "true"; String enabled = "true";
if (enableds instanceof List) { if (enableds instanceof List) {
Object o = ((List<?>) enableds).get(0); Object o = ((List<?>) enableds).get(0);
((List<?>) enableds).remove(0); ((List<?>) enableds).remove(0);
if (o != null) {
enabled = o.toString(); enabled = o.toString();
} }
}
threadGroup.addAttribute("enabled", enabled); threadGroup.addAttribute("enabled", enabled);
if (BooleanUtils.toBoolean(deleted)) { if (BooleanUtils.toBoolean(deleted)) {
@ -894,8 +928,10 @@ public class JmeterDocumentParser implements EngineSourceParser {
if (tgTypes instanceof List) { if (tgTypes instanceof List) {
Object o = ((List<?>) tgTypes).get(0); Object o = ((List<?>) tgTypes).get(0);
((List<?>) tgTypes).remove(0); ((List<?>) tgTypes).remove(0);
if (o != null) {
tgType = o.toString(); tgType = o.toString();
} }
}
if (StringUtils.equals(tgType, THREAD_GROUP)) { if (StringUtils.equals(tgType, THREAD_GROUP)) {
threadGroup.setName(THREAD_GROUP); threadGroup.setName(THREAD_GROUP);
threadGroup.addAttribute("guiclass", THREAD_GROUP + "Gui"); threadGroup.addAttribute("guiclass", THREAD_GROUP + "Gui");
@ -933,8 +969,10 @@ public class JmeterDocumentParser implements EngineSourceParser {
String duration = "2"; String duration = "2";
if (durations instanceof List) { if (durations instanceof List) {
Object o = ((List<?>) durations).remove(0); Object o = ((List<?>) durations).remove(0);
if (o != null) {
duration = o.toString(); duration = o.toString();
} }
}
Object units = context.getProperty("unit"); Object units = context.getProperty("unit");
if (units instanceof List) { if (units instanceof List) {
((List<?>) units).remove(0); ((List<?>) units).remove(0);
@ -956,43 +994,55 @@ public class JmeterDocumentParser implements EngineSourceParser {
if (targetLevels instanceof List) { if (targetLevels instanceof List) {
Object o = ((List<?>) targetLevels).get(0); Object o = ((List<?>) targetLevels).get(0);
((List<?>) targetLevels).remove(0); ((List<?>) targetLevels).remove(0);
if (o != null) {
threads = o.toString(); threads = o.toString();
} }
}
Object iterateNum = context.getProperty("iterateNum"); Object iterateNum = context.getProperty("iterateNum");
String loops = "1"; String loops = "1";
if (iterateNum instanceof List) { if (iterateNum instanceof List) {
Object o = ((List<?>) iterateNum).get(0); Object o = ((List<?>) iterateNum).get(0);
((List<?>) iterateNum).remove(0); ((List<?>) iterateNum).remove(0);
if (o != null) {
loops = o.toString(); loops = o.toString();
} }
}
Object onSampleErrors = context.getProperty("onSampleError"); Object onSampleErrors = context.getProperty("onSampleError");
String onSampleError = "continue"; String onSampleError = "continue";
if (onSampleErrors instanceof List) { if (onSampleErrors instanceof List) {
Object o = ((List<?>) onSampleErrors).get(0); Object o = ((List<?>) onSampleErrors).get(0);
((List<?>) onSampleErrors).remove(0); ((List<?>) onSampleErrors).remove(0);
if (o != null) {
onSampleError = o.toString(); onSampleError = o.toString();
} }
}
Object rampUps = context.getProperty("iterateRampUpTime"); Object rampUps = context.getProperty("iterateRampUpTime");
String rampUp = "10"; String rampUp = "10";
if (rampUps instanceof List) { if (rampUps instanceof List) {
Object o = ((List<?>) rampUps).get(0); Object o = ((List<?>) rampUps).get(0);
((List<?>) rampUps).remove(0); ((List<?>) rampUps).remove(0);
if (o != null) {
rampUp = o.toString(); rampUp = o.toString();
} }
}
Object deleteds = context.getProperty("deleted"); Object deleteds = context.getProperty("deleted");
String deleted = "false"; String deleted = "false";
if (deleteds instanceof List) { if (deleteds instanceof List) {
Object o = ((List<?>) deleteds).get(0); Object o = ((List<?>) deleteds).get(0);
((List<?>) deleteds).remove(0); ((List<?>) deleteds).remove(0);
if (o != null) {
deleted = o.toString(); deleted = o.toString();
} }
}
Object enableds = context.getProperty("enabled"); Object enableds = context.getProperty("enabled");
String enabled = "true"; String enabled = "true";
if (enableds instanceof List) { if (enableds instanceof List) {
Object o = ((List<?>) enableds).get(0); Object o = ((List<?>) enableds).get(0);
((List<?>) enableds).remove(0); ((List<?>) enableds).remove(0);
if (o != null) {
enabled = o.toString(); enabled = o.toString();
} }
}
threadGroup.addAttribute("enabled", enabled); threadGroup.addAttribute("enabled", enabled);
if (BooleanUtils.toBoolean(deleted)) { if (BooleanUtils.toBoolean(deleted)) {
threadGroup.addAttribute("enabled", "false"); threadGroup.addAttribute("enabled", "false");

View File

@ -1 +0,0 @@
load_configuration_value_is_null=

View File

@ -1 +0,0 @@
load_configuration_value_is_null=Load configuration error

View File

@ -1 +0,0 @@
load_configuration_value_is_null=压力配置参数错误

View File

@ -1 +0,0 @@
load_configuration_value_is_null=壓力配置參數錯誤