You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ni...@apache.org on 2020/12/30 13:00:22 UTC
[shardingsphere] branch master updated: Refactor DQL IT (#8835)
This is an automated email from the ASF dual-hosted git repository.
nicholasjiang 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 e1ac4cd Refactor DQL IT (#8835)
e1ac4cd is described below
commit e1ac4cdb7023332a26878aefa9dfedb95c3d8d44
Author: Liang Zhang <te...@163.com>
AuthorDate: Wed Dec 30 20:59:53 2020 +0800
Refactor DQL IT (#8835)
* Rename DataSetEnvironmentManager.fillData
* Rename BaseDQLIT.fillData
* Rename fillData
* Remove useless todo
* Refactor BaseDQLIT
---
.../integration/cases/dataset/row/DataSetRow.java | 2 +
.../test/integration/engine/it/BatchIT.java | 4 +-
.../test/integration/engine/it/ddl/BaseDDLIT.java | 2 +-
.../test/integration/engine/it/dml/BaseDMLIT.java | 4 +-
.../test/integration/engine/it/dql/BaseDQLIT.java | 89 +++++++++++++---------
.../integration/engine/it/dql/GeneralDQLIT.java | 4 +-
.../env/dataset/DataSetEnvironmentManager.java | 4 +-
7 files changed, 63 insertions(+), 46 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/row/DataSetRow.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/row/DataSetRow.java
index f2faec8..c580176 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/row/DataSetRow.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/row/DataSetRow.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.test.integration.cases.dataset.row;
import com.google.common.base.Splitter;
import lombok.Getter;
+import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -29,6 +30,7 @@ import java.util.List;
* Data set row.
*/
@Getter
+@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class DataSetRow {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BatchIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BatchIT.java
index ce343e1..d2a9cc7 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BatchIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BatchIT.java
@@ -93,8 +93,8 @@ public abstract class BatchIT extends BaseIT {
}
@Before
- public void insertData() throws SQLException, ParseException {
- dataSetEnvironmentManager.load();
+ public void fillData() throws SQLException, ParseException {
+ dataSetEnvironmentManager.fillData();
}
@After
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/ddl/BaseDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/ddl/BaseDDLIT.java
index 9073e59..3d8408a 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/ddl/BaseDDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/ddl/BaseDDLIT.java
@@ -61,7 +61,7 @@ public abstract class BaseDDLIT extends SingleIT {
@Before
public final void initTables() throws SQLException, ParseException, IOException, JAXBException {
SchemaEnvironmentManager.createTables();
- dataSetEnvironmentManager.load();
+ dataSetEnvironmentManager.fillData();
try (Connection connection = getTargetDataSource().getConnection()) {
executeInitSQLs(connection);
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dml/BaseDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dml/BaseDMLIT.java
index bea14f5..ae68d2d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dml/BaseDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dml/BaseDMLIT.java
@@ -75,8 +75,8 @@ public abstract class BaseDMLIT extends SingleIT {
}
@Before
- public void insertData() throws SQLException, ParseException {
- dataSetEnvironmentManager.load();
+ public void fillData() throws SQLException, ParseException {
+ dataSetEnvironmentManager.fillData();
}
@After
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/BaseDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/BaseDQLIT.java
index 142e8c1..d07e13d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/BaseDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/BaseDQLIT.java
@@ -40,6 +40,7 @@ import java.sql.SQLException;
import java.sql.Types;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -55,18 +56,17 @@ public abstract class BaseDQLIT extends SingleIT {
}
@BeforeClass
- public static void insertData() throws IOException, JAXBException, SQLException, ParseException {
+ public static void fillData() throws IOException, JAXBException, SQLException, ParseException {
SchemaEnvironmentManager.createDatabases();
- SchemaEnvironmentManager.dropTables();
SchemaEnvironmentManager.createTables();
for (DatabaseType each : IntegrateTestEnvironment.getInstance().getDatabaseEnvironments().keySet()) {
- insertData(each);
+ fillData(each);
}
}
- private static void insertData(final DatabaseType databaseType) throws SQLException, ParseException, IOException, JAXBException {
+ private static void fillData(final DatabaseType databaseType) throws SQLException, ParseException, IOException, JAXBException {
for (String each : IntegrateTestEnvironment.getInstance().getRuleTypes()) {
- new DataSetEnvironmentManager(EnvironmentPath.getDataSetFile(each), ActualDataSourceBuilder.createActualDataSources(each, databaseType)).load();
+ new DataSetEnvironmentManager(EnvironmentPath.getDataSetFile(each), ActualDataSourceBuilder.createActualDataSources(each, databaseType)).fillData();
}
}
@@ -76,50 +76,65 @@ public abstract class BaseDQLIT extends SingleIT {
}
protected final void assertResultSet(final ResultSet resultSet) throws SQLException {
- List<DataSetColumn> expectedColumns = new LinkedList<>();
+ assertMetaData(resultSet.getMetaData(), getExpectedColumns());
+ assertRows(resultSet, getDataSet().getRows());
+ }
+
+ private Collection<DataSetColumn> getExpectedColumns() {
+ Collection<DataSetColumn> result = new LinkedList<>();
for (DataSetMetadata each : getDataSet().getMetadataList()) {
- expectedColumns.addAll(each.getColumns());
+ result.addAll(each.getColumns());
}
- assertMetaData(resultSet.getMetaData(), expectedColumns);
- assertRows(resultSet, getDataSet().getRows());
+ return result;
}
- private void assertMetaData(final ResultSetMetaData actualMetaData, final List<DataSetColumn> expectedColumns) throws SQLException {
- // TODO fix shadow
+ private void assertMetaData(final ResultSetMetaData actual, final Collection<DataSetColumn> expected) throws SQLException {
+ // TODO Fix shadow
if ("shadow".equals(getRuleType())) {
return;
}
- // Unconfigured Table doesn't have column info, should skip check column info
- if (0 == actualMetaData.getColumnCount()) {
- return;
- }
- assertThat(actualMetaData.getColumnCount(), is(expectedColumns.size()));
+ assertThat(actual.getColumnCount(), is(expected.size()));
int index = 1;
- for (DataSetColumn each : expectedColumns) {
- assertThat(actualMetaData.getColumnLabel(index++).toLowerCase(), is(each.getName().toLowerCase()));
+ for (DataSetColumn each : expected) {
+ assertThat(actual.getColumnLabel(index++).toLowerCase(), is(each.getName().toLowerCase()));
}
}
- private void assertRows(final ResultSet actualResultSet, final List<DataSetRow> expectedDatSetRows) throws SQLException {
- int count = 0;
- ResultSetMetaData actualMetaData = actualResultSet.getMetaData();
- while (actualResultSet.next()) {
- int index = 1;
- assertTrue("Size of actual result set is different with size of expected dat set rows.", count < expectedDatSetRows.size());
- for (String each : expectedDatSetRows.get(count).getValues()) {
- if (Types.DATE == actualResultSet.getMetaData().getColumnType(index)) {
- if (!NOT_VERIFY_FLAG.equals(each)) {
- assertThat(new SimpleDateFormat("yyyy-MM-dd").format(actualResultSet.getDate(index)), is(each));
- assertThat(new SimpleDateFormat("yyyy-MM-dd").format(actualResultSet.getDate(actualMetaData.getColumnLabel(index))), is(each));
- }
- } else {
- assertThat(String.valueOf(actualResultSet.getObject(index)), is(each));
- assertThat(String.valueOf(actualResultSet.getObject(actualMetaData.getColumnLabel(index))), is(each));
- }
- index++;
+ private void assertRows(final ResultSet actual, final List<DataSetRow> expected) throws SQLException {
+ int rowCount = 0;
+ ResultSetMetaData actualMetaData = actual.getMetaData();
+ while (actual.next()) {
+ assertTrue("Size of actual result set is different with size of expected dat set rows.", rowCount < expected.size());
+ assertRow(actual, actualMetaData, expected.get(rowCount));
+ rowCount++;
+ }
+ assertThat("Size of actual result set is different with size of expected dat set rows.", rowCount, is(expected.size()));
+ }
+
+ private void assertRow(final ResultSet actual, final ResultSetMetaData actualMetaData, final DataSetRow expected) throws SQLException {
+ int columnIndex = 1;
+ for (String each : expected.getValues()) {
+ String columnLabel = actualMetaData.getColumnLabel(columnIndex);
+ if (Types.DATE == actual.getMetaData().getColumnType(columnIndex)) {
+ assertDateValue(actual, columnIndex, columnLabel, each);
+ } else {
+ assertObjectValue(actual, columnIndex, columnLabel, each);
}
- count++;
+ columnIndex++;
}
- assertThat("Size of actual result set is different with size of expected dat set rows.", count, is(expectedDatSetRows.size()));
+ }
+
+ private void assertDateValue(final ResultSet actual, final int columnIndex, final String columnLabel, final String expected) throws SQLException {
+ if (NOT_VERIFY_FLAG.equals(expected)) {
+ return;
+ }
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ assertThat(dateFormat.format(actual.getDate(columnIndex)), is(expected));
+ assertThat(dateFormat.format(actual.getDate(columnLabel)), is(expected));
+ }
+
+ private void assertObjectValue(final ResultSet actual, final int columnIndex, final String columnLabel, final String expected) throws SQLException {
+ assertThat(String.valueOf(actual.getObject(columnIndex)), is(expected));
+ assertThat(String.valueOf(actual.getObject(columnLabel)), is(expected));
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/GeneralDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/GeneralDQLIT.java
index 8fa4eab..aa5e460 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/GeneralDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/GeneralDQLIT.java
@@ -96,7 +96,7 @@ public final class GeneralDQLIT extends BaseDQLIT {
private void assertExecuteForStatement(final Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
- assertTrue("Not a DQL statement.", statement.execute(getSql()));
+ assertTrue("Not a query statement.", statement.execute(getSql()));
try (ResultSet resultSet = statement.getResultSet()) {
assertResultSet(resultSet);
}
@@ -108,7 +108,7 @@ public final class GeneralDQLIT extends BaseDQLIT {
for (SQLValue each : assertion.getSQLValues()) {
preparedStatement.setObject(each.getIndex(), each.getValue());
}
- assertTrue("Not a DQL statement.", preparedStatement.execute());
+ assertTrue("Not a query statement.", preparedStatement.execute());
try (ResultSet resultSet = preparedStatement.getResultSet()) {
assertResultSet(resultSet);
}
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 974592b..24ffce2 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
@@ -78,12 +78,12 @@ public final class DataSetEnvironmentManager {
}
/**
- * Load data.
+ * Fill data.
*
* @throws SQLException SQL exception
* @throws ParseException parse exception
*/
- public void load() throws SQLException, ParseException {
+ public void fillData() throws SQLException, ParseException {
Map<DataNode, List<DataSetRow>> dataNodeListMap = getDataSetRowMap();
List<Callable<Void>> insertTasks = new LinkedList<>();
for (Entry<DataNode, List<DataSetRow>> entry : dataNodeListMap.entrySet()) {