This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 f37370a11b7 Use SPI to handle DataSourceEnvironment (#36599)
f37370a11b7 is described below
commit f37370a11b7a42518157f014946acd254cb9783d
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Sep 17 14:31:00 2025 +0800
Use SPI to handle DataSourceEnvironment (#36599)
* Remove useless ProxyContainerConstants.AGENT_HOME_IN_CONTAINER
* Use SPI to handle DataSourceEnvironment
---
.../impl/ShardingSphereProxyClusterContainer.java | 13 ++-
.../impl/ShardingSphereProxyEmbeddedContainer.java | 8 +-
.../ShardingSphereProxyStandaloneContainer.java | 10 +-
.../StorageContainerConfigurationOption.java | 2 +
.../type/docker/DockerStorageContainer.java | 12 ++-
.../type/natived/NativeStorageContainer.java | 10 +-
.../atomic/util/StorageContainerUtils.java | 5 +-
.../e2e/env/runtime/DataSourceEnvironment.java | 109 ---------------------
.../runtime/datasource/DataSourceEnvironment.java | 55 +++++++++++
.../dialect/HiveDataSourceEnvironment.java | 46 +++++++++
.../dialect/MariaDBDataSourceEnvironment.java | 50 ++++++++++
.../dialect/MySQLDataSourceEnvironment.java | 51 ++++++++++
.../dialect/OpenGaussDataSourceEnvironment.java | 46 +++++++++
.../dialect/PostgreSQLDataSourceEnvironment.java | 46 +++++++++
...2e.env.runtime.datasource.DataSourceEnvironment | 22 +++++
.../pipeline/cases/PipelineContainerComposer.java | 8 +-
.../compose/PipelineDockerContainerComposer.java | 4 +-
.../compose/PipelineNativeContainerComposer.java | 12 ++-
.../engine/base/TransactionBaseE2EIT.java | 21 ++--
19 files changed, 379 insertions(+), 151 deletions(-)
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyClusterContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyClusterContainer.java
index 9c6e7b610e7..ff82a568be1 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyClusterContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyClusterContainer.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.test.e2e.env.container.atomic.adapter.impl;
import com.google.common.base.Strings;
import lombok.Setter;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.DockerITContainer;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.adapter.AdapterContainer;
@@ -26,7 +27,7 @@ import
org.apache.shardingsphere.test.e2e.env.container.atomic.adapter.config.Ad
import
org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyContainerConstants;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtils;
import
org.apache.shardingsphere.test.e2e.env.container.wait.JdbcConnectionWaitStrategy;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import javax.sql.DataSource;
import java.sql.DriverManager;
@@ -65,8 +66,9 @@ public final class ShardingSphereProxyClusterContainer
extends DockerITContainer
}
addEnv("TZ", "UTC");
mapResources(config.getMountedResources());
- setWaitStrategy(new JdbcConnectionWaitStrategy(() ->
DriverManager.getConnection(DataSourceEnvironment.getURL(databaseType,
- getHost(), getMappedPort(3307),
config.getProxyDataSourceName()), ProxyContainerConstants.USERNAME,
ProxyContainerConstants.PASSWORD)));
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
+ setWaitStrategy(new JdbcConnectionWaitStrategy(() ->
DriverManager.getConnection(
+ dataSourceEnvironment.getURL(getHost(), getMappedPort(3307),
config.getProxyDataSourceName()), ProxyContainerConstants.USERNAME,
ProxyContainerConstants.PASSWORD)));
withStartupTimeout(Duration.of(120L, ChronoUnit.SECONDS));
}
@@ -74,8 +76,9 @@ public final class ShardingSphereProxyClusterContainer
extends DockerITContainer
public DataSource getTargetDataSource(final String serverLists) {
DataSource dataSource = targetDataSourceProvider.get();
if (null == dataSource) {
-
targetDataSourceProvider.set(StorageContainerUtils.generateDataSource(DataSourceEnvironment.getURL(databaseType,
getHost(), getMappedPort(3307), config.getProxyDataSourceName()),
- ProxyContainerConstants.USERNAME,
ProxyContainerConstants.PASSWORD));
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
+
targetDataSourceProvider.set(StorageContainerUtils.generateDataSource(
+ dataSourceEnvironment.getURL(getHost(),
getMappedPort(3307), config.getProxyDataSourceName()),
ProxyContainerConstants.USERNAME, ProxyContainerConstants.PASSWORD));
}
return targetDataSourceProvider.get();
}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyEmbeddedContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyEmbeddedContainer.java
index e4ee32ca605..98bf3099245 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyEmbeddedContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyEmbeddedContainer.java
@@ -22,6 +22,7 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SystemUtils;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.proxy.backend.config.ProxyConfigurationLoader;
@@ -38,8 +39,8 @@ import
org.apache.shardingsphere.test.e2e.env.container.atomic.constants.Storage
import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.type.natived.NativeStorageContainer;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtils;
import
org.apache.shardingsphere.test.e2e.env.container.wait.JdbcConnectionWaitStrategy;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
import org.apache.shardingsphere.test.e2e.env.runtime.E2ETestEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.lifecycle.Startable;
import org.testcontainers.utility.Base58;
@@ -93,8 +94,9 @@ public final class ShardingSphereProxyEmbeddedContainer
implements AdapterContai
public DataSource getTargetDataSource(final String serverLists) {
DataSource dataSource = targetDataSourceProvider.get();
if (null == dataSource) {
-
targetDataSourceProvider.set(StorageContainerUtils.generateDataSource(DataSourceEnvironment.getURL(databaseType,
"127.0.0.1", 3307, config.getProxyDataSourceName()),
- ProxyContainerConstants.USERNAME,
ProxyContainerConstants.PASSWORD));
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
+
targetDataSourceProvider.set(StorageContainerUtils.generateDataSource(dataSourceEnvironment.getURL(
+ "127.0.0.1", 3307, config.getProxyDataSourceName()),
ProxyContainerConstants.USERNAME, ProxyContainerConstants.PASSWORD));
}
return targetDataSourceProvider.get();
}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyStandaloneContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyStandaloneContainer.java
index 08e72f8d5dd..51effec997e 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyStandaloneContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyStandaloneContainer.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.test.e2e.env.container.atomic.adapter.impl;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.DockerITContainer;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.adapter.AdapterContainer;
@@ -24,7 +25,7 @@ import
org.apache.shardingsphere.test.e2e.env.container.atomic.adapter.config.Ad
import
org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyContainerConstants;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtils;
import
org.apache.shardingsphere.test.e2e.env.container.wait.JdbcConnectionWaitStrategy;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import javax.sql.DataSource;
import java.sql.DriverManager;
@@ -52,15 +53,16 @@ public final class ShardingSphereProxyStandaloneContainer
extends DockerITContai
withExposedPorts(3307, 3308);
mapResources(config.getMountedResources());
setWaitStrategy(new JdbcConnectionWaitStrategy(() ->
DriverManager.getConnection(
- DataSourceEnvironment.getURL(databaseType, getHost(),
getMappedPort(3307), config.getProxyDataSourceName()), "proxy", "Proxy@123")));
+ DatabaseTypedSPILoader.getService(DataSourceEnvironment.class,
databaseType).getURL(getHost(), getMappedPort(3307),
config.getProxyDataSourceName()), "proxy", "Proxy@123")));
}
@Override
public DataSource getTargetDataSource(final String serverLists) {
DataSource dataSource = targetDataSourceProvider.get();
if (null == dataSource) {
-
targetDataSourceProvider.set(StorageContainerUtils.generateDataSource(DataSourceEnvironment.getURL(databaseType,
getHost(), getMappedPort(3307), config.getProxyDataSourceName()),
- ProxyContainerConstants.USERNAME,
ProxyContainerConstants.PASSWORD));
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
+
targetDataSourceProvider.set(StorageContainerUtils.generateDataSource(
+ dataSourceEnvironment.getURL(getHost(),
getMappedPort(3307), config.getProxyDataSourceName()),
ProxyContainerConstants.USERNAME, ProxyContainerConstants.PASSWORD));
}
return targetDataSourceProvider.get();
}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/option/StorageContainerConfigurationOption.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/option/StorageContainerConfigurationOption.java
index be248ea6ea3..cfdc238b278 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/option/StorageContainerConfigurationOption.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/option/StorageContainerConfigurationOption.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.test.e2e.env.container.atomic.storage.option;
import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPI;
+import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import java.util.Collection;
import java.util.List;
@@ -27,6 +28,7 @@ import java.util.Optional;
/**
* Storage container configuration option.
*/
+@SingletonSPI
public interface StorageContainerConfigurationOption extends DatabaseTypedSPI {
/**
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/type/docker/DockerStorageContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/type/docker/DockerStorageContainer.java
index 9293c5b4134..8c063230f75 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/type/docker/DockerStorageContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/type/docker/DockerStorageContainer.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.type.doc
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.Getter;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.DockerITContainer;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.constants.StorageContainerConstants;
@@ -30,7 +31,7 @@ import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.option.St
import
org.apache.shardingsphere.test.e2e.env.container.atomic.util.DockerImageVersion;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtils;
import
org.apache.shardingsphere.test.e2e.env.container.wait.JdbcConnectionWaitStrategy;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import
org.apache.shardingsphere.test.e2e.env.runtime.scenario.database.DatabaseEnvironmentManager;
import
org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type;
@@ -106,9 +107,10 @@ public class DockerStorageContainer extends
DockerITContainer implements Storage
}
private String getURL() {
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class,
option.getType());
return option.getDefaultDatabaseName(majorVersion)
- .map(optional ->
DataSourceEnvironment.getURL(option.getType(), "localhost",
getFirstMappedPort(), optional))
- .orElseGet(() ->
DataSourceEnvironment.getURL(option.getType(), "localhost",
getFirstMappedPort()));
+ .map(optional -> dataSourceEnvironment.getURL("localhost",
getFirstMappedPort(), optional))
+ .orElseGet(() -> dataSourceEnvironment.getURL("localhost",
getFirstMappedPort()));
}
@Override
@@ -146,8 +148,8 @@ public class DockerStorageContainer extends
DockerITContainer implements Storage
* @return JDBC URL
*/
public final String getJdbcUrl(final String dataSourceName) {
- return DataSourceEnvironment.getURL(
- option.getType(), getHost(), getMappedPort(),
Strings.isNullOrEmpty(dataSourceName) ?
option.getDefaultDatabaseName(majorVersion).orElse("") : dataSourceName);
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class,
option.getType());
+ return dataSourceEnvironment.getURL(getHost(), getMappedPort(),
Strings.isNullOrEmpty(dataSourceName) ?
option.getDefaultDatabaseName(majorVersion).orElse("") : dataSourceName);
}
/**
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/type/natived/NativeStorageContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/type/natived/NativeStorageContainer.java
index 0a1b46e6cb2..ac86b7570d3 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/type/natived/NativeStorageContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/storage/type/natived/NativeStorageContainer.java
@@ -27,8 +27,8 @@ import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.mount.Mou
import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.option.StorageContainerConfigurationOption;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.util.SQLScriptUtils;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtils;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
import org.apache.shardingsphere.test.e2e.env.runtime.E2ETestEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import
org.apache.shardingsphere.test.e2e.env.runtime.scenario.database.DatabaseEnvironmentManager;
import
org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type;
@@ -75,9 +75,10 @@ public final class NativeStorageContainer implements
StorageContainer {
}
private void initDatabase() {
- DataSource dataSource = StorageContainerUtils.generateDataSource(
- DataSourceEnvironment.getURL(databaseType,
env.getNativeStorageHost(), env.getNativeStoragePort()),
env.getNativeStorageUsername(), env.getNativeStoragePassword());
if (null != option) {
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
+ DataSource dataSource = StorageContainerUtils.generateDataSource(
+ dataSourceEnvironment.getURL(env.getNativeStorageHost(),
env.getNativeStoragePort()), env.getNativeStorageUsername(),
env.getNativeStoragePassword());
new MountSQLResourceGenerator(option).generate(0,
scenario).keySet().forEach(each -> SQLScriptUtils.execute(dataSource, each));
}
}
@@ -91,9 +92,10 @@ public final class NativeStorageContainer implements
StorageContainer {
private Map<String, DataSource> getDataSourceMap(final Collection<String>
databaseNames) {
Map<String, DataSource> result = new HashMap<>(databaseNames.size(),
1F);
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
for (String each : databaseNames) {
DataSource dataSource = StorageContainerUtils.generateDataSource(
- DataSourceEnvironment.getURL(databaseType,
env.getNativeStorageHost(), env.getNativeStoragePort(), each),
env.getNativeStorageUsername(), env.getNativeStoragePassword());
+ dataSourceEnvironment.getURL(env.getNativeStorageHost(),
env.getNativeStoragePort(), each), env.getNativeStorageUsername(),
env.getNativeStoragePassword());
result.put(each, dataSource);
}
return result;
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/util/StorageContainerUtils.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/util/StorageContainerUtils.java
index 550a438bb86..6b1bbbeb8e9 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/util/StorageContainerUtils.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/util/StorageContainerUtils.java
@@ -20,8 +20,9 @@ package
org.apache.shardingsphere.test.e2e.env.container.atomic.util;
import com.zaxxer.hikari.HikariDataSource;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import
org.apache.shardingsphere.database.connector.core.type.DatabaseTypeFactory;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import javax.sql.DataSource;
@@ -53,7 +54,7 @@ public final class StorageContainerUtils {
* @return data source
*/
public static DataSource generateDataSource(final String jdbcUrl, final
String username, final String password, final int maximumPoolSize) {
- String driverClassName =
DataSourceEnvironment.getDriverClassName(DatabaseTypeFactory.get(jdbcUrl));
+ String driverClassName =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class,
DatabaseTypeFactory.get(jdbcUrl)).getDriverClassName();
return generateDataSource(jdbcUrl, username, password,
maximumPoolSize, driverClassName);
}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/DataSourceEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/DataSourceEnvironment.java
deleted file mode 100644
index d2117320247..00000000000
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/DataSourceEnvironment.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.test.e2e.env.runtime;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-
-/**
- * Data source environment.
- */
-public final class DataSourceEnvironment {
-
- /**
- * Get driver class name.
- *
- * @param databaseType database type
- * @return driver class name
- * @throws UnsupportedOperationException unsupported operation exception
- */
- public static String getDriverClassName(final DatabaseType databaseType) {
- switch (databaseType.getType()) {
- case "MySQL":
- return "com.mysql.cj.jdbc.Driver";
- case "MariaDB":
- return "org.mariadb.jdbc.Driver";
- case "PostgreSQL":
- return "org.postgresql.Driver";
- case "openGauss":
- return "org.opengauss.Driver";
- case "Hive":
- return "org.apache.hive.jdbc.HiveDriver";
- default:
- throw new
UnsupportedOperationException(databaseType.getType());
- }
- }
-
- /**
- * Get URL.
- *
- * @param databaseType database type
- * @param host database host
- * @param port database port
- * @return URL
- * @throws UnsupportedOperationException unsupported operation exception
- */
- public static String getURL(final DatabaseType databaseType, final String
host, final int port) {
- switch (databaseType.getType()) {
- case "MySQL":
- return
String.format("jdbc:mysql://%s:%s?useSSL=true&requireSSL=true&enabledTLSProtocols=TLSv1.2,TLSv1.3&verifyServerCertificate=false"
- +
"&useServerPrepStmts=true&useLocalSessionState=true&characterEncoding=utf-8&allowMultiQueries=true&rewriteBatchedStatements=true",
host, port);
- case "MariaDB":
- return
String.format("jdbc:mysql://%s:%s?useSSL=false&useServerPrepStmts=true&useLocalSessionState=true&characterEncoding=utf-8&allowMultiQueries=true&rewriteBatchedStatements=true",
- host, port);
- case "PostgreSQL":
- return
String.format("jdbc:postgresql://%s:%s/?ssl=on&sslmode=prefer", host, port);
- case "openGauss":
- return String.format("jdbc:opengauss://%s:%s/", host, port);
- case "Hive":
- return String.format("jdbc:hive2://%s:%s/", host, port);
- default:
- throw new
UnsupportedOperationException(databaseType.getType());
- }
- }
-
- /**
- * Get URL.
- *
- * @param databaseType database type
- * @param host database host
- * @param port database port
- * @param dataSourceName data source name
- * @return URL
- * @throws UnsupportedOperationException unsupported operation exception
- */
- public static String getURL(final DatabaseType databaseType, final String
host, final int port, final String dataSourceName) {
- switch (databaseType.getType()) {
- case "MySQL":
- return String.format(
-
"jdbc:mysql://%s:%s/%s?useSSL=true&requireSSL=true&enabledTLSProtocols=TLSv1.2,TLSv1.3&verifyServerCertificate=false"
- +
"&useServerPrepStmts=true&useLocalSessionState=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true",
- host, port, dataSourceName);
- case "MariaDB":
- return
String.format("jdbc:mysql://%s:%s/%s?useSSL=false&useServerPrepStmts=true&useLocalSessionState=true&characterEncoding=utf-8&allowMultiQueries=true"
- + "&rewriteBatchedStatements=true", host, port,
dataSourceName);
- case "PostgreSQL":
- return
String.format("jdbc:postgresql://%s:%s/%s?ssl=on&sslmode=prefer", host, port,
dataSourceName);
- case "openGauss":
- return
String.format("jdbc:opengauss://%s:%s/%s?batchMode=OFF", host, port,
dataSourceName);
- case "Hive":
- return
String.format("jdbc:hive2://%s:%s/%s?ssl=false&useUnicode=true&characterEncoding=utf-8",
host, port, dataSourceName);
- default:
- throw new
UnsupportedOperationException(databaseType.getType());
- }
- }
-}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/DataSourceEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/DataSourceEnvironment.java
new file mode 100644
index 00000000000..61f8d37d6c6
--- /dev/null
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/DataSourceEnvironment.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.env.runtime.datasource;
+
+import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPI;
+import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
+
+/**
+ * Data source environment.
+ */
+@SingletonSPI
+public interface DataSourceEnvironment extends DatabaseTypedSPI {
+
+ /**
+ * Get driver class name.
+ *
+ * @return driver class name
+ * @throws UnsupportedOperationException unsupported operation exception
+ */
+ String getDriverClassName();
+
+ /**
+ * Get URL.
+ *
+ * @param host database host
+ * @param port database port
+ * @return URL
+ */
+ String getURL(String host, int port);
+
+ /**
+ * Get URL.
+ *
+ * @param host database host
+ * @param port database port
+ * @param dataSourceName data source name
+ * @return URL
+ */
+ String getURL(String host, int port, String dataSourceName);
+}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/HiveDataSourceEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/HiveDataSourceEnvironment.java
new file mode 100644
index 00000000000..f9dfb02a5c7
--- /dev/null
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/HiveDataSourceEnvironment.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect;
+
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
+
+/**
+ * Data source environment for Hive.
+ */
+public final class HiveDataSourceEnvironment implements DataSourceEnvironment {
+
+ @Override
+ public String getDriverClassName() {
+ return "org.apache.hive.jdbc.HiveDriver";
+ }
+
+ @Override
+ public String getURL(final String host, final int port) {
+ return String.format("jdbc:hive2://%s:%s/", host, port);
+ }
+
+ @Override
+ public String getURL(final String host, final int port, final String
dataSourceName) {
+ return
String.format("jdbc:hive2://%s:%s/%s?ssl=false&useUnicode=true&characterEncoding=utf-8",
host, port, dataSourceName);
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "Hive";
+ }
+}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/MariaDBDataSourceEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/MariaDBDataSourceEnvironment.java
new file mode 100644
index 00000000000..b2aca9d8751
--- /dev/null
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/MariaDBDataSourceEnvironment.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect;
+
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
+
+/**
+ * Data source environment for MariaDB.
+ */
+public final class MariaDBDataSourceEnvironment implements
DataSourceEnvironment {
+
+ @Override
+ public String getDriverClassName() {
+ return "org.mariadb.jdbc.Driver";
+ }
+
+ @Override
+ public String getURL(final String host, final int port) {
+ return String.format("jdbc:mysql://%s:%s?%s", host, port,
getQueryProperties());
+ }
+
+ @Override
+ public String getURL(final String host, final int port, final String
dataSourceName) {
+ return String.format("jdbc:mysql://%s:%s/%s?%s", host, port,
dataSourceName, getQueryProperties());
+ }
+
+ private String getQueryProperties() {
+ return
"useSSL=false&useServerPrepStmts=true&useLocalSessionState=true&characterEncoding=utf-8&allowMultiQueries=true&rewriteBatchedStatements=true";
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "MariaDB";
+ }
+}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/MySQLDataSourceEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/MySQLDataSourceEnvironment.java
new file mode 100644
index 00000000000..e4a4c00fd3d
--- /dev/null
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/MySQLDataSourceEnvironment.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect;
+
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
+
+/**
+ * Data source environment for MySQL.
+ */
+public final class MySQLDataSourceEnvironment implements DataSourceEnvironment
{
+
+ @Override
+ public String getDriverClassName() {
+ return "com.mysql.cj.jdbc.Driver";
+ }
+
+ @Override
+ public String getURL(final String host, final int port) {
+ return String.format("jdbc:mysql://%s:%s?%s", host, port,
getQueryProperties());
+ }
+
+ @Override
+ public String getURL(final String host, final int port, final String
dataSourceName) {
+ return String.format("jdbc:mysql://%s:%s/%s?%s", host, port,
dataSourceName, getQueryProperties());
+ }
+
+ private String getQueryProperties() {
+ return
"useSSL=true&requireSSL=true&enabledTLSProtocols=TLSv1.2,TLSv1.3&verifyServerCertificate=false"
+ +
"&useServerPrepStmts=true&useLocalSessionState=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true";
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "MySQL";
+ }
+}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/OpenGaussDataSourceEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/OpenGaussDataSourceEnvironment.java
new file mode 100644
index 00000000000..ccada15dc66
--- /dev/null
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/OpenGaussDataSourceEnvironment.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect;
+
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
+
+/**
+ * Data source environment for openGauss.
+ */
+public final class OpenGaussDataSourceEnvironment implements
DataSourceEnvironment {
+
+ @Override
+ public String getDriverClassName() {
+ return "org.opengauss.Driver";
+ }
+
+ @Override
+ public String getURL(final String host, final int port) {
+ return String.format("jdbc:opengauss://%s:%s/", host, port);
+ }
+
+ @Override
+ public String getURL(final String host, final int port, final String
dataSourceName) {
+ return String.format("jdbc:opengauss://%s:%s/%s?batchMode=OFF", host,
port, dataSourceName);
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "openGauss";
+ }
+}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/PostgreSQLDataSourceEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/PostgreSQLDataSourceEnvironment.java
new file mode 100644
index 00000000000..6b5ecf76150
--- /dev/null
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/datasource/dialect/PostgreSQLDataSourceEnvironment.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect;
+
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
+
+/**
+ * Data source environment for PostgreSQL.
+ */
+public final class PostgreSQLDataSourceEnvironment implements
DataSourceEnvironment {
+
+ @Override
+ public String getDriverClassName() {
+ return "org.postgresql.Driver";
+ }
+
+ @Override
+ public String getURL(final String host, final int port) {
+ return String.format("jdbc:postgresql://%s:%s/?ssl=on&sslmode=prefer",
host, port);
+ }
+
+ @Override
+ public String getURL(final String host, final int port, final String
dataSourceName) {
+ return
String.format("jdbc:postgresql://%s:%s/%s?ssl=on&sslmode=prefer", host, port,
dataSourceName);
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "PostgreSQL";
+ }
+}
diff --git
a/test/e2e/env/src/test/resources/META-INF/services/org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment
b/test/e2e/env/src/test/resources/META-INF/services/org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment
new file mode 100644
index 00000000000..5b253bc8d61
--- /dev/null
+++
b/test/e2e/env/src/test/resources/META-INF/services/org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect.MySQLDataSourceEnvironment
+org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect.PostgreSQLDataSourceEnvironment
+org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect.MariaDBDataSourceEnvironment
+org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect.OpenGaussDataSourceEnvironment
+org.apache.shardingsphere.test.e2e.env.runtime.datasource.dialect.HiveDataSourceEnvironment
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/PipelineContainerComposer.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/PipelineContainerComposer.java
index ddaa7b69bd4..627e681f133 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/PipelineContainerComposer.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/PipelineContainerComposer.java
@@ -28,6 +28,7 @@ import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourc
import org.apache.shardingsphere.data.pipeline.core.job.JobStatus;
import org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType;
import
org.apache.shardingsphere.database.connector.core.jdbcurl.appender.JdbcUrlAppender;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import
org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry;
import
org.apache.shardingsphere.database.connector.mysql.type.MySQLDatabaseType;
@@ -44,7 +45,7 @@ import
org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyCo
import
org.apache.shardingsphere.test.e2e.env.container.atomic.constants.StorageContainerConstants;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.type.docker.DockerStorageContainer;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtils;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.command.ExtraSQLCommand;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.env.PipelineE2EEnvironment;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.env.enums.PipelineEnvTypeEnum;
@@ -278,13 +279,14 @@ public final class PipelineContainerComposer implements
AutoCloseable {
* @return actual JDBC URL template
*/
public String getActualJdbcUrlTemplate(final String databaseName, final
boolean isInContainer, final int storageContainerIndex) {
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
if (PipelineEnvTypeEnum.DOCKER ==
PipelineE2EEnvironment.getInstance().getItEnvType()) {
DockerStorageContainer storageContainer =
((PipelineDockerContainerComposer)
containerComposer).getStorageContainers().get(storageContainerIndex);
return isInContainer
- ? DataSourceEnvironment.getURL(databaseType,
storageContainer.getNetworkAliases().get(0), storageContainer.getExposedPort(),
databaseName)
+ ?
dataSourceEnvironment.getURL(storageContainer.getNetworkAliases().get(0),
storageContainer.getExposedPort(), databaseName)
: storageContainer.getJdbcUrl(databaseName);
}
- return DataSourceEnvironment.getURL(databaseType, "127.0.0.1",
PipelineE2EEnvironment.getInstance().getActualDatabasePort(databaseType),
databaseName);
+ return dataSourceEnvironment.getURL("127.0.0.1",
PipelineE2EEnvironment.getInstance().getActualDatabasePort(databaseType),
databaseName);
}
/**
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/framework/container/compose/PipelineDockerContainerComposer.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/framework/container/compose/PipelineDockerContainerComposer.java
index 44f5cf71806..9c441b9c89b 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/framework/container/compose/PipelineDockerContainerComposer.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/framework/container/compose/PipelineDockerContainerComposer.java
@@ -30,7 +30,7 @@ import
org.apache.shardingsphere.test.e2e.env.container.atomic.governance.impl.Z
import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.StorageContainerFactory;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.option.StorageContainerConfigurationOption;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.type.docker.DockerStorageContainer;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.env.PipelineE2EEnvironment;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.env.enums.PipelineProxyTypeEnum;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.framework.container.config.proxy.PipelineProxyContainerConfigurationFactory;
@@ -91,7 +91,7 @@ public final class PipelineDockerContainerComposer extends
PipelineBaseContainer
port = proxyContainer.getFirstMappedPort();
}
DatabaseType databaseType =
"Oracle".equals(this.databaseType.getType()) ?
TypedSPILoader.getService(DatabaseType.class, "MySQL") : this.databaseType;
- return DataSourceEnvironment.getURL(databaseType, host, port,
databaseName);
+ return DatabaseTypedSPILoader.getService(DataSourceEnvironment.class,
databaseType).getURL(host, port, databaseName);
}
@Override
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/framework/container/compose/PipelineNativeContainerComposer.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/framework/container/compose/PipelineNativeContainerComposer.java
index 0cbc07c637b..dd6d24c4b30 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/framework/container/compose/PipelineNativeContainerComposer.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/framework/container/compose/PipelineNativeContainerComposer.java
@@ -19,11 +19,12 @@ package
org.apache.shardingsphere.test.e2e.operation.pipeline.framework.containe
import lombok.SneakyThrows;
import
org.apache.shardingsphere.database.connector.core.jdbcurl.appender.JdbcUrlAppender;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.env.PipelineE2EEnvironment;
import java.sql.Connection;
@@ -54,12 +55,13 @@ public final class PipelineNativeContainerComposer extends
PipelineBaseContainer
int actualDatabasePort = ENV.getActualDatabasePort(databaseType);
String username = ENV.getActualDataSourceUsername(databaseType);
String password = ENV.getActualDataSourcePassword(databaseType);
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
String jdbcUrl;
switch (databaseType.getType()) {
case "MySQL":
case "MariaDB":
String queryAllTables = String.format("select table_name from
information_schema.tables where table_schema='%s' and table_type='BASE TABLE'",
databaseName);
- jdbcUrl = DataSourceEnvironment.getURL(databaseType,
"localhost", actualDatabasePort, databaseName);
+ jdbcUrl = dataSourceEnvironment.getURL("localhost",
actualDatabasePort, databaseName);
try (
Connection connection = DriverManager.getConnection(
jdbcUrlAppender.appendQueryProperties(jdbcUrl,
PropertiesBuilder.build(new Property("allowPublicKeyRetrieval",
Boolean.TRUE.toString()))), username, password)) {
@@ -73,7 +75,7 @@ public final class PipelineNativeContainerComposer extends
PipelineBaseContainer
break;
case "openGauss":
case "PostgreSQL":
- jdbcUrl = DataSourceEnvironment.getURL(databaseType,
"localhost", actualDatabasePort, databaseName);
+ jdbcUrl = dataSourceEnvironment.getURL("localhost",
actualDatabasePort, databaseName);
try (Connection connection =
DriverManager.getConnection(jdbcUrl, username, password)) {
dropTableWithSchema(connection, "public");
dropTableWithSchema(connection, "test");
@@ -81,7 +83,7 @@ public final class PipelineNativeContainerComposer extends
PipelineBaseContainer
}
break;
case "Oracle":
- jdbcUrl = DataSourceEnvironment.getURL(databaseType,
"localhost", actualDatabasePort, "");
+ jdbcUrl = dataSourceEnvironment.getURL("localhost",
actualDatabasePort, "");
try (Connection connection =
DriverManager.getConnection(jdbcUrl, username, password)) {
dropTableWithOracle(connection, databaseName);
}
@@ -121,7 +123,7 @@ public final class PipelineNativeContainerComposer extends
PipelineBaseContainer
@Override
public String getProxyJdbcUrl(final String databaseName) {
DatabaseType databaseType =
"Oracle".equals(this.databaseType.getType()) ?
TypedSPILoader.getService(DatabaseType.class, "MySQL") : this.databaseType;
- return DataSourceEnvironment.getURL(databaseType, "localhost", 3307,
databaseName);
+ return DatabaseTypedSPILoader.getService(DataSourceEnvironment.class,
databaseType).getURL("localhost", 3307, databaseName);
}
@Override
diff --git
a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/engine/base/TransactionBaseE2EIT.java
b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/engine/base/TransactionBaseE2EIT.java
index c24fb62f7b1..665dad833ff 100644
---
a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/engine/base/TransactionBaseE2EIT.java
+++
b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/engine/base/TransactionBaseE2EIT.java
@@ -21,11 +21,12 @@ import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType;
import
org.apache.shardingsphere.test.e2e.env.container.atomic.storage.type.docker.DockerStorageContainer;
-import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
import
org.apache.shardingsphere.test.e2e.operation.transaction.cases.base.BaseTransactionTestCase;
import
org.apache.shardingsphere.test.e2e.operation.transaction.cases.base.BaseTransactionTestCase.TransactionTestCaseParameter;
import
org.apache.shardingsphere.test.e2e.operation.transaction.engine.command.CommonSQLCommand;
@@ -275,12 +276,12 @@ public abstract class TransactionBaseE2EIT {
}
private String getActualJdbcUrlTemplate(final String databaseName, final
TransactionContainerComposer containerComposer) {
+ DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class,
containerComposer.getDatabaseType());
if (ENV.getItEnvType() == TransactionE2EEnvTypeEnum.DOCKER) {
DockerStorageContainer storageContainer = (DockerStorageContainer)
((TransactionDockerContainerComposer)
containerComposer.getContainerComposer()).getStorageContainer();
- return
DataSourceEnvironment.getURL(containerComposer.getDatabaseType(),
-
containerComposer.getDatabaseType().getType().toLowerCase() + ".host",
storageContainer.getExposedPort(), databaseName);
+ return
dataSourceEnvironment.getURL(containerComposer.getDatabaseType().getType().toLowerCase()
+ ".host", storageContainer.getExposedPort(), databaseName);
}
- return
DataSourceEnvironment.getURL(containerComposer.getDatabaseType(), "127.0.0.1",
ENV.getActualDataSourceDefaultPort(containerComposer.getDatabaseType()),
databaseName);
+ return dataSourceEnvironment.getURL("127.0.0.1",
ENV.getActualDataSourceDefaultPort(containerComposer.getDatabaseType()),
databaseName);
}
/**
@@ -297,8 +298,10 @@ public abstract class TransactionBaseE2EIT {
}
private void executeWithLog(final Connection connection, final String sql)
throws SQLException {
- log.info("Connection execute:{}.", sql);
- connection.createStatement().execute(sql);
+ log.info("Connection execute: {}.", sql);
+ try (Statement statement = connection.createStatement()) {
+ statement.execute(sql);
+ }
Awaitility.await().pollDelay(1L, TimeUnit.SECONDS).until(() -> true);
}
@@ -306,9 +309,9 @@ public abstract class TransactionBaseE2EIT {
try (Connection connection =
containerComposer.getDataSource().getConnection()) {
int retryNumber = 0;
while (retryNumber <= 3) {
- try {
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(sql);
+ try (
+ Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(sql)) {
int result = 0;
while (resultSet.next()) {
result++;