From a124268cb10e13b3b902be711238177a370e9359 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 19 May 2021 16:56:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E5=90=8C=E5=90=8D=E5=A4=9A?= =?UTF-8?q?=E4=B8=AAcsv=20=E6=89=A7=E8=A1=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../definition/request/ParameterConfig.java | 4 +++ .../request/unknown/MsJmeterElement.java | 36 +++++++++++-------- .../api/service/ApiAutomationService.java | 1 + 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java index 08a9733c08..b32081c8da 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java @@ -7,6 +7,7 @@ import io.metersphere.commons.utils.ScriptEngineUtils; import lombok.Data; import org.apache.jmeter.config.Arguments; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -39,6 +40,9 @@ public class ParameterConfig { */ private String projectId; + private List csvFilePaths = new ArrayList<>(); + + public boolean isEffective(String projectId) { if (this.config != null && this.config.get(projectId) != null) { return true; diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/unknown/MsJmeterElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/unknown/MsJmeterElement.java index ac9a146c93..1c1a248597 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/unknown/MsJmeterElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/unknown/MsJmeterElement.java @@ -52,6 +52,27 @@ public class MsJmeterElement extends MsTestElement { ((TestElement) scriptWrapper).setName(this.getName()); ((TestElement) scriptWrapper).setEnabled(this.isEnable()); } + // csv 检查处理 + if (!config.isOperating() && scriptWrapper instanceof CSVDataSet && ((CSVDataSet) scriptWrapper).isEnabled()) { + String path = ((CSVDataSet) scriptWrapper).getPropertyAsString("filename"); + if (!new File(path).exists()) { + // 检查场景变量中的csv文件是否存在 + String pathArr[] = path.split("\\/"); + String csvPath = this.getCSVPath(config, pathArr[pathArr.length - 1]); + if (StringUtils.isNotEmpty(csvPath)) { + ((CSVDataSet) scriptWrapper).setProperty("filename", csvPath); + } else { + 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)) { @@ -60,20 +81,6 @@ public class MsJmeterElement extends MsTestElement { 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"); - if (!new File(path).exists()) { - // 检查场景变量中的csv文件是否存在 - String pathArr[] = path.split("\\/"); - String csvPath = this.getCSVPath(config, pathArr[pathArr.length - 1]); - if (StringUtils.isNotEmpty(csvPath)) { - ((CSVDataSet) scriptWrapper).setProperty("filename", csvPath); - } else { - MSException.throwException(StringUtils.isEmpty(((CSVDataSet) scriptWrapper).getName()) ? "CSVDataSet" : ((CSVDataSet) scriptWrapper).getName() + ":[ CSV文件不存在 ]"); - } - } - } if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { // 给所有孩子加一个父亲标志 @@ -82,6 +89,7 @@ public class MsJmeterElement extends MsTestElement { } } } + } } catch (Exception ex) { ex.printStackTrace(); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 4af88db4e8..0353f0dc9a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1173,6 +1173,7 @@ public class ApiAutomationService { HashTree hashTree = null; try { hashTree = request.getTestElement().generateHashTree(config); + LogUtil.info(request.getTestElement().getJmx(hashTree)); } catch (Exception e) { MSException.throwException(e.getMessage()); }