You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/02/12 23:52:19 UTC
[shardingsphere] branch master updated: Add DatabaseAssertionMetaData (#15385)
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 d123d60 Add DatabaseAssertionMetaData (#15385)
d123d60 is described below
commit d123d602afbc0a18c0f5ff325b3a8afc254016f4
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Feb 13 07:50:56 2022 +0800
Add DatabaseAssertionMetaData (#15385)
* Add DatabaseAssertionMetaData
* Remove BaseITCase.storageContainer
* For checkstyle
* Use actual data source instead of verification data source
* Use operation data source instead of verification data source
* Use operation data source instead of verification data source
* Remove useless code
* Remove useless code
* Remove useless code
* Refactor ComposedContainer
---
.../test/integration/engine/BaseITCase.java | 13 ++----
.../test/integration/engine/BatchITCase.java | 3 +-
.../test/integration/engine/dal/GeneralDALIT.java | 2 +-
.../test/integration/engine/dcl/GeneralDCLIT.java | 4 +-
.../test/integration/engine/ddl/BaseDDLIT.java | 15 +++----
.../test/integration/engine/ddl/GeneralDDLIT.java | 4 +-
.../integration/engine/dml/AdditionalDMLIT.java | 14 +++----
.../test/integration/engine/dml/BaseDMLIT.java | 15 ++++---
.../test/integration/engine/dml/BatchDMLIT.java | 4 +-
.../test/integration/engine/dml/GeneralDMLIT.java | 4 +-
.../integration/engine/dql/AdditionalDQLIT.java | 8 ++--
.../test/integration/engine/dql/GeneralDQLIT.java | 4 +-
.../test/integration/engine/ral/BaseRALIT.java | 4 +-
.../test/integration/engine/ral/GeneralRALIT.java | 6 +--
.../test/integration/engine/rdl/BaseRDLIT.java | 4 +-
.../test/integration/engine/rdl/GeneralRDLIT.java | 6 +--
.../test/integration/engine/rql/GeneralRQLIT.java | 2 +-
.../container/atomic/adapter/AdapterContainer.java | 14 ++-----
.../adapter/impl/ShardingSphereJDBCContainer.java | 23 +++--------
.../adapter/impl/ShardingSphereProxyContainer.java | 15 +++----
.../container/atomic/storage/StorageContainer.java | 11 -----
.../container/atomic/storage/impl/H2Container.java | 6 ---
.../atomic/storage/impl/MySQLContainer.java | 6 ---
.../atomic/storage/impl/PostgreSQLContainer.java | 19 ---------
.../container/compose/ComposedContainer.java | 21 ++++------
.../compose/mode/ClusterComposedContainer.java | 26 ++++--------
.../compose/mode/MemoryComposedContainer.java | 9 ++--
.../DatabaseAssertionMetaData.java} | 40 +++++-------------
.../database/DatabaseAssertionMetaDataFactory.java | 48 ++++++++++++++++++++++
.../impl/PostgreSQLDatabaseAssertionMetaData.java | 47 +++++++++++++++++++++
30 files changed, 186 insertions(+), 211 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
index fd60862..6b6190a 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataS
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCase;
-import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.StorageContainer;
import org.apache.shardingsphere.test.integration.framework.container.compose.ComposedContainer;
import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray;
import org.apache.shardingsphere.test.integration.framework.runner.ShardingSphereIntegrationTestParameterized;
@@ -56,13 +55,9 @@ public abstract class BaseITCase {
private final IntegrationTestCase integrationTestCase;
- private final StorageContainer storageContainer;
-
private final Map<String, DataSource> actualDataSourceMap;
- private final DataSource operationDataSource;
-
- private final DataSource verificationDataSource;
+ private final DataSource targetDataSource;
public BaseITCase(final ParameterizedArray parameterizedArray) {
adapter = parameterizedArray.getAdapter();
@@ -71,10 +66,8 @@ public abstract class BaseITCase {
databaseType = parameterizedArray.getDatabaseType();
sqlCommandType = parameterizedArray.getSqlCommandType();
integrationTestCase = parameterizedArray.getTestCaseContext().getTestCase();
- storageContainer = composedContainer.getStorageContainer();
- actualDataSourceMap = composedContainer.getStorageContainer().getActualDataSourceMap();
- operationDataSource = composedContainer.getOperationDataSource();
- verificationDataSource = composedContainer.getVerificationDataSource();
+ actualDataSourceMap = composedContainer.getActualDataSourceMap();
+ targetDataSource = composedContainer.getTargetDataSource();
}
@After
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchITCase.java
index 3d7c029..ae31e60 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchITCase.java
@@ -29,7 +29,6 @@ import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSet
import org.apache.shardingsphere.test.integration.cases.dataset.row.DataSetRow;
import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
-import org.apache.shardingsphere.test.integration.framework.container.compose.mode.ClusterComposedContainer;
import org.apache.shardingsphere.test.integration.framework.param.model.CaseParameterizedArray;
import org.junit.Before;
@@ -92,7 +91,7 @@ public abstract class BatchITCase extends BaseITCase {
DataSetMetaData expectedDataSetMetaData = expected.getMetaDataList().get(0);
for (String each : new InlineExpressionParser(expectedDataSetMetaData.getDataNodes()).splitAndEvaluate()) {
DataNode dataNode = new DataNode(each);
- DataSource dataSource = getComposedContainer() instanceof ClusterComposedContainer ? getVerificationDataSource() : getActualDataSourceMap().get(dataNode.getDataSourceName());
+ DataSource dataSource = getActualDataSourceMap().get(dataNode.getDataSourceName());
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(String.format("SELECT * FROM %s ORDER BY 1", dataNode.getTableName()))) {
assertDataSet(preparedStatement, expected.findRows(dataNode), expectedDataSetMetaData);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dal/GeneralDALIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dal/GeneralDALIT.java
index c61bb76..7866e7e 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dal/GeneralDALIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dal/GeneralDALIT.java
@@ -59,7 +59,7 @@ public final class GeneralDALIT extends BaseDALIT {
@Test
public void assertExecute() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
assertExecuteForStatement(connection);
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
index c61d2db..d4850b2 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
@@ -56,7 +56,7 @@ public final class GeneralDCLIT extends BaseDCLIT {
@Test
public void assertExecuteUpdate() throws SQLException, ParseException {
String sql = getSQL();
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
executeUpdateForStatement(connection, sql);
} else {
@@ -68,7 +68,7 @@ public final class GeneralDCLIT extends BaseDCLIT {
@Test
public void assertExecute() throws SQLException, ParseException {
String sql = getSQL();
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
executeForStatement(connection, sql);
} else {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
index d94d4a9..4b4b03f 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
@@ -25,11 +25,9 @@ import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSet
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetIndex;
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetMetaData;
import org.apache.shardingsphere.test.integration.engine.SingleITCase;
-import org.apache.shardingsphere.test.integration.framework.container.compose.mode.ClusterComposedContainer;
import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray;
import org.junit.Before;
-import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
@@ -56,14 +54,14 @@ public abstract class BaseDDLIT extends SingleITCase {
public final void init() throws Exception {
assertNotNull("Expected affected table is required", getAssertion().getInitialSQL());
assertNotNull("Init SQL is required", getAssertion().getInitialSQL().getAffectedTable());
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
executeInitSQLs(connection);
}
}
@Override
public final void tearDown() throws Exception {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
String dropSql = String.format("DROP TABLE %s", getAssertion().getInitialSQL().getAffectedTable());
executeUpdateForPrepareStatement(connection, dropSql);
} catch (final SQLException | NoSuchTableException ignored) {
@@ -98,8 +96,7 @@ public abstract class BaseDDLIT extends SingleITCase {
private void assertNotContainsTable(final Collection<DataNode> dataNodes) throws SQLException {
for (DataNode each : dataNodes) {
- try (Connection connection = getComposedContainer() instanceof ClusterComposedContainer
- ? getVerificationDataSource().getConnection() : getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) {
+ try (Connection connection = getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) {
assertNotContainsTable(connection, each.getTableName());
}
}
@@ -112,8 +109,7 @@ public abstract class BaseDDLIT extends SingleITCase {
private List<DataSetColumn> getActualColumns(final Collection<DataNode> dataNodes) throws SQLException {
Set<DataSetColumn> result = new LinkedHashSet<>();
for (DataNode each : dataNodes) {
- DataSource dataSource = getComposedContainer() instanceof ClusterComposedContainer ? getVerificationDataSource() : getActualDataSourceMap().get(each.getDataSourceName());
- try (Connection connection = dataSource.getConnection()) {
+ try (Connection connection = getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) {
result.addAll(getActualColumns(connection, each.getTableName()));
}
}
@@ -137,8 +133,7 @@ public abstract class BaseDDLIT extends SingleITCase {
private List<DataSetIndex> getActualIndexes(final Collection<DataNode> dataNodes) throws SQLException {
Set<DataSetIndex> result = new LinkedHashSet<>();
for (DataNode each : dataNodes) {
- DataSource dataSource = getComposedContainer() instanceof ClusterComposedContainer ? getVerificationDataSource() : getActualDataSourceMap().get(each.getDataSourceName());
- try (Connection connection = dataSource.getConnection()) {
+ try (Connection connection = getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) {
result.addAll(getActualIndexes(connection, each.getTableName()));
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java
index afa6b53..bbe9a4f 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java
@@ -58,7 +58,7 @@ public final class GeneralDDLIT extends BaseDDLIT {
@Test
public void assertExecuteUpdate() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
executeUpdateForStatement(connection);
} else {
@@ -82,7 +82,7 @@ public final class GeneralDDLIT extends BaseDDLIT {
@Test
public void assertExecute() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
executeForStatement(connection);
} else {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java
index bedcb8a..78499b9 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java
@@ -69,7 +69,7 @@ public final class AdditionalDMLIT extends BaseDMLIT {
return;
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType()
? executeUpdateForStatementWithAutoGeneratedKeys(connection) : executeUpdateForPreparedStatementWithAutoGeneratedKeys(connection);
}
@@ -98,7 +98,7 @@ public final class AdditionalDMLIT extends BaseDMLIT {
return;
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType() ? executeUpdateForStatementWithColumnIndexes(connection) : executeUpdateForPreparedStatementWithColumnIndexes(connection);
}
assertDataSet(actualUpdateCount);
@@ -126,7 +126,7 @@ public final class AdditionalDMLIT extends BaseDMLIT {
return;
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType() ? executeUpdateForStatementWithColumnNames(connection) : executeUpdateForPreparedStatementWithColumnNames(connection);
}
assertDataSet(actualUpdateCount);
@@ -154,7 +154,7 @@ public final class AdditionalDMLIT extends BaseDMLIT {
return;
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType()
? executeForStatementWithoutAutoGeneratedKeys(connection) : executeForPreparedStatementWithoutAutoGeneratedKeys(connection);
}
@@ -185,7 +185,7 @@ public final class AdditionalDMLIT extends BaseDMLIT {
return;
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType() ? executeForStatementWithAutoGeneratedKeys(connection) : executeForPreparedStatementWithAutoGeneratedKeys(connection);
}
assertDataSet(actualUpdateCount);
@@ -217,7 +217,7 @@ public final class AdditionalDMLIT extends BaseDMLIT {
return;
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType() ? executeForStatementWithColumnIndexes(connection) : executeForPreparedStatementWithColumnIndexes(connection);
}
assertDataSet(actualUpdateCount);
@@ -247,7 +247,7 @@ public final class AdditionalDMLIT extends BaseDMLIT {
return;
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType() ? executeForStatementWithColumnNames(connection) : executeForPreparedStatementWithColumnNames(connection);
}
assertDataSet(actualUpdateCount);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
index 8573f89..99653f9 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
@@ -25,7 +25,8 @@ import org.apache.shardingsphere.test.integration.cases.dataset.row.DataSetRow;
import org.apache.shardingsphere.test.integration.engine.SingleITCase;
import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
-import org.apache.shardingsphere.test.integration.framework.container.compose.mode.ClusterComposedContainer;
+import org.apache.shardingsphere.test.integration.framework.database.DatabaseAssertionMetaData;
+import org.apache.shardingsphere.test.integration.framework.database.DatabaseAssertionMetaDataFactory;
import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray;
import org.junit.Before;
@@ -70,8 +71,7 @@ public abstract class BaseDMLIT extends SingleITCase {
DataSetMetaData expectedDataSetMetaData = getDataSet().getMetaDataList().get(0);
for (String each : new InlineExpressionParser(expectedDataSetMetaData.getDataNodes()).splitAndEvaluate()) {
DataNode dataNode = new DataNode(each);
- DataSource dataSource = getComposedContainer() instanceof ClusterComposedContainer
- ? getVerificationDataSource() : getActualDataSourceMap().get(dataNode.getDataSourceName());
+ DataSource dataSource = getActualDataSourceMap().get(dataNode.getDataSourceName());
try (
Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(generateFetchActualDataSQL(dataNode))) {
@@ -88,9 +88,12 @@ public abstract class BaseDMLIT extends SingleITCase {
}
private String generateFetchActualDataSQL(final DataNode dataNode) throws SQLException {
- Optional<String> primaryKeyColumnName = getStorageContainer().getPrimaryKeyColumnName(getActualDataSourceMap().get(dataNode.getDataSourceName()), dataNode.getTableName());
- return primaryKeyColumnName.isPresent()
- ? String.format("SELECT * FROM %s ORDER BY %s ASC", dataNode.getTableName(), primaryKeyColumnName.get()) : String.format("SELECT * FROM %s", dataNode.getTableName());
+ Optional<DatabaseAssertionMetaData> databaseAssertionMetaData = DatabaseAssertionMetaDataFactory.newInstance(getDatabaseType());
+ if (databaseAssertionMetaData.isPresent()) {
+ String primaryKeyColumnName = databaseAssertionMetaData.get().getPrimaryKeyColumnName(getActualDataSourceMap().get(dataNode.getDataSourceName()), dataNode.getTableName());
+ return String.format("SELECT * FROM %s ORDER BY %s ASC", dataNode.getTableName(), primaryKeyColumnName);
+ }
+ return String.format("SELECT * FROM %s", dataNode.getTableName());
}
private void assertMetaData(final ResultSetMetaData actual, final Collection<DataSetColumn> expected) throws SQLException {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java
index c821af0..99f12cd 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java
@@ -71,7 +71,7 @@ public final class BatchDMLIT extends BatchITCase {
default:
}
int[] actualUpdateCounts;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCounts = executeBatchForPreparedStatement(connection);
}
assertDataSets(actualUpdateCounts);
@@ -105,7 +105,7 @@ public final class BatchDMLIT extends BatchITCase {
return;
default:
}
- try (Connection connection = getOperationDataSource().getConnection();
+ try (Connection connection = getTargetDataSource().getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(getSQL())) {
for (IntegrationTestCaseAssertion each : getIntegrationTestCase().getAssertions()) {
addBatch(preparedStatement, each);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
index 1c61af3..b5cd1db 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
@@ -66,7 +66,7 @@ public final class GeneralDMLIT extends BaseDMLIT {
default:
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType() ? executeUpdateForStatement(connection) : executeUpdateForPreparedStatement(connection);
}
assertDataSet(actualUpdateCount);
@@ -96,7 +96,7 @@ public final class GeneralDMLIT extends BaseDMLIT {
default:
}
int actualUpdateCount;
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLExecuteType.Literal == getSqlExecuteType() ? executeForStatement(connection) : executeForPreparedStatement(connection);
}
assertDataSet(actualUpdateCount);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java
index a7cd0b3..c377422 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java
@@ -65,7 +65,7 @@ public final class AdditionalDQLIT extends BaseDQLIT {
@Test
public void assertExecuteQueryWithResultSetTypeAndResultSetConcurrency() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
assertExecuteQueryForStatementWithResultSetTypeAndResultSetConcurrency(connection);
} else {
@@ -95,7 +95,7 @@ public final class AdditionalDQLIT extends BaseDQLIT {
@Test
public void assertExecuteQueryWithResultSetTypeAndResultSetConcurrencyAndResultSetHoldability() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
assertExecuteQueryForStatementWithResultSetTypeAndResultSetConcurrencyAndResultSetHoldability(connection);
} else {
@@ -127,7 +127,7 @@ public final class AdditionalDQLIT extends BaseDQLIT {
@Test
public void assertExecuteWithResultSetTypeAndResultSetConcurrency() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
assertExecuteForStatementWithResultSetTypeAndResultSetConcurrency(connection);
} else {
@@ -159,7 +159,7 @@ public final class AdditionalDQLIT extends BaseDQLIT {
@Test
public void assertExecuteWithResultSetTypeAndResultSetConcurrencyAndResultSetHoldability() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
assertExecuteForStatementWithResultSetTypeAndResultSetConcurrencyAndResultSetHoldability(connection);
} else {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
index 9bc47d2..91acbb4 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
@@ -61,7 +61,7 @@ public final class GeneralDQLIT extends BaseDQLIT {
@Test
public void assertExecuteQuery() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
assertExecuteQueryForStatement(connection);
} else {
@@ -91,7 +91,7 @@ public final class GeneralDQLIT extends BaseDQLIT {
@Test
public void assertExecute() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
if (SQLExecuteType.Literal == getSqlExecuteType()) {
assertExecuteForStatement(connection);
} else {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/BaseRALIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/BaseRALIT.java
index 21e6b41..00afff7 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/BaseRALIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/BaseRALIT.java
@@ -46,7 +46,7 @@ public abstract class BaseRALIT extends SingleITCase {
@Before
public final void init() throws Exception {
if (getAssertion().getInitialSQL() != null) {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
executeInitSQLs(connection);
}
}
@@ -55,7 +55,7 @@ public abstract class BaseRALIT extends SingleITCase {
@Override
public final void tearDown() throws Exception {
if (getAssertion().getDestroySQL() != null) {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
executeDestroySQLs(connection);
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/GeneralRALIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/GeneralRALIT.java
index 6171a6a..418f243 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/GeneralRALIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/GeneralRALIT.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.test.integration.engine.ral;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.SQLExecuteType;
import org.apache.shardingsphere.test.integration.framework.container.compose.ComposedContainerManager;
-import org.apache.shardingsphere.test.integration.framework.container.compose.mode.ClusterComposedContainer;
import org.apache.shardingsphere.test.integration.framework.param.ParameterizedArrayFactory;
import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray;
import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray;
@@ -30,7 +29,6 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
-import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -61,9 +59,7 @@ public final class GeneralRALIT extends BaseRALIT {
@Test
public void assertExecute() throws SQLException, ParseException {
- DataSource dataSource = getComposedContainer() instanceof ClusterComposedContainer
- ? getVerificationDataSource() : getOperationDataSource();
- try (Connection connection = dataSource.getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
assertExecuteForStatement(connection);
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/BaseRDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/BaseRDLIT.java
index 862860f..91641eb 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/BaseRDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/BaseRDLIT.java
@@ -47,7 +47,7 @@ public abstract class BaseRDLIT extends SingleITCase {
@Before
public final void init() throws Exception {
assertNotNull("Init SQL is required", getAssertion().getInitialSQL());
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
executeInitSQLs(connection);
}
}
@@ -55,7 +55,7 @@ public abstract class BaseRDLIT extends SingleITCase {
@Override
public final void tearDown() throws Exception {
if (getAssertion().getDestroySQL() != null) {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
executeDestroySQLs(connection);
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/GeneralRDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/GeneralRDLIT.java
index 66046ae..d392221 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/GeneralRDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/GeneralRDLIT.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.test.integration.engine.rdl;
import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
import org.apache.shardingsphere.test.integration.cases.SQLExecuteType;
import org.apache.shardingsphere.test.integration.framework.container.compose.ComposedContainerManager;
-import org.apache.shardingsphere.test.integration.framework.container.compose.mode.ClusterComposedContainer;
import org.apache.shardingsphere.test.integration.framework.param.ParameterizedArrayFactory;
import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray;
import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray;
@@ -30,7 +29,6 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
-import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -61,9 +59,7 @@ public final class GeneralRDLIT extends BaseRDLIT {
@Test
public void assertExecute() throws SQLException, ParseException {
- DataSource dataSource = getComposedContainer() instanceof ClusterComposedContainer
- ? getVerificationDataSource() : getOperationDataSource();
- try (Connection connection = dataSource.getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
assertExecuteForStatement(connection);
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rql/GeneralRQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rql/GeneralRQLIT.java
index 1523355..8f27fa1 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rql/GeneralRQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rql/GeneralRQLIT.java
@@ -59,7 +59,7 @@ public final class GeneralRQLIT extends BaseRQLIT {
@Test
public void assertExecute() throws SQLException, ParseException {
- try (Connection connection = getOperationDataSource().getConnection()) {
+ try (Connection connection = getTargetDataSource().getConnection()) {
assertExecuteForStatement(connection);
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/AdapterContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/AdapterContainer.java
index a71877e..b80c381 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/AdapterContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/AdapterContainer.java
@@ -35,18 +35,10 @@ public abstract class AdapterContainer extends AtomicContainer {
}
/**
- * Get operation data source.
+ * Get target data source.
*
* @param serverLists server lists
- * @return operation data source
+ * @return target data source
*/
- public abstract DataSource getOperationDataSource(String serverLists);
-
- /**
- * Get verification data source.
- *
- * @param serverLists server lists
- * @return verification data source
- */
- public abstract DataSource getVerificationDataSource(String serverLists);
+ public abstract DataSource getTargetDataSource(String serverLists);
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
index 8a9b836..02ffa12 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
@@ -50,9 +50,7 @@ public final class ShardingSphereJDBCContainer extends AdapterContainer {
private Map<String, DataSource> dataSourceMap;
- private final AtomicReference<DataSource> clientDataSourceProvider = new AtomicReference<>();
-
- private final AtomicReference<DataSource> anotherClientDataSourceProvider = new AtomicReference<>();
+ private final AtomicReference<DataSource> targetDataSourceProvider = new AtomicReference<>();
public ShardingSphereJDBCContainer(final String scenario) {
super("ShardingSphere-JDBC", "ShardingSphere-JDBC", true);
@@ -73,29 +71,20 @@ public final class ShardingSphereJDBCContainer extends AdapterContainer {
}
@Override
- public DataSource getOperationDataSource(final String serverLists) {
- DataSource dataSource = clientDataSourceProvider.get();
+ public DataSource getTargetDataSource(final String serverLists) {
+ DataSource dataSource = targetDataSourceProvider.get();
if (Objects.isNull(dataSource)) {
if (Strings.isNullOrEmpty(serverLists)) {
try {
- clientDataSourceProvider.set(YamlShardingSphereDataSourceFactory.createDataSource(dataSourceMap, new File(EnvironmentPath.getRulesConfigurationFile(scenario))));
+ targetDataSourceProvider.set(YamlShardingSphereDataSourceFactory.createDataSource(dataSourceMap, new File(EnvironmentPath.getRulesConfigurationFile(scenario))));
} catch (final SQLException | IOException ex) {
throw new RuntimeException(ex);
}
} else {
- clientDataSourceProvider.set(createGovernanceClientDataSource(serverLists));
+ targetDataSourceProvider.set(createGovernanceClientDataSource(serverLists));
}
}
- return clientDataSourceProvider.get();
- }
-
- @Override
- public DataSource getVerificationDataSource(final String serverLists) {
- DataSource dataSource = anotherClientDataSourceProvider.get();
- if (Objects.isNull(dataSource)) {
- anotherClientDataSourceProvider.set(createGovernanceClientDataSource(serverLists));
- }
- return anotherClientDataSourceProvider.get();
+ return targetDataSourceProvider.get();
}
@SneakyThrows({SQLException.class, IOException.class})
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereProxyContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereProxyContainer.java
index 93aa901..d0d3ad2 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereProxyContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereProxyContainer.java
@@ -54,7 +54,7 @@ public final class ShardingSphereProxyContainer extends AdapterContainer {
private final String scenario;
- private final AtomicReference<DataSource> dataSourceProvider = new AtomicReference<>();
+ private final AtomicReference<DataSource> targetDataSourceProvider = new AtomicReference<>();
public ShardingSphereProxyContainer(final DatabaseType databaseType, final String scenario) {
this(null, databaseType, scenario);
@@ -114,17 +114,12 @@ public final class ShardingSphereProxyContainer extends AdapterContainer {
}
@Override
- public DataSource getOperationDataSource(final String serverLists) {
- DataSource dataSource = dataSourceProvider.get();
+ public DataSource getTargetDataSource(final String serverLists) {
+ DataSource dataSource = targetDataSourceProvider.get();
if (Objects.isNull(dataSource)) {
- dataSourceProvider.set(createProxyDataSource());
+ targetDataSourceProvider.set(createProxyDataSource());
}
- return dataSourceProvider.get();
- }
-
- @Override
- public DataSource getVerificationDataSource(final String serverLists) {
- return getOperationDataSource(serverLists);
+ return targetDataSourceProvider.get();
}
private DataSource createProxyDataSource() {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/StorageContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/StorageContainer.java
index 664f52e..2846ee1 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/StorageContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/StorageContainer.java
@@ -32,7 +32,6 @@ import org.testcontainers.shaded.com.google.common.collect.ImmutableMap.Builder;
import javax.sql.DataSource;
import javax.xml.bind.JAXBException;
import java.io.IOException;
-import java.sql.SQLException;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
@@ -98,14 +97,4 @@ public abstract class StorageContainer extends AtomicContainer {
}
protected abstract int getPort();
-
- /**
- * Get primary key column name.
- *
- * @param dataSource data source
- * @param tableName table name
- * @return primary key column name
- * @throws SQLException SQL exception
- */
- public abstract Optional<String> getPrimaryKeyColumnName(DataSource dataSource, String tableName) throws SQLException;
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
index bee95ec..3d5f639 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
@@ -31,7 +31,6 @@ import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map.Entry;
-import java.util.Optional;
/**
* H2 container.
@@ -84,9 +83,4 @@ public final class H2Container extends StorageContainer {
protected int getPort() {
return 0;
}
-
- @Override
- public Optional<String> getPrimaryKeyColumnName(final DataSource dataSource, final String tableName) {
- return Optional.empty();
- }
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/MySQLContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/MySQLContainer.java
index d79ee76..ae60f0c 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/MySQLContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/MySQLContainer.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.test.integration.framework.container.atomic.st
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.StorageContainer;
-import javax.sql.DataSource;
import java.util.Collections;
import java.util.Optional;
@@ -59,9 +58,4 @@ public final class MySQLContainer extends StorageContainer {
protected int getPort() {
return getMappedPort(3306);
}
-
- @Override
- public Optional<String> getPrimaryKeyColumnName(final DataSource dataSource, final String tableName) {
- return Optional.empty();
- }
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/PostgreSQLContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/PostgreSQLContainer.java
index 6b57e94..4dd2a16 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/PostgreSQLContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/PostgreSQLContainer.java
@@ -23,13 +23,9 @@ import org.apache.shardingsphere.test.integration.env.DataSourceEnvironment;
import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.StorageContainer;
import org.postgresql.util.PSQLException;
-import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
-import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Optional;
/**
* PostgreSQL container.
@@ -78,19 +74,4 @@ public final class PostgreSQLContainer extends StorageContainer {
protected int getPort() {
return getMappedPort(5432);
}
-
- @Override
- public Optional<String> getPrimaryKeyColumnName(final DataSource dataSource, final String tableName) throws SQLException {
- String sql = String.format("SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type "
- + "FROM pg_index i JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey) WHERE i.indrelid = '%s'::regclass AND i.indisprimary", tableName);
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(sql)) {
- if (resultSet.next()) {
- return Optional.of(resultSet.getString("attname"));
- }
- throw new SQLException(String.format("Can not get primary key of `%s`", tableName));
- }
- }
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/ComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/ComposedContainer.java
index bdc8245..e37ad04 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/ComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/ComposedContainer.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.test.integration.framework.container.compose;
import org.apache.shardingsphere.test.integration.framework.container.atomic.AtomicContainers;
-import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.StorageContainer;
import javax.sql.DataSource;
+import java.util.Map;
/**
* Composed container.
@@ -35,23 +35,16 @@ public interface ComposedContainer {
AtomicContainers getContainers();
/**
- * Get storage container.
+ * Get actual data source map.
*
- * @return storage container
+ * @return actual data source map
*/
- StorageContainer getStorageContainer();
+ Map<String, DataSource> getActualDataSourceMap();
/**
- * Get operation data source.
+ * Get target data source.
*
- * @return operation data source
+ * @return target data source
*/
- DataSource getOperationDataSource();
-
- /**
- * Get verification data source.
- *
- * @return verification data source
- */
- DataSource getVerificationDataSource();
+ DataSource getTargetDataSource();
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/mode/ClusterComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/mode/ClusterComposedContainer.java
index 0231be6..8bfc4be 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/mode/ClusterComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/mode/ClusterComposedContainer.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import org.apache.shardingsphere.test.integration.framework.container.atomic.AtomicContainers;
import org.apache.shardingsphere.test.integration.framework.container.atomic.adapter.AdapterContainer;
import org.apache.shardingsphere.test.integration.framework.container.atomic.adapter.AdapterContainerFactory;
-import org.apache.shardingsphere.test.integration.framework.container.atomic.adapter.impl.ShardingSphereProxyContainer;
import org.apache.shardingsphere.test.integration.framework.container.atomic.governance.GovernanceContainer;
import org.apache.shardingsphere.test.integration.framework.container.atomic.governance.GovernanceContainerFactory;
import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.StorageContainer;
@@ -30,6 +29,7 @@ import org.apache.shardingsphere.test.integration.framework.container.compose.Co
import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray;
import javax.sql.DataSource;
+import java.util.Map;
/**
* Cluster composed container.
@@ -44,9 +44,7 @@ public final class ClusterComposedContainer implements ComposedContainer {
@Getter
private final StorageContainer storageContainer;
- private final AdapterContainer operationAdapterContainer;
-
- private final AdapterContainer verificationAdapterContainer;
+ private final AdapterContainer adapterContainer;
public ClusterComposedContainer(final String testSuiteName, final ParameterizedArray parameterizedArray) {
containers = new AtomicContainers(testSuiteName, parameterizedArray.getScenario());
@@ -54,26 +52,18 @@ public final class ClusterComposedContainer implements ComposedContainer {
governanceContainer = containers.registerContainer(GovernanceContainerFactory.newInstance("ZooKeeper"), "zk");
storageContainer = containers.registerContainer(
StorageContainerFactory.newInstance(parameterizedArray.getDatabaseType(), parameterizedArray.getScenario()), parameterizedArray.getDatabaseType().getName());
- operationAdapterContainer = containers.registerContainer(
+ adapterContainer = containers.registerContainer(
AdapterContainerFactory.newInstance(parameterizedArray.getAdapter(), parameterizedArray.getDatabaseType(), parameterizedArray.getScenario()), parameterizedArray.getAdapter());
- operationAdapterContainer.dependsOn(governanceContainer, storageContainer);
- if ("proxy".equals(parameterizedArray.getAdapter())) {
- verificationAdapterContainer = containers.registerContainer(
- new ShardingSphereProxyContainer("ShardingSphere-Proxy-1", parameterizedArray.getDatabaseType(), parameterizedArray.getScenario()), "ShardingSphere-Proxy-1");
- } else {
- verificationAdapterContainer = containers.registerContainer(
- AdapterContainerFactory.newInstance(parameterizedArray.getAdapter(), parameterizedArray.getDatabaseType(), parameterizedArray.getScenario()), parameterizedArray.getAdapter());
- }
- verificationAdapterContainer.dependsOn(governanceContainer, storageContainer);
+ adapterContainer.dependsOn(governanceContainer, storageContainer);
}
@Override
- public DataSource getOperationDataSource() {
- return operationAdapterContainer.getOperationDataSource(governanceContainer.getServerLists());
+ public Map<String, DataSource> getActualDataSourceMap() {
+ return storageContainer.getActualDataSourceMap();
}
@Override
- public DataSource getVerificationDataSource() {
- return verificationAdapterContainer.getVerificationDataSource(governanceContainer.getServerLists());
+ public DataSource getTargetDataSource() {
+ return adapterContainer.getTargetDataSource(governanceContainer.getServerLists());
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/mode/MemoryComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/mode/MemoryComposedContainer.java
index 6f932f7..aaa9670 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/mode/MemoryComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/mode/MemoryComposedContainer.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.test.integration.framework.container.compose.Co
import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray;
import javax.sql.DataSource;
+import java.util.Map;
/**
* Memory composed container.
@@ -50,12 +51,12 @@ public final class MemoryComposedContainer implements ComposedContainer {
}
@Override
- public DataSource getOperationDataSource() {
- return adapterContainer.getOperationDataSource(null);
+ public Map<String, DataSource> getActualDataSourceMap() {
+ return storageContainer.getActualDataSourceMap();
}
@Override
- public DataSource getVerificationDataSource() {
- return adapterContainer.getOperationDataSource(null);
+ public DataSource getTargetDataSource() {
+ return adapterContainer.getTargetDataSource(null);
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/ComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/DatabaseAssertionMetaData.java
similarity index 50%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/ComposedContainer.java
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/DatabaseAssertionMetaData.java
index bdc8245..10a6545 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/compose/ComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/DatabaseAssertionMetaData.java
@@ -15,43 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.integration.framework.container.compose;
-
-import org.apache.shardingsphere.test.integration.framework.container.atomic.AtomicContainers;
-import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.StorageContainer;
+package org.apache.shardingsphere.test.integration.framework.database;
import javax.sql.DataSource;
+import java.sql.SQLException;
/**
- * Composed container.
+ * Database assertion meta data.
*/
-public interface ComposedContainer {
-
- /**
- * Get containers.
- *
- * @return containers
- */
- AtomicContainers getContainers();
-
- /**
- * Get storage container.
- *
- * @return storage container
- */
- StorageContainer getStorageContainer();
-
- /**
- * Get operation data source.
- *
- * @return operation data source
- */
- DataSource getOperationDataSource();
+public interface DatabaseAssertionMetaData {
/**
- * Get verification data source.
+ * Get primary key column name.
*
- * @return verification data source
+ * @param dataSource data source
+ * @param tableName table name
+ * @return primary key column name
+ * @throws SQLException SQL exception
*/
- DataSource getVerificationDataSource();
+ String getPrimaryKeyColumnName(DataSource dataSource, String tableName) throws SQLException;
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/DatabaseAssertionMetaDataFactory.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/DatabaseAssertionMetaDataFactory.java
new file mode 100644
index 0000000..46314bc
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/DatabaseAssertionMetaDataFactory.java
@@ -0,0 +1,48 @@
+/*
+ * 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.integration.framework.database;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.test.integration.framework.database.impl.PostgreSQLDatabaseAssertionMetaData;
+
+import java.util.Optional;
+
+/**
+ * Database assertion meta data factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DatabaseAssertionMetaDataFactory {
+
+ /**
+ * Create new instance of database assertion meta data.
+ *
+ * @param databaseType database type
+ * @return new instance of database assertion meta data
+ */
+ @SuppressWarnings("SwitchStatementWithTooFewBranches")
+ public static Optional<DatabaseAssertionMetaData> newInstance(final DatabaseType databaseType) {
+ switch (databaseType.getName()) {
+ case "PostgreSQL":
+ return Optional.of(new PostgreSQLDatabaseAssertionMetaData());
+ default:
+ return Optional.empty();
+ }
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/impl/PostgreSQLDatabaseAssertionMetaData.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/impl/PostgreSQLDatabaseAssertionMetaData.java
new file mode 100644
index 0000000..8bf445b
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/database/impl/PostgreSQLDatabaseAssertionMetaData.java
@@ -0,0 +1,47 @@
+/*
+ * 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.integration.framework.database.impl;
+
+import org.apache.shardingsphere.test.integration.framework.database.DatabaseAssertionMetaData;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * PostgreSQL assertion meta data.
+ */
+public final class PostgreSQLDatabaseAssertionMetaData implements DatabaseAssertionMetaData {
+
+ @Override
+ public String getPrimaryKeyColumnName(final DataSource dataSource, final String tableName) throws SQLException {
+ String sql = String.format("SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type "
+ + "FROM pg_index i JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey) WHERE i.indrelid = '%s'::regclass AND i.indisprimary", tableName);
+ try (
+ Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(sql)) {
+ if (resultSet.next()) {
+ return resultSet.getString("attname");
+ }
+ throw new SQLException(String.format("Can not get primary key of `%s`", tableName));
+ }
+ }
+}