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 b428f9a Add dal test engine (#9090)
b428f9a is described below
commit b428f9a48ce4ec41b71fd41c92fddbaf8c6dd1aa
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jan 19 18:38:05 2021 +0800
Add dal test engine (#9090)
---
.../test/integration/engine/it/dal/BaseDALIT.java | 113 +++++++++++++++++++++
.../integration/engine/it/dal/GeneralDALIT.java | 74 ++++++++++++++
.../cases/dal/dal-integration-test-cases.xml | 21 ++++
.../cases/dal/dataset/db/mysql/show_databases.xml | 23 +++++
.../mysql/show_databases.xml | 23 +++++
.../dataset/replica_query/mysql/show_databases.xml | 23 +++++
.../cases/dal/dataset/tbl/mysql/show_databases.xml | 23 +++++
7 files changed, 300 insertions(+)
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dal/BaseDALIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dal/BaseDALIT.java
new file mode 100644
index 0000000..29116b4
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dal/BaseDALIT.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.it.dal;
+
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import
org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCaseAssertion;
+import
org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetColumn;
+import
org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetMetadata;
+import org.apache.shardingsphere.test.integration.cases.dataset.row.DataSetRow;
+import org.apache.shardingsphere.test.integration.engine.it.SingleIT;
+import org.apache.shardingsphere.test.integration.engine.param.SQLExecuteType;
+
+import javax.xml.bind.JAXBException;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+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;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public abstract class BaseDALIT extends SingleIT {
+
+ protected BaseDALIT(final String parentPath, final
IntegrationTestCaseAssertion assertion, final String adapter, final String
scenario,
+ final DatabaseType databaseType, final SQLExecuteType
sqlExecuteType, final String sql) throws IOException, JAXBException,
SQLException, ParseException {
+ super(parentPath, assertion, adapter, scenario, databaseType,
sqlExecuteType, sql);
+ }
+
+ protected final void assertResultSet(final ResultSet resultSet) throws
SQLException {
+ assertMetaData(resultSet.getMetaData(), getExpectedColumns());
+ assertRows(resultSet, getDataSet().getRows());
+ }
+
+ private Collection<DataSetColumn> getExpectedColumns() {
+ Collection<DataSetColumn> result = new LinkedList<>();
+ for (DataSetMetadata each : getDataSet().getMetadataList()) {
+ result.addAll(each.getColumns());
+ }
+ return result;
+ }
+
+ private void assertMetaData(final ResultSetMetaData actual, final
Collection<DataSetColumn> expected) throws SQLException {
+ // TODO Fix shadow
+ if ("shadow".equals(getScenario())) {
+ return;
+ }
+ assertThat(actual.getColumnCount(), is(expected.size()));
+ int index = 1;
+ for (DataSetColumn each : expected) {
+ assertThat(actual.getColumnLabel(index++).toLowerCase(),
is(each.getName().toLowerCase()));
+ }
+ }
+
+ 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);
+ }
+ columnIndex++;
+ }
+ }
+
+ 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-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dal/GeneralDALIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dal/GeneralDALIT.java
new file mode 100644
index 0000000..9dfd0d4
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dal/GeneralDALIT.java
@@ -0,0 +1,74 @@
+/*
+ * 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.it.dal;
+
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.test.integration.cases.SQLCommandType;
+import
org.apache.shardingsphere.test.integration.cases.assertion.IntegrationTestCaseAssertion;
+import
org.apache.shardingsphere.test.integration.engine.param.ParameterizedArrayFactory;
+import org.apache.shardingsphere.test.integration.engine.param.SQLExecuteType;
+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.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class GeneralDALIT extends BaseDALIT {
+
+ public GeneralDALIT(final String parentPath, final
IntegrationTestCaseAssertion assertion, final String adapter, final String
scenario,
+ final String databaseType, final SQLExecuteType
sqlExecuteType, final String sql) throws IOException, JAXBException,
SQLException, ParseException {
+ super(parentPath, assertion, adapter, scenario,
DatabaseTypeRegistry.getActualDatabaseType(databaseType), sqlExecuteType, sql);
+ }
+
+ @Parameters(name = "{2}: {3} -> {4} -> {5} -> {6}")
+ public static Collection<Object[]> getParameters() {
+ return
ParameterizedArrayFactory.getAssertionParameterizedArray(SQLCommandType.DAL).stream()
+ .filter(each -> "proxy".equals(each[2]) &&
SQLExecuteType.Literal == each[5]).collect(Collectors.toList());
+ }
+
+ @SuppressWarnings("JUnitTestMethodWithNoAssertions")
+ @Test
+ public void assertExecute() throws SQLException {
+ try (Connection connection = getTargetDataSource().getConnection()) {
+ assertExecuteForStatement(connection);
+ }
+ }
+
+ private void assertExecuteForStatement(final Connection connection) throws
SQLException {
+ try (Statement statement = connection.createStatement()) {
+ boolean isQuery = statement.execute(getSql());
+ if (isQuery) {
+ try (ResultSet resultSet = statement.getResultSet()) {
+ assertResultSet(resultSet);
+ }
+ } else {
+ assertThat(statement.getUpdateCount(), is(0));
+ }
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dal-integration-test-cases.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dal-integration-test-cases.xml
new file mode 100644
index 0000000..914c19e
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dal-integration-test-cases.xml
@@ -0,0 +1,21 @@
+<!--
+ ~ 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.
+ -->
+<integration-test-cases>
+ <test-case sql="SHOW DATABASES" db-types="MySQL">
+ <assertion expected-data-file="show_databases.xml" />
+ </test-case>
+</integration-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/db/mysql/show_databases.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/db/mysql/show_databases.xml
new file mode 100644
index 0000000..8010153
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/db/mysql/show_databases.xml
@@ -0,0 +1,23 @@
+<!--
+ ~ 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.
+ -->
+
+<dataset>
+ <metadata>
+ <column name="schema_name" />
+ </metadata>
+ <row values="db" />
+</dataset>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/dbtbl_with_replica_query/mysql/show_databases.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/dbtbl_with_replica_query/mysql/show_databases.xml
new file mode 100644
index 0000000..9e50cae
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/dbtbl_with_replica_query/mysql/show_databases.xml
@@ -0,0 +1,23 @@
+<!--
+ ~ 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.
+ -->
+
+<dataset>
+ <metadata>
+ <column name="schema_name" />
+ </metadata>
+ <row values="dbtbl_with_replica_query" />
+</dataset>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/replica_query/mysql/show_databases.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/replica_query/mysql/show_databases.xml
new file mode 100644
index 0000000..76f2d41
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/replica_query/mysql/show_databases.xml
@@ -0,0 +1,23 @@
+<!--
+ ~ 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.
+ -->
+
+<dataset>
+ <metadata>
+ <column name="schema_name" />
+ </metadata>
+ <row values="replica_query" />
+</dataset>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/tbl/mysql/show_databases.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/tbl/mysql/show_databases.xml
new file mode 100644
index 0000000..e294b78
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dal/dataset/tbl/mysql/show_databases.xml
@@ -0,0 +1,23 @@
+<!--
+ ~ 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.
+ -->
+
+<dataset>
+ <metadata>
+ <column name="schema_name" />
+ </metadata>
+ <row values="tbl" />
+</dataset>