This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 7ce4229eb01 Refactor DockerStorageContainer.createAccessDataSource()
(#19500)
7ce4229eb01 is described below
commit 7ce4229eb013e2720620d6f5c31b40a899e2a41e
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 24 14:39:09 2022 +0800
Refactor DockerStorageContainer.createAccessDataSource() (#19500)
* Refactor DockerStorageContainer.createAccessDataSource()
* Refactor DockerStorageContainer.createAccessDataSource()
---
.../atomic/storage/DockerStorageContainer.java | 22 +++++++++-------------
.../cases/general/CreateTableSQLGeneratorIT.java | 18 ++----------------
2 files changed, 11 insertions(+), 29 deletions(-)
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/DockerStorageContainer.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/DockerStorageContainer.java
index b6049861121..15ee6dea784 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/DockerStorageContainer.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/DockerStorageContainer.java
@@ -82,12 +82,18 @@ public abstract class DockerStorageContainer extends
DockerITContainer implement
@SneakyThrows({IOException.class, JAXBException.class})
protected void postStart() {
if (!Strings.isNullOrEmpty(scenario)) {
- DatabaseEnvironmentManager.getDatabaseNames(scenario).forEach(each
-> actualDataSourceMap.put(each, createDataSource(each)));
-
DatabaseEnvironmentManager.getExpectedDatabaseNames(scenario).forEach(each ->
expectedDataSourceMap.put(each, createDataSource(each)));
+ DatabaseEnvironmentManager.getDatabaseNames(scenario).forEach(each
-> actualDataSourceMap.put(each, createAccessDataSource(each)));
+
DatabaseEnvironmentManager.getExpectedDatabaseNames(scenario).forEach(each ->
expectedDataSourceMap.put(each, createAccessDataSource(each)));
}
}
- private DataSource createDataSource(final String dataSourceName) {
+ /**
+ * Create access data source.
+ *
+ * @param dataSourceName data source name
+ * @return access data source
+ */
+ public DataSource createAccessDataSource(final String dataSourceName) {
HikariDataSource result = new HikariDataSource();
result.setDriverClassName(DataSourceEnvironment.getDriverClassName(databaseType));
result.setJdbcUrl(DataSourceEnvironment.getURL(databaseType,
getHost(), getMappedPort(getPort()), dataSourceName));
@@ -98,16 +104,6 @@ public abstract class DockerStorageContainer extends
DockerITContainer implement
return result;
}
- /**
- * Get JDBC URL.
- *
- * @param databaseName database name
- * @return JDBC URL
- */
- public final String getJdbcUrl(final String databaseName) {
- return DataSourceEnvironment.getURL(databaseType, getHost(),
getFirstMappedPort(), databaseName);
- }
-
/**
* Get root username.
*
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/CreateTableSQLGeneratorIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/CreateTableSQLGeneratorIT.java
index 39bbbb6897c..ce3f86cff4a 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/CreateTableSQLGeneratorIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/CreateTableSQLGeneratorIT.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.integration.data.pipeline.cases.general;
-import com.zaxxer.hikari.HikariDataSource;
import
org.apache.shardingsphere.data.pipeline.spi.ddlgenerator.CreateTableSQLGeneratorFactory;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
@@ -31,7 +30,6 @@ import
org.apache.shardingsphere.integration.data.pipeline.env.enums.ScalingITEn
import
org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.DockerStorageContainer;
import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.StorageContainerFactory;
-import
org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -106,7 +104,7 @@ public final class CreateTableSQLGeneratorIT {
@Test
public void assertGenerateCreateTableSQL() throws SQLException {
initData();
- DataSource dataSource = createDataSource(DEFAULT_DATABASE);
+ DataSource dataSource =
storageContainer.createAccessDataSource(DEFAULT_DATABASE);
try (
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
@@ -121,19 +119,7 @@ public final class CreateTableSQLGeneratorIT {
}
private void initData() throws SQLException {
- DataSource dataSource = createDataSource("");
- dataSource.getConnection().createStatement().execute("CREATE DATABASE
" + DEFAULT_DATABASE);
- }
-
- private DataSource createDataSource(final String databaseName) {
- HikariDataSource result = new HikariDataSource();
-
result.setDriverClassName(DataSourceEnvironment.getDriverClassName(storageContainer.getDatabaseType()));
- result.setJdbcUrl(storageContainer.getJdbcUrl(databaseName));
- result.setUsername(storageContainer.getTestCaseUsername());
- result.setPassword(storageContainer.getTestCasePassword());
- result.setMaximumPoolSize(2);
- result.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
- return result;
+
storageContainer.createAccessDataSource("").getConnection().createStatement().execute("CREATE
DATABASE " + DEFAULT_DATABASE);
}
private void assertIsCorrect(final Collection<String> actualSQL, final
Collection<String> expectedSQL) {