From 6d9f017a90973567248e609905b68c1de4545cac Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Fri, 17 May 2024 16:24:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=AD=A5=E9=AA=A4=E7=BA=A7csv=E4=BD=9C=E7=94=A8=E5=9F=9F?= =?UTF-8?q?=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/metersphere/api/dto/ApiFile.java | 5 +++++ .../java/io/metersphere/api/dto/scenario/CsvVariable.java | 2 +- .../api/parser/jmeter/child/MsCsvChildPreConverter.java | 7 ++++++- .../api/parser/jmeter/constants/JmeterProperty.java | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/ApiFile.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/ApiFile.java index ff851dcda8..2e090fc48a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/ApiFile.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/ApiFile.java @@ -2,6 +2,7 @@ package io.metersphere.api.dto; import jakarta.validation.constraints.NotBlank; import lombok.Data; +import org.apache.commons.lang3.StringUtils; /** * 接口执行所需要的文件 @@ -33,4 +34,8 @@ public class ApiFile { * 引用的文件被删除,需要标识 */ private Boolean delete = false; + + public boolean isValid() { + return StringUtils.isNotBlank(fileId) && StringUtils.isNotBlank(fileName) ; + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/CsvVariable.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/CsvVariable.java index e934b514a4..3276368558 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/CsvVariable.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/CsvVariable.java @@ -79,7 +79,7 @@ public class CsvVariable { private Boolean stopThreadOnEof = false; public boolean isValid() { - return StringUtils.isNotBlank(name) && file != null; + return StringUtils.isNotBlank(name) && file != null && file.isValid(); } public boolean isEnable() { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/child/MsCsvChildPreConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/child/MsCsvChildPreConverter.java index fde1b84e4d..9928a02124 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/child/MsCsvChildPreConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/child/MsCsvChildPreConverter.java @@ -18,6 +18,7 @@ import org.apache.jorphan.collections.HashTree; import java.io.File; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.UUID; /** * 解析 csv 文件 @@ -37,7 +38,10 @@ public class MsCsvChildPreConverter extends AbstractJmeterElementConverter { CsvVariable csvVariable = apiParamConfig.getCsvVariable(csvId); if (csvVariable != null) { - addCsvDataSet(tree, JmeterProperty.CSVDataSetProperty.SHARE_MODE_THREAD, csvVariable); + // 场景级的线程共享,步骤级的私有 + String shareMode = StringUtils.equals(csvVariable.getScope(), CsvVariable.CsvVariableScope.SCENARIO.name()) ? + JmeterProperty.CSVDataSetProperty.SHARE_MODE_THREAD : UUID.randomUUID().toString(); + addCsvDataSet(tree, shareMode, csvVariable); } }); } @@ -66,6 +70,7 @@ public class MsCsvChildPreConverter extends AbstractJmeterElementConverter