diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/BaseEnvElement.java b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/BaseEnvElement.java index b8ffde66a4..501634378a 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/BaseEnvElement.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/BaseEnvElement.java @@ -1,16 +1,16 @@ package io.metersphere.api.dto.scenario.environment.item; -import io.metersphere.plugin.core.MsTestElement; import lombok.Data; import java.util.LinkedList; + @Data public class BaseEnvElement { // 组件类型 private String type; // 用于数据反射对象 - private String clazzName = MsTestElement.class.getCanonicalName(); + private String clazzName = BaseEnvElement.class.getCanonicalName(); // 自身资源ID(用例ID/接口ID/场景ID)等 private String id; @@ -39,7 +39,7 @@ public class BaseEnvElement { private String refType; // 子组件 - private LinkedList hashTree; + private LinkedList hashTree; // 项目ID private String projectId; diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/MsScenarioEnv.java b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/MsScenarioEnv.java new file mode 100644 index 0000000000..2ea02b42eb --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/MsScenarioEnv.java @@ -0,0 +1,11 @@ +package io.metersphere.api.dto.scenario.environment.item; + +import lombok.Data; + +import java.util.Map; + +@Data +public class MsScenarioEnv { + private String environmentId; + private Map environmentMap; +} diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java index 2134ca6c42..b75ee363ba 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java @@ -10,6 +10,7 @@ import io.metersphere.api.dto.definition.request.MsScenario; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; +import io.metersphere.api.dto.scenario.environment.item.MsScenarioEnv; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; @@ -172,6 +173,9 @@ public class ApiScenarioEnvService { environmentType = EnvironmentType.JSON.toString(); } String definition = apiScenarioWithBLOBs.getScenarioDefinition(); + JSONObject element = JSONUtil.parseObject(definition); + ElementUtil.dataFormatting(element); + definition = element.toString(); MsScenario scenario = JSON.parseObject(definition, MsScenario.class); GenerateHashTreeUtil.parse(definition, scenario); if (StringUtils.equals(environmentType, EnvironmentType.JSON.toString()) && StringUtils.isNotEmpty(environmentJson)) { @@ -189,7 +193,7 @@ public class ApiScenarioEnvService { public boolean verifyScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs) { if (apiScenarioWithBLOBs != null) { String definition = apiScenarioWithBLOBs.getScenarioDefinition(); - MsScenario scenario = JSON.parseObject(definition, MsScenario.class); + MsScenarioEnv scenario = JSON.parseObject(definition, MsScenarioEnv.class); Map envMap = scenario.getEnvironmentMap(); return this.check(definition, envMap, scenario.getEnvironmentId(), apiScenarioWithBLOBs.getProjectId()); } @@ -250,7 +254,7 @@ public class ApiScenarioEnvService { public boolean verifyPlanScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs, TestPlanApiScenario testPlanApiScenarios) { if (apiScenarioWithBLOBs != null) { String definition = apiScenarioWithBLOBs.getScenarioDefinition(); - MsScenario scenario = JSON.parseObject(definition, MsScenario.class); + MsScenarioEnv scenario = JSON.parseObject(definition, MsScenarioEnv.class); Map envMap = scenario.getEnvironmentMap(); if (testPlanApiScenarios != null) { String envType = testPlanApiScenarios.getEnvironmentType(); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 8dc2424c93..15490ea465 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -186,7 +186,7 @@ public class JMeterService { public void run(JmeterRunRequestDTO request) { if (request.getPool().isPool() && StringUtils.isNotBlank(request.getRunMode())) { this.runNode(request); - } else { + } else if (request.getHashTree() != null) { //解析hashTree,是否含有文件库文件 HashTreeUtil.initRepositoryFiles(request); CommonBeanFactory.getBean(ExecThreadPoolExecutor.class).addTask(request); diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java index bbd2cc29e1..2ac5c48759 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java @@ -10,18 +10,21 @@ import io.metersphere.api.dto.definition.request.*; import io.metersphere.api.dto.definition.request.variable.ScenarioVariable; import io.metersphere.api.jmeter.NewDriverManager; import io.metersphere.api.jmeter.ResourcePoolCalculation; -import io.metersphere.base.domain.TestResource; -import io.metersphere.service.ApiExecutionQueueService; -import io.metersphere.service.RemakeReportService; -import io.metersphere.commons.constants.ElementConstants; -import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.base.domain.ApiScenarioWithBLOBs; +import io.metersphere.base.domain.TestResource; import io.metersphere.base.domain.TestResourcePool; import io.metersphere.base.mapper.TestResourcePoolMapper; +import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.constants.RunModeConstants; -import io.metersphere.dto.*; +import io.metersphere.dto.BaseSystemConfigDTO; +import io.metersphere.dto.JmeterRunRequestDTO; +import io.metersphere.dto.ResultDTO; +import io.metersphere.dto.RunModeConfigDTO; +import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.plugin.core.MsTestElement; +import io.metersphere.service.ApiExecutionQueueService; +import io.metersphere.service.RemakeReportService; import io.metersphere.utils.LoggerUtil; import io.metersphere.vo.BooleanPool; import io.metersphere.xpack.api.service.ApiRetryOnFailureService; @@ -139,14 +142,17 @@ public class GenerateHashTreeUtil { MsThreadGroup group = new MsThreadGroup(); group.setLabel(item.getName()); group.setName(runRequest.getReportId()); - MsScenario scenario = JSON.parseObject(item.getScenarioDefinition(), MsScenario.class); + JSONObject element = JSONUtil.parseObject(item.getScenarioDefinition()); + ElementUtil.dataFormatting(element); + String definition = element.toString(); + MsScenario scenario = JSON.parseObject(definition, MsScenario.class); group.setOnSampleError(scenario.getOnSampleError()); if (planEnvMap != null && planEnvMap.size() > 0) { scenario.setEnvironmentMap(planEnvMap); } else { setScenarioEnv(scenario, item); } - String data = item.getScenarioDefinition(); + String data = definition; // 失败重试 if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) { ApiRetryOnFailureService apiRetryOnFailureService = CommonBeanFactory.getBean(ApiRetryOnFailureService.class); @@ -172,6 +178,7 @@ public class GenerateHashTreeUtil { } catch (Exception ex) { remakeException(runRequest); LoggerUtil.error("场景资源:" + item.getName() + ", 生成执行脚本失败", runRequest.getReportId(), ex); + return null; } LogUtil.info(testPlan.getJmx(jmeterHashTree));