fix(接口自动化): 修复同名多个csv 执行问题
This commit is contained in:
parent
77879cd176
commit
a124268cb1
|
@ -7,6 +7,7 @@ import io.metersphere.commons.utils.ScriptEngineUtils;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.jmeter.config.Arguments;
|
import org.apache.jmeter.config.Arguments;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -39,6 +40,9 @@ public class ParameterConfig {
|
||||||
*/
|
*/
|
||||||
private String projectId;
|
private String projectId;
|
||||||
|
|
||||||
|
private List<String> csvFilePaths = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public boolean isEffective(String projectId) {
|
public boolean isEffective(String projectId) {
|
||||||
if (this.config != null && this.config.get(projectId) != null) {
|
if (this.config != null && this.config.get(projectId) != null) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -52,16 +52,8 @@ public class MsJmeterElement extends MsTestElement {
|
||||||
((TestElement) scriptWrapper).setName(this.getName());
|
((TestElement) scriptWrapper).setName(this.getName());
|
||||||
((TestElement) scriptWrapper).setEnabled(this.isEnable());
|
((TestElement) scriptWrapper).setEnabled(this.isEnable());
|
||||||
}
|
}
|
||||||
if (config.isOperating()) {
|
// csv 检查处理
|
||||||
elementTree = tree.add(scriptWrapper);
|
if (!config.isOperating() && scriptWrapper instanceof CSVDataSet && ((CSVDataSet) scriptWrapper).isEnabled()) {
|
||||||
} else if (!(scriptWrapper instanceof TestPlan) && !(scriptWrapper instanceof ThreadGroup)) {
|
|
||||||
elementTree = tree.add(scriptWrapper);
|
|
||||||
}
|
|
||||||
if (!config.isOperating() && scriptWrapper instanceof ThreadGroup && !((ThreadGroup) scriptWrapper).isEnabled()) {
|
|
||||||
LogUtil.info(((ThreadGroup) scriptWrapper).getName() + "是被禁用线程组不加入执行");
|
|
||||||
} else {
|
|
||||||
// CSV数据检查文件路径是否还存在
|
|
||||||
if (!config.isOperating() && scriptWrapper instanceof CSVDataSet) {
|
|
||||||
String path = ((CSVDataSet) scriptWrapper).getPropertyAsString("filename");
|
String path = ((CSVDataSet) scriptWrapper).getPropertyAsString("filename");
|
||||||
if (!new File(path).exists()) {
|
if (!new File(path).exists()) {
|
||||||
// 检查场景变量中的csv文件是否存在
|
// 检查场景变量中的csv文件是否存在
|
||||||
|
@ -73,7 +65,22 @@ public class MsJmeterElement extends MsTestElement {
|
||||||
MSException.throwException(StringUtils.isEmpty(((CSVDataSet) scriptWrapper).getName()) ? "CSVDataSet" : ((CSVDataSet) scriptWrapper).getName() + ":[ CSV文件不存在 ]");
|
MSException.throwException(StringUtils.isEmpty(((CSVDataSet) scriptWrapper).getName()) ? "CSVDataSet" : ((CSVDataSet) scriptWrapper).getName() + ":[ CSV文件不存在 ]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String csvPath = ((CSVDataSet) scriptWrapper).getPropertyAsString("filename");
|
||||||
|
if (config.getCsvFilePaths().contains(csvPath)) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
config.getCsvFilePaths().add(csvPath);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.isOperating()) {
|
||||||
|
elementTree = tree.add(scriptWrapper);
|
||||||
|
} else if (!(scriptWrapper instanceof TestPlan) && !(scriptWrapper instanceof ThreadGroup)) {
|
||||||
|
elementTree = tree.add(scriptWrapper);
|
||||||
|
}
|
||||||
|
if (!config.isOperating() && scriptWrapper instanceof ThreadGroup && !((ThreadGroup) scriptWrapper).isEnabled()) {
|
||||||
|
LogUtil.info(((ThreadGroup) scriptWrapper).getName() + "是被禁用线程组不加入执行");
|
||||||
|
} else {
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
for (MsTestElement el : hashTree) {
|
for (MsTestElement el : hashTree) {
|
||||||
// 给所有孩子加一个父亲标志
|
// 给所有孩子加一个父亲标志
|
||||||
|
@ -82,6 +89,7 @@ public class MsJmeterElement extends MsTestElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
|
@ -1173,6 +1173,7 @@ public class ApiAutomationService {
|
||||||
HashTree hashTree = null;
|
HashTree hashTree = null;
|
||||||
try {
|
try {
|
||||||
hashTree = request.getTestElement().generateHashTree(config);
|
hashTree = request.getTestElement().generateHashTree(config);
|
||||||
|
LogUtil.info(request.getTestElement().getJmx(hashTree));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MSException.throwException(e.getMessage());
|
MSException.throwException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue