This is an automated email from the ASF dual-hosted git repository.
tuichenchuxin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 7feeecf958a Refactor e2e jdbc rule config load logic to support
database special config (#27610)
7feeecf958a is described below
commit 7feeecf958a1fb7fc4eb9298e9580fcb789a9a7a
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Aug 1 17:05:15 2023 +0800
Refactor e2e jdbc rule config load logic to support database special config
(#27610)
* Refactor e2e jdbc rule config load logic to support database special
config
* Refactor e2e jdbc rule config load logic to support database special
config
---
.../atomic/adapter/AdapterContainerFactory.java | 2 +-
.../adapter/impl/ShardingSphereJdbcContainer.java | 10 +++++++---
.../env/runtime/scenario/path/ScenarioCommonPath.java | 17 ++++++++++++-----
3 files changed, 20 insertions(+), 9 deletions(-)
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/AdapterContainerFactory.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/AdapterContainerFactory.java
index 67db4750e92..396c670f5ca 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/AdapterContainerFactory.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/AdapterContainerFactory.java
@@ -54,7 +54,7 @@ public final class AdapterContainerFactory {
? new
ShardingSphereProxyClusterContainer(databaseType, containerConfig)
: new
ShardingSphereProxyStandaloneContainer(databaseType, containerConfig);
case JDBC:
- return new ShardingSphereJdbcContainer(storageContainer,
scenario);
+ return new ShardingSphereJdbcContainer(storageContainer,
scenario, databaseType);
default:
throw new RuntimeException(String.format("Unknown adapter
`%s`.", adapter));
}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereJdbcContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereJdbcContainer.java
index fc9e63b9c3e..96e08884393 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereJdbcContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereJdbcContainer.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.test.e2e.env.container.atomic.adapter.impl;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
import
org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration;
@@ -45,11 +46,14 @@ public final class ShardingSphereJdbcContainer implements
EmbeddedITContainer, A
private final ScenarioCommonPath scenarioCommonPath;
+ private final DatabaseType databaseType;
+
private final AtomicReference<DataSource> targetDataSourceProvider = new
AtomicReference<>();
- public ShardingSphereJdbcContainer(final StorageContainer
storageContainer, final String scenario) {
+ public ShardingSphereJdbcContainer(final StorageContainer
storageContainer, final String scenario, final DatabaseType databaseType) {
this.storageContainer = storageContainer;
scenarioCommonPath = new ScenarioCommonPath(scenario);
+ this.databaseType = databaseType;
}
@Override
@@ -63,7 +67,7 @@ public final class ShardingSphereJdbcContainer implements
EmbeddedITContainer, A
if (Strings.isNullOrEmpty(serverLists)) {
try {
targetDataSourceProvider.set(
-
YamlShardingSphereDataSourceFactory.createDataSource(storageContainer.getActualDataSourceMap(),
new File(scenarioCommonPath.getRuleConfigurationFile())));
+
YamlShardingSphereDataSourceFactory.createDataSource(storageContainer.getActualDataSourceMap(),
new File(scenarioCommonPath.getRuleConfigurationFile(databaseType))));
} catch (final SQLException | IOException ex) {
throw new RuntimeException(ex);
}
@@ -76,7 +80,7 @@ public final class ShardingSphereJdbcContainer implements
EmbeddedITContainer, A
@SneakyThrows({SQLException.class, IOException.class})
private DataSource createGovernanceClientDataSource(final String
serverLists) {
- YamlRootConfiguration rootConfig = YamlEngine.unmarshal(new
File(scenarioCommonPath.getRuleConfigurationFile()),
YamlRootConfiguration.class);
+ YamlRootConfiguration rootConfig = YamlEngine.unmarshal(new
File(scenarioCommonPath.getRuleConfigurationFile(databaseType)),
YamlRootConfiguration.class);
rootConfig.setMode(createYamlModeConfiguration(serverLists));
return
YamlShardingSphereDataSourceFactory.createDataSource(storageContainer.getActualDataSourceMap(),
YamlEngine.marshal(rootConfig).getBytes(StandardCharsets.UTF_8));
}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/scenario/path/ScenarioCommonPath.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/scenario/path/ScenarioCommonPath.java
index 54a58da920b..a39309e8dd0 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/scenario/path/ScenarioCommonPath.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/scenario/path/ScenarioCommonPath.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.test.e2e.env.runtime.scenario.path;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import java.net.URL;
@@ -48,10 +49,12 @@ public final class ScenarioCommonPath {
/**
* Get rule configuration file.
*
+ * @param databaseType database type
* @return rule configuration file
*/
- public String getRuleConfigurationFile() {
- return getFile(RULE_CONFIG_FILE);
+ public String getRuleConfigurationFile(final DatabaseType databaseType) {
+ String databaseFileName = String.join("/",
String.format("env/scenario/%s/jdbc/conf", scenario),
databaseType.getType().toLowerCase(), RULE_CONFIG_FILE);
+ return exists(databaseFileName) ? getFile(databaseFileName) :
getFile(String.join("/", ROOT_PATH, scenario, RULE_CONFIG_FILE));
}
/**
@@ -64,9 +67,13 @@ public final class ScenarioCommonPath {
}
private String getFile(final String fileName) {
- String path = String.join("/", ROOT_PATH, scenario, fileName);
- URL url =
Thread.currentThread().getContextClassLoader().getResource(path);
- assertNotNull(url, String.format("File `%s` must exist.", path));
+ URL url =
Thread.currentThread().getContextClassLoader().getResource(fileName);
+ assertNotNull(url, String.format("File `%s` must exist.", fileName));
return url.getFile();
}
+
+ private boolean exists(final String fileName) {
+ URL url =
Thread.currentThread().getContextClassLoader().getResource(fileName);
+ return null != url;
+ }
}