From 1d50e1a910b2973ccc61ff9318eff58651dfdf59 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 27 Jan 2021 14:41:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9C=BA=E6=99=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E8=87=AA=E5=AE=9A=E4=B9=89=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/sampler/MsJDBCSampler.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index a918fd4589..554d8fb504 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -24,7 +24,6 @@ import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; import java.util.List; -import java.util.stream.Collectors; @Data @EqualsAndHashCode(callSuper = true) @@ -51,7 +50,7 @@ public class MsJDBCSampler extends MsTestElement { @JSONField(ordinal = 28) private String dataSourceId; @JSONField(ordinal = 29) - private String protocol="SQL"; + private String protocol = "SQL"; @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { @@ -62,7 +61,8 @@ public class MsJDBCSampler extends MsTestElement { this.getRefElement(this); } if (StringUtils.isNotEmpty(dataSourceId)) { - initDataSource(); + this.dataSource = null; + this.initDataSource(); } if (this.dataSource == null) { MSException.throwException("数据源为空无法执行"); @@ -79,14 +79,16 @@ public class MsJDBCSampler extends MsTestElement { private void initDataSource() { ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); - ApiTestEnvironmentWithBLOBs environment = environmentService.get(this.dataSourceId); + ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId); if (environment != null && environment.getConfig() != null) { - EnvironmentConfig config = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); - if (CollectionUtils.isNotEmpty(config.getDatabaseConfigs())) { - List databaseConfigs = config.getDatabaseConfigs().stream().filter((DatabaseConfig d) -> this.dataSourceId.equals(d.getId())).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(databaseConfigs)) { - this.dataSource = databaseConfigs.get(0); - } + EnvironmentConfig envConfig = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); + if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) { + envConfig.getDatabaseConfigs().forEach(item -> { + if (item.getId().equals(this.dataSourceId)) { + this.dataSource = item; + return; + } + }); } } }