From 4aa518599719d4cde8a2fa445504f4cca0ed3800 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 | 37 ++++++++++++------- .../api/service/ApiAutomationService.java | 1 + 3 files changed, 28 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..e6870ce3b1 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,28 @@ 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 +82,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 +90,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 355b147443..1c019429ea 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1261,6 +1261,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()); }