You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/12/30 10:14:57 UTC
[shardingsphere] branch master updated: Split GeneralDDLIT to
JDBCGeneralDDLIT and ProxyGeneralDDLIT (#8828)
This is an automated email from the ASF dual-hosted git repository.
zhangyonglun 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 adafd44 Split GeneralDDLIT to JDBCGeneralDDLIT and ProxyGeneralDDLIT (#8828)
adafd44 is described below
commit adafd44a48207688a347c17b6180a18bb6e3721f
Author: Liang Zhang <te...@163.com>
AuthorDate: Wed Dec 30 18:14:36 2020 +0800
Split GeneralDDLIT to JDBCGeneralDDLIT and ProxyGeneralDDLIT (#8828)
* Rename ActualDataSourceBuilder
* Add ActualDataSourceBuilder.createActualDataSources()
* Refactor BaseIT
* Add JDBCGeneralDDLIT
* Refactor JDBCGeneralDDLIT
* Refactor BaseDDLIT
* Refactor ProxyGeneralDDLIT
* Move IntegrateTestParameters
---
.../{engine/util => }/IntegrateTestParameters.java | 2 +-
.../test/integration/cases/dataset/DataSet.java | 7 +-
.../cases/dataset/metadata/DataSetMetadata.java | 6 +-
.../test/integration/engine/BaseIT.java | 18 +--
.../test/integration/engine/BatchIT.java | 2 +-
.../test/integration/engine/dcl/GeneralDCLIT.java | 2 +-
.../test/integration/engine/ddl/BaseDDLIT.java | 122 +++-----------------
.../test/integration/engine/ddl/GeneralDDLIT.java | 87 ---------------
.../integration/engine/ddl/JDBCGeneralDDLIT.java | 113 +++++++++++++++++++
.../ddl/{BaseDDLIT.java => ProxyGeneralDDLIT.java} | 124 +++++++++------------
.../integration/engine/dml/AdditionalDMLIT.java | 2 +-
.../test/integration/engine/dml/BaseDMLIT.java | 3 +-
.../test/integration/engine/dml/BatchDMLIT.java | 2 +-
.../test/integration/engine/dml/GeneralDMLIT.java | 2 +-
.../integration/engine/dql/AdditionalDQLIT.java | 2 +-
.../test/integration/engine/dql/BaseDQLIT.java | 17 +--
.../test/integration/engine/dql/GeneralDQLIT.java | 2 +-
.../env/dataset/DataSetEnvironmentManager.java | 2 +-
...ceBuilder.java => ActualDataSourceBuilder.java} | 34 +++++-
.../env/schema/SchemaEnvironmentManager.java | 10 +-
.../dataset/{empty_table.xml => drop_table.xml} | 7 +-
.../{empty_table.xml => unchanged_table.xml} | 0
.../cases/ddl/ddl-integrate-test-cases.xml | 8 +-
23 files changed, 244 insertions(+), 330 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/util/IntegrateTestParameters.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/IntegrateTestParameters.java
similarity index 99%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/util/IntegrateTestParameters.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/IntegrateTestParameters.java
index bf91a0c..1eb6822 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/util/IntegrateTestParameters.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/IntegrateTestParameters.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.integration.engine.util;
+package org.apache.shardingsphere.test.integration;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/DataSet.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/DataSet.java
index 59ca249..7d62550 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/DataSet.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/DataSet.java
@@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
+import java.util.Optional;
/**
* Data sets root xml entry.
@@ -53,13 +54,13 @@ public final class DataSet {
* @param tableName table name
* @return data set meta data belong to current table
*/
- public DataSetMetadata findMetadata(final String tableName) {
+ public Optional<DataSetMetadata> findMetadata(final String tableName) {
for (DataSetMetadata each : metadataList) {
if (tableName.equals(each.getTableName())) {
- return each;
+ return Optional.of(each);
}
}
- throw new IllegalArgumentException(String.format("Cannot find expected metadata via table name: '%s'", tableName));
+ return Optional.empty();
}
/**
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/metadata/DataSetMetadata.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/metadata/DataSetMetadata.java
index cce99a1..ab98f68 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/metadata/DataSetMetadata.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/metadata/DataSetMetadata.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.test.integration.cases.dataset.metadata;
import lombok.Getter;
+import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -27,6 +28,7 @@ import java.util.LinkedList;
import java.util.List;
@Getter
+@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class DataSetMetadata {
@@ -37,8 +39,8 @@ public final class DataSetMetadata {
private String tableName;
@XmlElement(name = "column")
- private List<DataSetColumn> columns = new LinkedList<>();
+ private final List<DataSetColumn> columns = new LinkedList<>();
@XmlElement(name = "index")
- private List<DataSetIndex> indexes = new LinkedList<>();
+ private final List<DataSetIndex> indexes = new LinkedList<>();
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseIT.java
index db69403..b8837ab 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseIT.java
@@ -24,9 +24,8 @@ import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataS
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
-import org.apache.shardingsphere.test.integration.env.datasource.builder.JdbcDataSourceBuilder;
+import org.apache.shardingsphere.test.integration.env.datasource.builder.ActualDataSourceBuilder;
import org.apache.shardingsphere.test.integration.env.datasource.builder.ProxyDataSourceBuilder;
-import org.apache.shardingsphere.test.integration.env.schema.SchemaEnvironmentManager;
import org.junit.After;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -39,8 +38,6 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
@@ -68,19 +65,10 @@ public abstract class BaseIT {
BaseIT(final String ruleType, final DatabaseType databaseType) throws IOException, JAXBException, SQLException {
this.ruleType = ruleType;
this.databaseType = databaseType;
- actualDataSources = createActualDataSources();
+ actualDataSources = ActualDataSourceBuilder.createActualDataSources(ruleType, databaseType);
targetDataSource = createTargetDataSource();
}
- private Map<String, DataSource> createActualDataSources() throws IOException, JAXBException {
- Collection<String> dataSourceNames = SchemaEnvironmentManager.getDataSourceNames(ruleType);
- Map<String, DataSource> result = new HashMap<>(dataSourceNames.size(), 1);
- for (String each : dataSourceNames) {
- result.put(each, JdbcDataSourceBuilder.build(each, databaseType));
- }
- return result;
- }
-
private DataSource createTargetDataSource() throws SQLException, IOException {
return IntegrateTestEnvironment.getInstance().isProxyEnvironment() ? ProxyDataSourceBuilder.build(String.format("proxy_%s", ruleType), databaseType)
: YamlShardingSphereDataSourceFactory.createDataSource(actualDataSources, new File(EnvironmentPath.getRulesConfigurationFile(ruleType)));
@@ -91,7 +79,7 @@ public abstract class BaseIT {
}
@After
- public void tearDown() {
+ public final void tearDown() {
if (targetDataSource instanceof ShardingSphereDataSource) {
((ShardingSphereDataSource) targetDataSource).getMetaDataContexts().getExecutorEngine().close();
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchIT.java
index b6253a2..b87187d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchIT.java
@@ -166,7 +166,7 @@ public abstract class BatchIT extends BaseIT {
dataSet.getRows().sort(Comparator.comparingInt(o -> Integer.parseInt(o.getValues().get(0))));
}
- private void assertMetaData(final ResultSetMetaData actualMetaData, final List<DataSetColumn> columnMetadataList) throws SQLException {
+ private void assertMetaData(final ResultSetMetaData actualMetaData, final Collection<DataSetColumn> columnMetadataList) throws SQLException {
assertThat(actualMetaData.getColumnCount(), is(columnMetadataList.size()));
int index = 1;
for (DataSetColumn each : columnMetadataList) {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
index 567089b..8439854 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.test.integration.engine.dcl;
import org.apache.shardingsphere.test.integration.cases.assertion.dcl.DCLIntegrateTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
-import org.apache.shardingsphere.test.integration.engine.util.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
index a6616d7..b65cae8 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
@@ -17,13 +17,11 @@
package org.apache.shardingsphere.test.integration.engine.ddl;
-import lombok.extern.slf4j.Slf4j;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.ddl.DDLIntegrateTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
-import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetColumn;
-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.SingleIT;
import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
@@ -36,20 +34,10 @@ import org.junit.BeforeClass;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.sql.Connection;
-import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
-import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-@Slf4j
public abstract class BaseDDLIT extends SingleIT {
private final DataSetEnvironmentManager dataSetEnvironmentManager;
@@ -73,109 +61,31 @@ public abstract class BaseDDLIT extends SingleIT {
@Before
public final void initTables() throws SQLException, ParseException, IOException, JAXBException {
SchemaEnvironmentManager.createTables();
- resetTargetDataSource();
dataSetEnvironmentManager.load();
- }
-
- @After
- public final void destroyTables() throws JAXBException, IOException {
- SchemaEnvironmentManager.dropTables();
- }
-
- protected final void assertTableMetaData(final Connection connection) throws SQLException {
- String tableName = ((DDLIntegrateTestCaseAssertion) getAssertion()).getTable();
- List<DataSetColumn> actualColumns = getActualColumns(connection, tableName);
- List<DataSetIndex> actualIndexes = getActualIndexes(connection, tableName);
- if (actualColumns.isEmpty() || actualIndexes.isEmpty()) {
- assertIfDropTable(actualColumns);
- assertIfDropIndex(actualIndexes);
- return;
- }
- try {
- assertTableMetaData(actualColumns, actualIndexes, getDataSet().findMetadata(tableName));
- } catch (final AssertionError ex) {
- log.error("[ERROR] SQL::{}, Parameter::{}, Expect::{}", getCaseIdentifier(), getAssertion().getParameters(), getAssertion().getExpectedDataFile());
- throw ex;
- }
- }
-
- private void assertTableMetaData(final List<DataSetColumn> actualColumns, final List<DataSetIndex> actualIndexes, final DataSetMetadata expected) {
- for (DataSetColumn each : expected.getColumns()) {
- assertColumnMetaData(actualColumns, each);
- }
- for (DataSetIndex each : expected.getIndexes()) {
- assertIndexMetaData(actualIndexes, each);
- }
- }
-
- private List<DataSetColumn> getActualColumns(final Connection connection, final String tableName) throws SQLException {
- DatabaseMetaData metaData = connection.getMetaData();
- boolean isTableExisted = metaData.getTables(null, null, tableName, new String[] {"TABLE"}).next();
- if (!isTableExisted) {
- return Collections.emptyList();
- }
- try (ResultSet resultSet = metaData.getColumns(null, null, tableName, null)) {
- List<DataSetColumn> result = new LinkedList<>();
- while (resultSet.next()) {
- DataSetColumn each = new DataSetColumn();
- each.setName(resultSet.getString("COLUMN_NAME"));
- each.setType(resultSet.getString("TYPE_NAME").toLowerCase());
- result.add(each);
- }
- return result;
- }
- }
-
- private List<DataSetIndex> getActualIndexes(final Connection connection, final String tableName) throws SQLException {
- DatabaseMetaData metaData = connection.getMetaData();
- try (ResultSet resultSet = metaData.getIndexInfo(null, null, tableName, false, false)) {
- List<DataSetIndex> result = new LinkedList<>();
- while (resultSet.next()) {
- DataSetIndex each = new DataSetIndex();
- each.setName(resultSet.getString("INDEX_NAME"));
- each.setUnique(!resultSet.getBoolean("NON_UNIQUE"));
- each.setColumns(resultSet.getString("COLUMN_NAME"));
- result.add(each);
- }
- return result;
- }
- }
-
- private void assertIfDropTable(final List<DataSetColumn> actualColumns) {
- if (getSql().startsWith("DROP TABLE")) {
- assertTrue(actualColumns.isEmpty());
+ try (Connection connection = getTargetDataSource().getConnection()) {
+ executeInitSQLs(connection);
}
+ resetTargetDataSource();
}
- private void assertIfDropIndex(final List<DataSetIndex> actualIndexes) {
- if (getSql().startsWith("DROP INDEX")) {
- assertTrue(actualIndexes.isEmpty());
+ private void executeInitSQLs(final Connection connection) throws SQLException {
+ if (Strings.isNullOrEmpty(((DDLIntegrateTestCaseAssertion) getAssertion()).getInitSQL())) {
+ return;
}
- }
-
- private void assertColumnMetaData(final List<DataSetColumn> actual, final DataSetColumn expect) {
- for (DataSetColumn each : actual) {
- if (expect.getName().equals(each.getName())) {
- if ("MySQL".equals(getDatabaseType().getName()) && "integer".equals(expect.getType())) {
- assertThat(each.getType(), is("int"));
- } else if ("PostgreSQL".equals(getDatabaseType().getName()) && "integer".equals(expect.getType())) {
- assertThat(each.getType(), is("int4"));
- } else {
- assertThat(each.getType(), is(expect.getType()));
- }
- }
+ for (String each : Splitter.on(";").trimResults().splitToList(((DDLIntegrateTestCaseAssertion) getAssertion()).getInitSQL())) {
+ connection.prepareStatement(each).executeUpdate();
}
}
- private void assertIndexMetaData(final List<DataSetIndex> actual, final DataSetIndex expect) {
- for (DataSetIndex each : actual) {
- if (expect.getName().equals(each.getName())) {
- assertThat(each.isUnique(), is(expect.isUnique()));
- }
+ @After
+ public final void destroyTables() throws JAXBException, IOException, SQLException {
+ SchemaEnvironmentManager.dropTables();
+ try (Connection connection = getTargetDataSource().getConnection()) {
+ dropInitializedTable(connection);
}
}
- protected final void dropTableIfExisted(final Connection connection) {
+ private void dropInitializedTable(final Connection connection) {
try (PreparedStatement preparedStatement = connection.prepareStatement(String.format("DROP TABLE %s", ((DDLIntegrateTestCaseAssertion) getAssertion()).getTable()))) {
preparedStatement.executeUpdate();
} catch (final SQLException ignored) {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java
deleted file mode 100644
index 912eaf2..0000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java
+++ /dev/null
@@ -1,87 +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.integration.engine.ddl;
-
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.test.integration.cases.assertion.ddl.DDLIntegrateTestCaseAssertion;
-import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
-import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
-import org.apache.shardingsphere.test.integration.engine.util.IntegrateTestParameters;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.junit.Test;
-import org.junit.runners.Parameterized.Parameters;
-
-import javax.xml.bind.JAXBException;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.text.ParseException;
-import java.util.Collection;
-
-public final class GeneralDDLIT extends BaseDDLIT {
-
- public GeneralDDLIT(final String parentPath, final DDLIntegrateTestCaseAssertion assertion, final String ruleType,
- final String databaseType, final SQLCaseType caseType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
- super(parentPath, assertion, ruleType, DatabaseTypeRegistry.getActualDatabaseType(databaseType), caseType, sql);
- }
-
- @Parameters(name = "{2} -> {3} -> {4} -> {5}")
- public static Collection<Object[]> getParameters() {
- return IntegrateTestParameters.getParametersWithAssertion(IntegrateTestCaseType.DDL);
- }
-
- @Test
- public void assertExecuteUpdate() throws SQLException {
- assertExecute(true);
- }
-
- @Test
- public void assertExecute() throws SQLException {
- assertExecute(false);
- }
-
- private void assertExecute(final boolean isExecuteUpdate) throws SQLException {
- try (Connection connection = getTargetDataSource().getConnection()) {
- dropTableIfExisted(connection);
- if (!Strings.isNullOrEmpty(((DDLIntegrateTestCaseAssertion) getAssertion()).getInitSQL())) {
- for (String each : Splitter.on(";").trimResults().splitToList(((DDLIntegrateTestCaseAssertion) getAssertion()).getInitSQL())) {
- connection.prepareStatement(each).executeUpdate();
- }
- }
- if (isExecuteUpdate) {
- if (SQLCaseType.Literal == getCaseType()) {
- connection.createStatement().executeUpdate(getSql());
- } else {
- connection.prepareStatement(getSql()).executeUpdate();
- }
- } else {
- if (SQLCaseType.Literal == getCaseType()) {
- connection.createStatement().execute(getSql());
- } else {
- connection.prepareStatement(getSql()).execute();
- }
- }
- assertTableMetaData(connection);
- dropTableIfExisted(connection);
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
- }
- }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/JDBCGeneralDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/JDBCGeneralDDLIT.java
new file mode 100644
index 0000000..b915b76
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/JDBCGeneralDDLIT.java
@@ -0,0 +1,113 @@
+/*
+ * 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.engine.ddl;
+
+import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
+import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
+import org.apache.shardingsphere.test.integration.cases.assertion.ddl.DDLIntegrateTestCaseAssertion;
+import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
+import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetColumn;
+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.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
+import org.junit.Test;
+import org.junit.runners.Parameterized.Parameters;
+
+import javax.xml.bind.JAXBException;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+
+public final class JDBCGeneralDDLIT extends BaseDDLIT {
+
+ public JDBCGeneralDDLIT(final String parentPath, final DDLIntegrateTestCaseAssertion assertion, final String ruleType,
+ final String databaseType, final SQLCaseType caseType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
+ super(parentPath, assertion, ruleType, DatabaseTypeRegistry.getActualDatabaseType(databaseType), caseType, sql);
+ }
+
+ @Parameters(name = "{2} -> {3} -> {4} -> {5}")
+ public static Collection<Object[]> getParameters() {
+ return IntegrateTestEnvironment.getInstance().isProxyEnvironment() ? Collections.emptyList() : IntegrateTestParameters.getParametersWithAssertion(IntegrateTestCaseType.DDL);
+ }
+
+ @SuppressWarnings("JUnitTestMethodWithNoAssertions")
+ @Test
+ public void assertExecuteUpdate() throws SQLException {
+ try (Connection connection = getTargetDataSource().getConnection()) {
+ if (SQLCaseType.Literal == getCaseType()) {
+ connection.createStatement().executeUpdate(getSql());
+ } else {
+ connection.prepareStatement(getSql()).executeUpdate();
+ }
+ assertTableMetaData(((ShardingSphereConnection) connection).getMetaDataContexts().getDefaultMetaData().getSchema());
+ } catch (final SQLException ex) {
+ logException(ex);
+ throw ex;
+ }
+ }
+
+ @SuppressWarnings("JUnitTestMethodWithNoAssertions")
+ @Test
+ public void assertExecute() throws SQLException {
+ try (Connection connection = getTargetDataSource().getConnection()) {
+ if (SQLCaseType.Literal == getCaseType()) {
+ connection.createStatement().execute(getSql());
+ } else {
+ connection.prepareStatement(getSql()).execute();
+ }
+ assertTableMetaData(((ShardingSphereConnection) connection).getMetaDataContexts().getDefaultMetaData().getSchema());
+ } catch (final SQLException ex) {
+ logException(ex);
+ throw ex;
+ }
+ }
+
+ private void assertTableMetaData(final ShardingSphereSchema schema) {
+ String tableName = ((DDLIntegrateTestCaseAssertion) getAssertion()).getTable();
+ Optional<DataSetMetadata> expected = getDataSet().findMetadata(tableName);
+ if (!expected.isPresent()) {
+ assertFalse(schema.containsTable(tableName));
+ return;
+ }
+ TableMetaData actual = schema.get(tableName);
+ assertTableMetaData(actual, expected.get());
+ }
+
+ private void assertTableMetaData(final TableMetaData actual, final DataSetMetadata expected) {
+ // TODO fill metadata for replica query and other rules
+ if (actual.getColumns().isEmpty()) {
+ return;
+ }
+ assertThat(new LinkedList<>(actual.getColumns().keySet()), is(expected.getColumns().stream().map(DataSetColumn::getName).collect(Collectors.toList())));
+ assertThat(new LinkedList<>(actual.getIndexes().keySet()), is(expected.getIndexes().stream().map(DataSetIndex::getName).collect(Collectors.toList())));
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/ProxyGeneralDDLIT.java
similarity index 57%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/ProxyGeneralDDLIT.java
index a6616d7..01a2342 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/ProxyGeneralDDLIT.java
@@ -17,86 +17,87 @@
package org.apache.shardingsphere.test.integration.engine.ddl;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.ddl.DDLIntegrateTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetColumn;
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.SingleIT;
-import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
-import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
-import org.apache.shardingsphere.test.integration.env.schema.SchemaEnvironmentManager;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
+import org.junit.Test;
+import org.junit.runners.Parameterized.Parameters;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
+import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-@Slf4j
-public abstract class BaseDDLIT extends SingleIT {
+public final class ProxyGeneralDDLIT extends BaseDDLIT {
- private final DataSetEnvironmentManager dataSetEnvironmentManager;
-
- protected BaseDDLIT(final String parentPath, final DDLIntegrateTestCaseAssertion assertion, final String ruleType,
- final DatabaseType databaseType, final SQLCaseType caseType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
- super(parentPath, assertion, ruleType, databaseType, caseType, sql);
- dataSetEnvironmentManager = new DataSetEnvironmentManager(EnvironmentPath.getDataSetFile(ruleType), getActualDataSources());
- }
-
- @BeforeClass
- public static void initDatabases() throws IOException, JAXBException {
- SchemaEnvironmentManager.createDatabases();
+ public ProxyGeneralDDLIT(final String parentPath, final DDLIntegrateTestCaseAssertion assertion, final String ruleType,
+ final String databaseType, final SQLCaseType caseType, final String sql) throws IOException, JAXBException, SQLException, ParseException {
+ super(parentPath, assertion, ruleType, DatabaseTypeRegistry.getActualDatabaseType(databaseType), caseType, sql);
}
- @AfterClass
- public static void destroyDatabases() throws IOException, JAXBException {
- SchemaEnvironmentManager.dropDatabases();
+ @Parameters(name = "{2} -> {3} -> {4} -> {5}")
+ public static Collection<Object[]> getParameters() {
+ return IntegrateTestEnvironment.getInstance().isProxyEnvironment() ? IntegrateTestParameters.getParametersWithAssertion(IntegrateTestCaseType.DDL) : Collections.emptyList();
}
- @Before
- public final void initTables() throws SQLException, ParseException, IOException, JAXBException {
- SchemaEnvironmentManager.createTables();
- resetTargetDataSource();
- dataSetEnvironmentManager.load();
+ @SuppressWarnings("JUnitTestMethodWithNoAssertions")
+ @Test
+ public void assertExecuteUpdate() throws SQLException {
+ try (Connection connection = getTargetDataSource().getConnection()) {
+ if (SQLCaseType.Literal == getCaseType()) {
+ connection.createStatement().executeUpdate(getSql());
+ } else {
+ connection.prepareStatement(getSql()).executeUpdate();
+ }
+ assertTableMetaData(connection);
+ } catch (final SQLException ex) {
+ logException(ex);
+ throw ex;
+ }
}
- @After
- public final void destroyTables() throws JAXBException, IOException {
- SchemaEnvironmentManager.dropTables();
+ @SuppressWarnings("JUnitTestMethodWithNoAssertions")
+ @Test
+ public void assertExecute() throws SQLException {
+ try (Connection connection = getTargetDataSource().getConnection()) {
+ if (SQLCaseType.Literal == getCaseType()) {
+ connection.createStatement().execute(getSql());
+ } else {
+ connection.prepareStatement(getSql()).execute();
+ }
+ assertTableMetaData(connection);
+ } catch (final SQLException ex) {
+ logException(ex);
+ throw ex;
+ }
}
- protected final void assertTableMetaData(final Connection connection) throws SQLException {
+ private void assertTableMetaData(final Connection connection) throws SQLException {
String tableName = ((DDLIntegrateTestCaseAssertion) getAssertion()).getTable();
- List<DataSetColumn> actualColumns = getActualColumns(connection, tableName);
- List<DataSetIndex> actualIndexes = getActualIndexes(connection, tableName);
- if (actualColumns.isEmpty() || actualIndexes.isEmpty()) {
- assertIfDropTable(actualColumns);
- assertIfDropIndex(actualIndexes);
+ Optional<DataSetMetadata> expected = getDataSet().findMetadata(tableName);
+ if (!expected.isPresent()) {
+ assertFalse(containsTable(connection, tableName));
return;
}
- try {
- assertTableMetaData(actualColumns, actualIndexes, getDataSet().findMetadata(tableName));
- } catch (final AssertionError ex) {
- log.error("[ERROR] SQL::{}, Parameter::{}, Expect::{}", getCaseIdentifier(), getAssertion().getParameters(), getAssertion().getExpectedDataFile());
- throw ex;
- }
+ assertTableMetaData(getActualColumns(connection, tableName), getActualIndexes(connection, tableName), expected.get());
}
private void assertTableMetaData(final List<DataSetColumn> actualColumns, final List<DataSetIndex> actualIndexes, final DataSetMetadata expected) {
@@ -108,12 +109,12 @@ public abstract class BaseDDLIT extends SingleIT {
}
}
+ private boolean containsTable(final Connection connection, final String tableName) throws SQLException {
+ return connection.getMetaData().getTables(null, null, tableName, new String[] {"TABLE"}).next();
+ }
+
private List<DataSetColumn> getActualColumns(final Connection connection, final String tableName) throws SQLException {
DatabaseMetaData metaData = connection.getMetaData();
- boolean isTableExisted = metaData.getTables(null, null, tableName, new String[] {"TABLE"}).next();
- if (!isTableExisted) {
- return Collections.emptyList();
- }
try (ResultSet resultSet = metaData.getColumns(null, null, tableName, null)) {
List<DataSetColumn> result = new LinkedList<>();
while (resultSet.next()) {
@@ -141,18 +142,6 @@ public abstract class BaseDDLIT extends SingleIT {
}
}
- private void assertIfDropTable(final List<DataSetColumn> actualColumns) {
- if (getSql().startsWith("DROP TABLE")) {
- assertTrue(actualColumns.isEmpty());
- }
- }
-
- private void assertIfDropIndex(final List<DataSetIndex> actualIndexes) {
- if (getSql().startsWith("DROP INDEX")) {
- assertTrue(actualIndexes.isEmpty());
- }
- }
-
private void assertColumnMetaData(final List<DataSetColumn> actual, final DataSetColumn expect) {
for (DataSetColumn each : actual) {
if (expect.getName().equals(each.getName())) {
@@ -174,11 +163,4 @@ public abstract class BaseDDLIT extends SingleIT {
}
}
}
-
- protected final void dropTableIfExisted(final Connection connection) {
- try (PreparedStatement preparedStatement = connection.prepareStatement(String.format("DROP TABLE %s", ((DDLIntegrateTestCaseAssertion) getAssertion()).getTable()))) {
- preparedStatement.executeUpdate();
- } catch (final SQLException ignored) {
- }
- }
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java
index 8ea3799..b865e7e 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.test.integration.cases.assertion.dml.DMLIntegra
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLValue;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
-import org.apache.shardingsphere.test.integration.engine.util.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.junit.Test;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
index f614354..36e94d8 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
@@ -47,6 +47,7 @@ import java.sql.Statement;
import java.sql.Types;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Collection;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
@@ -131,7 +132,7 @@ public abstract class BaseDMLIT extends SingleIT {
}
}
- private void assertMetaData(final ResultSetMetaData actualMetaData, final List<DataSetColumn> columnMetadataList) throws SQLException {
+ private void assertMetaData(final ResultSetMetaData actualMetaData, final Collection<DataSetColumn> columnMetadataList) throws SQLException {
assertThat(actualMetaData.getColumnCount(), is(columnMetadataList.size()));
int index = 1;
for (DataSetColumn each : columnMetadataList) {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java
index 994977b..7b31fc6 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.test.integration.cases.assertion.IntegrateTestC
import org.apache.shardingsphere.test.integration.cases.assertion.root.IntegrateTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLValue;
import org.apache.shardingsphere.test.integration.engine.BatchIT;
-import org.apache.shardingsphere.test.integration.engine.util.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
index e804ac3..755ae15 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.test.integration.cases.assertion.dml.DMLIntegra
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLValue;
import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
-import org.apache.shardingsphere.test.integration.engine.util.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java
index 9b6fe56..e590be6 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.test.integration.cases.assertion.dql.DQLIntegra
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLValue;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
-import org.apache.shardingsphere.test.integration.engine.util.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.junit.Test;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
index 5973955..1119b12 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
@@ -28,12 +28,11 @@ import org.apache.shardingsphere.test.integration.engine.SingleIT;
import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
-import org.apache.shardingsphere.test.integration.env.datasource.builder.JdbcDataSourceBuilder;
+import org.apache.shardingsphere.test.integration.env.datasource.builder.ActualDataSourceBuilder;
import org.apache.shardingsphere.test.integration.env.schema.SchemaEnvironmentManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import javax.sql.DataSource;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.sql.ResultSet;
@@ -42,11 +41,8 @@ import java.sql.SQLException;
import java.sql.Types;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -72,7 +68,7 @@ public abstract class BaseDQLIT extends SingleIT {
private static void insertData(final DatabaseType databaseType) throws SQLException, ParseException, IOException, JAXBException {
for (String each : IntegrateTestEnvironment.getInstance().getRuleTypes()) {
- new DataSetEnvironmentManager(EnvironmentPath.getDataSetFile(each), createDataSourceMap(databaseType, each)).load();
+ new DataSetEnvironmentManager(EnvironmentPath.getDataSetFile(each), ActualDataSourceBuilder.createActualDataSources(each, databaseType)).load();
}
}
@@ -81,15 +77,6 @@ public abstract class BaseDQLIT extends SingleIT {
SchemaEnvironmentManager.dropDatabases();
}
- private static Map<String, DataSource> createDataSourceMap(final DatabaseType databaseType, final String ruleType) throws IOException, JAXBException {
- Collection<String> dataSourceNames = SchemaEnvironmentManager.getDataSourceNames(ruleType);
- Map<String, DataSource> result = new HashMap<>(dataSourceNames.size(), 1);
- for (String each : dataSourceNames) {
- result.put(each, JdbcDataSourceBuilder.build(each, databaseType));
- }
- return result;
- }
-
protected final void assertResultSet(final ResultSet resultSet) throws SQLException {
List<DataSetColumn> expectedColumns = new LinkedList<>();
for (DataSetMetadata each : getDataSet().getMetadataList()) {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
index 8b4af03..80b73e9 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.test.integration.cases.assertion.dql.DQLIntegra
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLValue;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
-import org.apache.shardingsphere.test.integration.engine.util.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java
index 5b9b167..974592b 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java
@@ -120,7 +120,7 @@ public final class DataSetEnvironmentManager {
return result;
}
- private String generateInsertSQL(final String tableName, final List<DataSetColumn> columnMetadata) {
+ private String generateInsertSQL(final String tableName, final Collection<DataSetColumn> columnMetadata) {
List<String> columnNames = new LinkedList<>();
List<String> placeholders = new LinkedList<>();
for (DataSetColumn each : columnMetadata) {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/JdbcDataSourceBuilder.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ActualDataSourceBuilder.java
similarity index 81%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/JdbcDataSourceBuilder.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ActualDataSourceBuilder.java
index 342ee94..9ed74e4 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/JdbcDataSourceBuilder.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ActualDataSourceBuilder.java
@@ -25,29 +25,51 @@ import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
import org.apache.shardingsphere.test.integration.env.datasource.DatabaseEnvironment;
+import org.apache.shardingsphere.test.integration.env.schema.SchemaEnvironmentManager;
import javax.sql.DataSource;
+import javax.xml.bind.JAXBException;
+import java.io.IOException;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
- * JDBC data source builder.
+ * Actual data source builder.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class JdbcDataSourceBuilder {
+public final class ActualDataSourceBuilder {
private static final DataSourcePoolType DATA_SOURCE_POOL_TYPE = DataSourcePoolType.HikariCP;
private static final Map<DataSourceCacheKey, DataSource> CACHE = new HashMap<>();
/**
- * Build jdbc data source.
+ * Create actual data sources.
+ *
+ * @param ruleType rule type
+ * @param databaseType database type
+ * @return actual data sources map
+ * @throws IOException IO exception
+ * @throws JAXBException JAXB exception
+ */
+ public static Map<String, DataSource> createActualDataSources(final String ruleType, final DatabaseType databaseType) throws IOException, JAXBException {
+ Collection<String> dataSourceNames = SchemaEnvironmentManager.getDataSourceNames(ruleType);
+ Map<String, DataSource> result = new HashMap<>(dataSourceNames.size(), 1);
+ for (String each : dataSourceNames) {
+ result.put(each, build(each, databaseType));
+ }
+ return result;
+ }
+
+ /**
+ * Build actual data source.
*
- * @param name data source name
+ * @param name actual data source name
* @param databaseType database type
- * @return data source
+ * @return actual data source
*/
public static DataSource build(final String name, final DatabaseType databaseType) {
DataSourceCacheKey cacheKey = new DataSourceCacheKey(name, databaseType);
@@ -70,7 +92,7 @@ public final class JdbcDataSourceBuilder {
throw new UnsupportedOperationException(DATA_SOURCE_POOL_TYPE.name());
}
}
-
+
private static DataSource createDBCP(final String dataSourceName, final DatabaseType databaseType, final DatabaseEnvironment databaseEnvironment) {
BasicDataSource result = new BasicDataSource();
result.setDriverClassName(databaseEnvironment.getDriverClassName());
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/schema/SchemaEnvironmentManager.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/schema/SchemaEnvironmentManager.java
index b367fb8..2ac5b4a 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/schema/SchemaEnvironmentManager.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/schema/SchemaEnvironmentManager.java
@@ -23,7 +23,7 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
-import org.apache.shardingsphere.test.integration.env.datasource.builder.JdbcDataSourceBuilder;
+import org.apache.shardingsphere.test.integration.env.datasource.builder.ActualDataSourceBuilder;
import org.h2.tools.RunScript;
import javax.sql.DataSource;
@@ -78,7 +78,7 @@ public final class SchemaEnvironmentManager {
private static void createDatabases(final String ruleType) throws IOException, JAXBException {
SchemaEnvironment schemaEnvironment = unmarshal(EnvironmentPath.getSchemaFile(ruleType));
for (DatabaseType each : IntegrateTestEnvironment.getInstance().getDatabaseEnvironments().keySet()) {
- DataSource dataSource = JdbcDataSourceBuilder.build(null, each);
+ DataSource dataSource = ActualDataSourceBuilder.build(null, each);
executeSQLScript(dataSource, generateCreateDatabaseSQLs(each, schemaEnvironment.getDatabases()));
}
}
@@ -109,7 +109,7 @@ public final class SchemaEnvironmentManager {
private static void dropDatabases(final String ruleType) throws IOException, JAXBException {
SchemaEnvironment schemaEnvironment = unmarshal(EnvironmentPath.getSchemaFile(ruleType));
for (DatabaseType each : IntegrateTestEnvironment.getInstance().getDatabaseEnvironments().keySet()) {
- DataSource dataSource = JdbcDataSourceBuilder.build(null, each);
+ DataSource dataSource = ActualDataSourceBuilder.build(null, each);
executeSQLScript(dataSource, generatePrepareDropDatabaseSQLs(each, schemaEnvironment.getDatabases()));
executeSQLScript(dataSource, generateDropDatabaseSQLs(each, schemaEnvironment.getDatabases()));
}
@@ -155,7 +155,7 @@ public final class SchemaEnvironmentManager {
private static void createTables(final SchemaEnvironment schemaEnvironment, final DatabaseType databaseType) {
for (String each : schemaEnvironment.getDatabases()) {
- DataSource dataSource = JdbcDataSourceBuilder.build(each, databaseType);
+ DataSource dataSource = ActualDataSourceBuilder.build(each, databaseType);
executeSQLScript(dataSource, schemaEnvironment.getTableCreateSQLs());
}
}
@@ -181,7 +181,7 @@ public final class SchemaEnvironmentManager {
private static void dropTables(final SchemaEnvironment schemaEnvironment, final DatabaseType databaseType) {
for (String each : schemaEnvironment.getDatabases()) {
- DataSource dataSource = JdbcDataSourceBuilder.build(each, databaseType);
+ DataSource dataSource = ActualDataSourceBuilder.build(each, databaseType);
executeSQLScript(dataSource, schemaEnvironment.getTableDropSQLs());
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/empty_table.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/drop_table.xml
similarity index 82%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/empty_table.xml
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/drop_table.xml
index 305f43f..f31f346 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/empty_table.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/drop_table.xml
@@ -15,9 +15,4 @@
~ limitations under the License.
-->
-<dataset>
- <metadata table-name="t_order_details">
- <column name="id" type="integer" />
- <column name="description" type="varchar" />
- </metadata>
-</dataset>
+<dataset />
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/empty_table.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/unchanged_table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/empty_table.xml
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/dataset/unchanged_table.xml
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/ddl-integrate-test-cases.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/ddl-integrate-test-cases.xml
index 19635d0..bfe7c30 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/ddl-integrate-test-cases.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/resources/integrate/cases/ddl/ddl-integrate-test-cases.xml
@@ -33,19 +33,19 @@
</ddl-test-case>
<ddl-test-case sql="DROP TABLE t_order_details">
- <assertion init-sql="CREATE TABLE t_order_details(id int, description varchar(10))" table="t_order_details" expected-data-file="empty_table.xml" />
+ <assertion init-sql="CREATE TABLE t_order_details(id int, description varchar(10))" table="t_order_details" expected-data-file="drop_table.xml" />
</ddl-test-case>
<ddl-test-case sql="DROP INDEX t_order_details_index ON t_order_details" db-types="MySQL,SQLServer">
- <assertion init-sql="CREATE TABLE t_order_details(id int, description varchar(10));CREATE INDEX t_order_details_index ON t_order_details(description)" table="t_order_details" expected-data-file="empty_table.xml" />
+ <assertion init-sql="CREATE TABLE t_order_details(id int, description varchar(10));CREATE INDEX t_order_details_index ON t_order_details(description)" table="t_order_details" expected-data-file="unchanged_table.xml" />
</ddl-test-case>
<ddl-test-case sql="DROP INDEX order_index" db-types="PostgreSQL,Oracle">
- <assertion init-sql="CREATE TABLE t_order_details(id int, description varchar(10));CREATE INDEX t_order_details_index ON t_order_details(description)" table="t_order_details" expected-data-file="empty_table.xml" />
+ <assertion init-sql="CREATE TABLE t_order_details(id int, description varchar(10));CREATE INDEX t_order_details_index ON t_order_details(description)" table="t_order_details" expected-data-file="unchanged_table.xml" />
</ddl-test-case>
<ddl-test-case sql="TRUNCATE TABLE t_order_details">
- <assertion init-sql="CREATE TABLE t_order_details(id int, description varchar(10))" table="t_order_details" expected-data-file="empty_table.xml" />
+ <assertion init-sql="CREATE TABLE t_order_details(id int, description varchar(10))" table="t_order_details" expected-data-file="unchanged_table.xml" />
</ddl-test-case>
<!-- TODO add single table DDL test cases -->