diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index 435c1a75d0..c48ff30480 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -20,9 +20,6 @@ import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.config.Arguments; -import org.apache.jmeter.config.CSVDataSet; -import org.apache.jmeter.config.RandomVariableConfig; -import org.apache.jmeter.modifiers.CounterConfig; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; @@ -68,7 +65,8 @@ public class MsScenario extends MsTestElement { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); ApiScenarioWithBLOBs scenario = apiAutomationService.getApiScenario(this.getId()); JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); - hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() {}); + hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() { + }); } catch (Exception ex) { ex.printStackTrace(); } @@ -88,9 +86,9 @@ public class MsScenario extends MsTestElement { } // 场景变量和环境变量 tree.add(arguments(config)); - addCsvDataSet(tree); - addCounter(tree); - addRandom(tree); + this.addCsvDataSet(tree, variables); + this.addCounter(tree, variables); + this.addRandom(tree, variables); if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { el.toHashTree(tree, el.getHashTree(), config); @@ -133,71 +131,5 @@ public class MsScenario extends MsTestElement { return arguments; } - private void addCsvDataSet(HashTree tree) { - if (CollectionUtils.isNotEmpty(this.getVariables())) { - List list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(list)) { - list.forEach(item -> { - CSVDataSet csvDataSet = new CSVDataSet(); - csvDataSet.setEnabled(true); - csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName()); - csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); - csvDataSet.setName(item.getName()); - csvDataSet.setProperty("fileEncoding", item.getEncoding()); - csvDataSet.setProperty("variableNames", item.getName()); - if (CollectionUtils.isNotEmpty(item.getFiles())) { - csvDataSet.setProperty("filename", BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName()); - } - csvDataSet.setIgnoreFirstLine(false); - csvDataSet.setProperty("delimiter", item.getDelimiter()); - csvDataSet.setComment(item.getDescription()); - tree.add(csvDataSet); - }); - } - } - } - - private void addCounter(HashTree tree) { - if (CollectionUtils.isNotEmpty(this.getVariables())) { - List list = variables.stream().filter(ScenarioVariable::isCounterValid).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(list)) { - list.forEach(item -> { - CounterConfig counterConfig = new CounterConfig(); - counterConfig.setEnabled(true); - counterConfig.setProperty(TestElement.TEST_CLASS, CounterConfig.class.getName()); - counterConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("CounterConfigGui")); - counterConfig.setName(item.getName()); - counterConfig.setStart(item.getStartNumber()); - counterConfig.setEnd(item.getEndNumber()); - counterConfig.setVarName(item.getName()); - counterConfig.setIncrement(item.getIncrement()); - counterConfig.setFormat(item.getValue()); - counterConfig.setComment(item.getDescription()); - tree.add(counterConfig); - }); - } - } - } - - private void addRandom(HashTree tree) { - if (CollectionUtils.isNotEmpty(this.getVariables())) { - List list = variables.stream().filter(ScenarioVariable::isRandom).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(list)) { - list.forEach(item -> { - RandomVariableConfig randomVariableConfig = new RandomVariableConfig(); - randomVariableConfig.setEnabled(true); - randomVariableConfig.setProperty(TestElement.TEST_CLASS, RandomVariableConfig.class.getName()); - randomVariableConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); - randomVariableConfig.setName(item.getName()); - randomVariableConfig.setProperty("variableName", item.getName()); - randomVariableConfig.setProperty("outputFormat", item.getValue()); - randomVariableConfig.setProperty("minimumValue", item.getMinNumber()); - randomVariableConfig.setProperty("maximumValue", item.getMaxNumber()); - randomVariableConfig.setComment(item.getDescription()); - tree.add(randomVariableConfig); - }); - } - } - } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index 48364c9b74..976edef4e2 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -22,6 +22,7 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler; import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler; import io.metersphere.api.dto.definition.request.timer.MsConstantTimer; +import io.metersphere.api.dto.definition.request.variable.ScenarioVariable; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.service.ApiDefinitionService; @@ -33,6 +34,9 @@ import io.metersphere.commons.utils.LogUtil; import lombok.Data; import org.apache.commons.collections.CollectionUtils; import org.apache.jmeter.config.Arguments; +import org.apache.jmeter.config.CSVDataSet; +import org.apache.jmeter.config.RandomVariableConfig; +import org.apache.jmeter.modifiers.CounterConfig; import org.apache.jmeter.protocol.http.control.AuthManager; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; @@ -42,6 +46,7 @@ import org.apache.jorphan.collections.ListedHashTree; import java.io.ByteArrayOutputStream; import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type") @JsonSubTypes({ @@ -91,6 +96,7 @@ public abstract class MsTestElement { @JSONField(ordinal = 10) private LinkedList hashTree; + private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; // 公共环境逐层传递,如果自身有环境 以自身引用环境为准否则以公共环境作为请求环境 public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { for (MsTestElement el : hashTree) { @@ -166,6 +172,74 @@ public abstract class MsTestElement { } return null; } + + protected void addCsvDataSet(HashTree tree,List variables) { + if (CollectionUtils.isNotEmpty(variables)) { + List list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(list)) { + list.forEach(item -> { + CSVDataSet csvDataSet = new CSVDataSet(); + csvDataSet.setEnabled(true); + csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName()); + csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); + csvDataSet.setName(item.getName()); + csvDataSet.setProperty("fileEncoding", item.getEncoding()); + csvDataSet.setProperty("variableNames", item.getName()); + if (CollectionUtils.isNotEmpty(item.getFiles())) { + csvDataSet.setProperty("filename", BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName()); + } + csvDataSet.setIgnoreFirstLine(false); + csvDataSet.setProperty("delimiter", item.getDelimiter()); + csvDataSet.setComment(item.getDescription()); + tree.add(csvDataSet); + }); + } + } + } + + protected void addCounter(HashTree tree,List variables) { + if (CollectionUtils.isNotEmpty(variables)) { + List list = variables.stream().filter(ScenarioVariable::isCounterValid).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(list)) { + list.forEach(item -> { + CounterConfig counterConfig = new CounterConfig(); + counterConfig.setEnabled(true); + counterConfig.setProperty(TestElement.TEST_CLASS, CounterConfig.class.getName()); + counterConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("CounterConfigGui")); + counterConfig.setName(item.getName()); + counterConfig.setStart(item.getStartNumber()); + counterConfig.setEnd(item.getEndNumber()); + counterConfig.setVarName(item.getName()); + counterConfig.setIncrement(item.getIncrement()); + counterConfig.setFormat(item.getValue()); + counterConfig.setComment(item.getDescription()); + tree.add(counterConfig); + }); + } + } + } + + protected void addRandom(HashTree tree,List variables) { + if (CollectionUtils.isNotEmpty(variables)) { + List list = variables.stream().filter(ScenarioVariable::isRandom).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(list)) { + list.forEach(item -> { + RandomVariableConfig randomVariableConfig = new RandomVariableConfig(); + randomVariableConfig.setEnabled(true); + randomVariableConfig.setProperty(TestElement.TEST_CLASS, RandomVariableConfig.class.getName()); + randomVariableConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); + randomVariableConfig.setName(item.getName()); + randomVariableConfig.setProperty("variableName", item.getName()); + randomVariableConfig.setProperty("outputFormat", item.getValue()); + randomVariableConfig.setProperty("minimumValue", item.getMinNumber()); + randomVariableConfig.setProperty("maximumValue", item.getMaxNumber()); + randomVariableConfig.setComment(item.getDescription()); + tree.add(randomVariableConfig); + }); + } + } + } + } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java index c2c38fa3b3..57f279adfa 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java @@ -60,6 +60,12 @@ public class MsLoopController extends MsTestElement { config.setStepType("LOOP"); final HashTree groupTree = controller(tree); + if (CollectionUtils.isNotEmpty(config.getVariables())) { + this.addCsvDataSet(groupTree, config.getVariables()); + this.addCounter(groupTree, config.getVariables()); + this.addRandom(groupTree, config.getVariables()); + } + // 循环下都增加一个计数器,用于结果统计 groupTree.add(addCounterConfig()); // 不打开执行成功后轮询功能,则成功后就停止循环 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 a8a190bf6e..c015d4c19b 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -27,6 +27,7 @@ import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.i18n.Translator; import io.metersphere.job.sechedule.ApiScenarioTestJob; +import io.metersphere.job.sechedule.TestPlanTestJob; import io.metersphere.service.ScheduleService; import io.metersphere.track.dto.TestPlanDTO; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; @@ -630,8 +631,14 @@ public class ApiAutomationService { } private void addOrUpdateApiScenarioCronJob(Schedule request) { - scheduleService.addOrUpdateCronJob( - request, ApiScenarioTestJob.getJobKey(request.getResourceId()), ApiScenarioTestJob.getTriggerKey(request.getResourceId()), ApiScenarioTestJob.class); + if(StringUtils.equals(request.getGroup(),ScheduleGroup.TEST_PLAN_TEST.name())){ + scheduleService.addOrUpdateCronJob( + request, TestPlanTestJob.getJobKey(request.getResourceId()), TestPlanTestJob.getTriggerKey(request.getResourceId()), TestPlanTestJob.class); + }else{ + scheduleService.addOrUpdateCronJob( + request, ApiScenarioTestJob.getJobKey(request.getResourceId()), ApiScenarioTestJob.getTriggerKey(request.getResourceId()), ApiScenarioTestJob.class); + } + } public JmxInfoDTO genPerformanceTestJmx(RunScenarioRequest request) throws Exception { diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 792ace0c68..bb9c030916 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 792ace0c68d2b4ff42a74d8e6df32ca7f290ca1c +Subproject commit bb9c0309161c91bf7d0a9f85cc44bc0eb0fc11ac diff --git a/frontend/src/business/components/api/automation/scenario/variable/EditConstant.vue b/frontend/src/business/components/api/automation/scenario/variable/EditConstant.vue index 092979f24c..eb4165ff1a 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/EditConstant.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/EditConstant.vue @@ -1,7 +1,7 @@