From 2c3d56a23f52017e47f713f786244bc68b489234 Mon Sep 17 00:00:00 2001 From: Cong Hu Date: Thu, 1 Aug 2024 10:23:13 +0800 Subject: [PATCH] Remove the dependency on E2ETestParameter from E2EContainerComposer. (#32345) --- .../composer/BatchE2EContainerComposer.java | 112 ------------ .../engine/composer/E2EContainerComposer.java | 17 +- .../SingleE2EContext.java} | 19 +- .../test/e2e/engine/type/DALE2EIT.java | 36 ++-- .../test/e2e/engine/type/DCLE2EIT.java | 29 +-- .../test/e2e/engine/type/DDLE2EIT.java | 91 +++++----- .../test/e2e/engine/type/RALE2EIT.java | 71 ++++---- .../test/e2e/engine/type/RDLE2EIT.java | 63 ++++--- .../test/e2e/engine/type/RQLE2EIT.java | 27 +-- .../engine/type/dml/AdditionalDMLE2EIT.java | 167 ++++++++++-------- .../e2e/engine/type/dml/BaseDMLE2EIT.java | 109 +++++++++--- .../e2e/engine/type/dml/BatchDMLE2EIT.java | 54 ++++-- .../e2e/engine/type/dml/GeneralDMLE2EIT.java | 49 ++--- .../engine/type/dql/AdditionalDQLE2EIT.java | 113 ++++++------ .../e2e/engine/type/dql/BaseDQLE2EIT.java | 28 +-- .../e2e/engine/type/dql/GeneralDQLE2EIT.java | 90 +++++----- 16 files changed, 562 insertions(+), 513 deletions(-) delete mode 100644 test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/BatchE2EContainerComposer.java rename test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/{composer/SingleE2EContainerComposer.java => context/SingleE2EContext.java} (79%) diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/BatchE2EContainerComposer.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/BatchE2EContainerComposer.java deleted file mode 100644 index 301df6d0557b0..0000000000000 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/BatchE2EContainerComposer.java +++ /dev/null @@ -1,112 +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.e2e.engine.composer; - -import org.apache.shardingsphere.test.e2e.cases.casse.assertion.E2ETestCaseAssertion; -import org.apache.shardingsphere.test.e2e.cases.dataset.DataSet; -import org.apache.shardingsphere.test.e2e.cases.dataset.DataSetLoader; -import org.apache.shardingsphere.test.e2e.cases.dataset.row.DataSetRow; -import org.apache.shardingsphere.test.e2e.env.DataSetEnvironmentManager; -import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath; -import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type; -import org.apache.shardingsphere.test.e2e.framework.param.model.CaseTestParameter; - -import javax.xml.bind.JAXBException; -import java.io.IOException; -import java.sql.Statement; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Set; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * Batch E2E container composer. - */ -public final class BatchE2EContainerComposer extends E2EContainerComposer implements AutoCloseable { - - private final Collection dataSets = new LinkedList<>(); - - private final DataSetEnvironmentManager dataSetEnvironmentManager; - - public BatchE2EContainerComposer(final CaseTestParameter testParam) throws JAXBException, IOException { - super(testParam); - for (E2ETestCaseAssertion each : testParam.getTestCaseContext().getTestCase().getAssertions()) { - dataSets.add(DataSetLoader.load(testParam.getTestCaseContext().getParentPath(), testParam.getScenario(), testParam.getDatabaseType(), testParam.getMode(), each.getExpectedDataFile())); - } - dataSetEnvironmentManager = new DataSetEnvironmentManager(new ScenarioDataPath(testParam.getScenario()).getDataSetFile(Type.ACTUAL), getActualDataSourceMap(), testParam.getDatabaseType()); - dataSetEnvironmentManager.fillData(); - } - - /** - * Get data set. - * - * @param actualUpdateCounts actual update counts - * @return data set - */ - public DataSet getDataSet(final int[] actualUpdateCounts) { - Collection dataSets = new LinkedList<>(); - assertThat(actualUpdateCounts.length, is(this.dataSets.size())); - int count = 0; - for (DataSet each : this.dataSets) { - if (Statement.SUCCESS_NO_INFO != actualUpdateCounts[count]) { - assertThat(actualUpdateCounts[count], is(each.getUpdateCount())); - } - dataSets.add(each); - count++; - } - return mergeDataSets(dataSets); - } - - private DataSet mergeDataSets(final Collection dataSets) { - DataSet result = new DataSet(); - Set existedRows = new HashSet<>(); - for (DataSet each : dataSets) { - mergeMetaData(each, result); - mergeRow(each, result, existedRows); - } - sortRow(result); - return result; - } - - private void mergeMetaData(final DataSet original, final DataSet dist) { - if (dist.getMetaDataList().isEmpty()) { - dist.getMetaDataList().addAll(original.getMetaDataList()); - } - } - - private void mergeRow(final DataSet original, final DataSet dist, final Set existedRows) { - for (DataSetRow each : original.getRows()) { - if (existedRows.add(each)) { - dist.getRows().add(each); - } - } - } - - private void sortRow(final DataSet dataSet) { - dataSet.getRows().sort(Comparator.comparingLong(o -> Long.parseLong(o.splitValues(",").get(0)))); - } - - @Override - public void close() { - dataSetEnvironmentManager.cleanData(); - } -} diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/E2EContainerComposer.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/E2EContainerComposer.java index c1e036f2d55f7..d39bc6b82f937 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/E2EContainerComposer.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/E2EContainerComposer.java @@ -21,13 +21,13 @@ import lombok.Getter; import lombok.SneakyThrows; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.test.e2e.container.compose.ContainerComposer; import org.apache.shardingsphere.test.e2e.container.compose.ContainerComposerRegistry; import org.apache.shardingsphere.test.e2e.engine.TotalSuitesCountCalculator; import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath; -import org.apache.shardingsphere.test.e2e.framework.param.model.E2ETestParameter; import org.h2.tools.RunScript; import javax.sql.DataSource; @@ -45,7 +45,7 @@ * E2E container composer. */ @Getter -public abstract class E2EContainerComposer { +public final class E2EContainerComposer { public static final String NOT_VERIFY_FLAG = "NOT_VERIFY"; @@ -66,23 +66,22 @@ public abstract class E2EContainerComposer { private final Map expectedDataSourceMap; - protected E2EContainerComposer(final E2ETestParameter testParam) { - containerComposer = CONTAINER_COMPOSER_REGISTRY.getContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), - AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + public E2EContainerComposer(final String key, final String scenario, final DatabaseType databaseType, final AdapterMode adapterMode, final AdapterType adapterType) { + containerComposer = CONTAINER_COMPOSER_REGISTRY.getContainerComposer(key, scenario, databaseType, adapterMode, adapterType); containerComposer.start(); actualDataSourceMap = containerComposer.getActualDataSourceMap(); targetDataSource = containerComposer.getTargetDataSource(); expectedDataSourceMap = containerComposer.getExpectedDataSourceMap(); - executeLogicDatabaseInitSQLFileOnlyOnce(testParam, targetDataSource); + executeLogicDatabaseInitSQLFileOnlyOnce(key, scenario, databaseType, targetDataSource); } @SneakyThrows({SQLException.class, IOException.class}) - private void executeLogicDatabaseInitSQLFileOnlyOnce(final E2ETestParameter testParam, final DataSource targetDataSource) { - Optional logicDatabaseInitSQLFile = new ScenarioDataPath(testParam.getScenario()).findActualDatabaseInitSQLFile(DefaultDatabase.LOGIC_NAME, testParam.getDatabaseType()); + private void executeLogicDatabaseInitSQLFileOnlyOnce(final String key, final String scenario, final DatabaseType databaseType, final DataSource targetDataSource) { + Optional logicDatabaseInitSQLFile = new ScenarioDataPath(scenario).findActualDatabaseInitSQLFile(DefaultDatabase.LOGIC_NAME, databaseType); if (!logicDatabaseInitSQLFile.isPresent()) { return; } - String cacheKey = testParam.getKey() + "-" + System.identityHashCode(targetDataSource); + String cacheKey = key + "-" + System.identityHashCode(targetDataSource); if (!INITIALIZED_SUITES.contains(cacheKey)) { synchronized (INITIALIZED_SUITES) { if (!INITIALIZED_SUITES.contains(cacheKey)) { diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/SingleE2EContainerComposer.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/context/SingleE2EContext.java similarity index 79% rename from test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/SingleE2EContainerComposer.java rename to test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/context/SingleE2EContext.java index 69d3f687a5e61..869a09409c703 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/composer/SingleE2EContainerComposer.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/context/SingleE2EContext.java @@ -15,25 +15,22 @@ * limitations under the License. */ -package org.apache.shardingsphere.test.e2e.engine.composer; +package org.apache.shardingsphere.test.e2e.engine.context; import lombok.Getter; -import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import org.apache.shardingsphere.test.e2e.cases.casse.assertion.E2ETestCaseAssertion; import org.apache.shardingsphere.test.e2e.cases.dataset.DataSet; import org.apache.shardingsphere.test.e2e.cases.dataset.DataSetLoader; import org.apache.shardingsphere.test.e2e.cases.value.SQLValue; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; +import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -/** - * Single E2E container composer. - */ @Getter -public final class SingleE2EContainerComposer extends E2EContainerComposer { +public class SingleE2EContext { private final String sql; @@ -43,20 +40,13 @@ public final class SingleE2EContainerComposer extends E2EContainerComposer { private final DataSet dataSet; - private final DataSet generatedKeyDataSet; - - public SingleE2EContainerComposer(final AssertionTestParameter testParam) { - super(testParam); + public SingleE2EContext(final AssertionTestParameter testParam) { sql = testParam.getTestCaseContext().getTestCase().getSql(); sqlExecuteType = testParam.getSqlExecuteType(); assertion = testParam.getAssertion(); dataSet = null == assertion || null == assertion.getExpectedDataFile() ? null : DataSetLoader.load(testParam.getTestCaseContext().getParentPath(), testParam.getScenario(), testParam.getDatabaseType(), testParam.getMode(), assertion.getExpectedDataFile()); - generatedKeyDataSet = null == assertion || null == assertion.getExpectedGeneratedKeyDataFile() - ? null - : DataSetLoader.load( - testParam.getTestCaseContext().getParentPath(), testParam.getScenario(), testParam.getDatabaseType(), testParam.getMode(), assertion.getExpectedGeneratedKeyDataFile()); } /** @@ -72,4 +62,5 @@ private String getLiteralSQL(final String sql) { List params = null == assertion ? Collections.emptyList() : assertion.getSQLValues().stream().map(SQLValue::toString).collect(Collectors.toList()); return params.isEmpty() ? sql : String.format(sql.replace("%", "ÿ").replace("?", "%s"), params.toArray()).replace("ÿ", "%").replace("%%", "%").replace("'%'", "'%%'"); } + } diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DALE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DALE2EIT.java index fdbb7bbd767c2..df611de53956d 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DALE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DALE2EIT.java @@ -18,6 +18,9 @@ package org.apache.shardingsphere.test.e2e.engine.type; import org.apache.shardingsphere.infra.util.datetime.DateTimeFormatterFactory; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetColumn; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetMetaData; @@ -25,7 +28,6 @@ import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; import org.junit.jupiter.api.condition.EnabledIf; @@ -57,40 +59,42 @@ void assertExecute(final AssertionTestParameter testParam) throws SQLException { if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - assertExecute(containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + assertExecute(containerComposer, singleE2EContext); } - private void assertExecute(final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecute(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { try (Statement statement = connection.createStatement()) { - statement.execute(containerComposer.getSQL()); - assertExecuteResult(containerComposer, statement); + statement.execute(singleE2EContext.getSQL()); + assertExecuteResult(singleE2EContext, statement); } } } - private void assertExecuteResult(final SingleE2EContainerComposer containerComposer, final Statement statement) throws SQLException { + private void assertExecuteResult(final SingleE2EContext singleE2EContext, final Statement statement) throws SQLException { try (ResultSet resultSet = statement.getResultSet()) { - if (null == containerComposer.getAssertion().getAssertionSQL()) { - assertResultSet(containerComposer, resultSet); + if (null == singleE2EContext.getAssertion().getAssertionSQL()) { + assertResultSet(singleE2EContext, resultSet); } else { - statement.execute(containerComposer.getAssertion().getAssertionSQL().getSql()); + statement.execute(singleE2EContext.getAssertion().getAssertionSQL().getSql()); try (ResultSet assertionSQLResultSet = statement.getResultSet()) { - assertResultSet(containerComposer, assertionSQLResultSet); + assertResultSet(singleE2EContext, assertionSQLResultSet); } } } } - private void assertResultSet(final SingleE2EContainerComposer containerComposer, final ResultSet resultSet) throws SQLException { - assertMetaData(resultSet.getMetaData(), getExpectedColumns(containerComposer)); - assertRows(resultSet, containerComposer.getDataSet().getRows()); + private void assertResultSet(final SingleE2EContext singleE2EContext, final ResultSet resultSet) throws SQLException { + assertMetaData(resultSet.getMetaData(), getExpectedColumns(singleE2EContext)); + assertRows(resultSet, singleE2EContext.getDataSet().getRows()); } - private Collection getExpectedColumns(final SingleE2EContainerComposer containerComposer) { + private Collection getExpectedColumns(final SingleE2EContext singleE2EContext) { Collection result = new LinkedList<>(); - for (DataSetMetaData each : containerComposer.getDataSet().getMetaDataList()) { + for (DataSetMetaData each : singleE2EContext.getDataSet().getMetaDataList()) { result.addAll(each.getColumns()); } return result; diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DCLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DCLE2EIT.java index e326ffdfc0c79..bc92a33e46020 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DCLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DCLE2EIT.java @@ -17,11 +17,14 @@ package org.apache.shardingsphere.test.e2e.engine.type; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; import org.apache.shardingsphere.test.e2e.env.runtime.scenario.authority.AuthorityEnvironmentManager; import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioCommonPath; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; @@ -48,18 +51,20 @@ void assertExecuteUpdate(final AssertionTestParameter testParam) throws SQLExcep if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); try ( AuthorityEnvironmentManager ignored = new AuthorityEnvironmentManager( new ScenarioCommonPath(testParam.getScenario()).getAuthorityFile(), containerComposer.getActualDataSourceMap(), testParam.getDatabaseType())) { - assertExecuteUpdate(containerComposer); + assertExecuteUpdate(containerComposer, singleE2EContext); } } - private void assertExecuteUpdate(final SingleE2EContainerComposer containerComposer) throws SQLException { - String sql = containerComposer.getSQL(); + private void assertExecuteUpdate(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { + String sql = singleE2EContext.getSQL(); try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - if (SQLExecuteType.Literal == containerComposer.getSqlExecuteType()) { + if (SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType()) { try (Statement statement = connection.createStatement()) { statement.executeUpdate(sql); } @@ -79,18 +84,20 @@ void assertExecute(final AssertionTestParameter testParam) throws SQLException, if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); try ( AuthorityEnvironmentManager ignored = new AuthorityEnvironmentManager( new ScenarioCommonPath(testParam.getScenario()).getAuthorityFile(), containerComposer.getActualDataSourceMap(), testParam.getDatabaseType())) { - assertExecute(containerComposer); + assertExecute(containerComposer, singleE2EContext); } } - private void assertExecute(final SingleE2EContainerComposer containerComposer) throws SQLException { - String sql = containerComposer.getSQL(); + private void assertExecute(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { + String sql = singleE2EContext.getSQL(); try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - if (SQLExecuteType.Literal == containerComposer.getSqlExecuteType()) { + if (SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType()) { try (Statement statement = connection.createStatement()) { statement.execute(sql); } diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DDLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DDLE2EIT.java index 09437b5bd92db..fd3f12e52d426 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DDLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DDLE2EIT.java @@ -20,6 +20,9 @@ import com.google.common.base.Splitter; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetColumn; @@ -27,7 +30,7 @@ import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetMetaData; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; import org.junit.jupiter.api.condition.EnabledIf; @@ -65,28 +68,30 @@ void assertExecuteUpdate(final AssertionTestParameter testParam) throws SQLExcep if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(containerComposer, singleE2EContext); try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - if (SQLExecuteType.Literal == containerComposer.getSqlExecuteType()) { - executeUpdateForStatement(containerComposer, connection); + if (SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType()) { + executeUpdateForStatement(singleE2EContext, connection); } else { - executeUpdateForPreparedStatement(containerComposer, connection); + executeUpdateForPreparedStatement(singleE2EContext, connection); } - assertTableMetaData(testParam, containerComposer); + assertTableMetaData(testParam, containerComposer, singleE2EContext); } - tearDown(containerComposer); + tearDown(containerComposer, singleE2EContext); } - private void executeUpdateForStatement(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private void executeUpdateForStatement(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.executeUpdate(containerComposer.getSQL()) > 0, "Not a DDL statement."); + assertFalse(statement.executeUpdate(singleE2EContext.getSQL()) > 0, "Not a DDL statement."); } waitCompleted(); } - private void executeUpdateForPreparedStatement(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL())) { + private void executeUpdateForPreparedStatement(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL())) { assertFalse(preparedStatement.executeUpdate() > 0, "Not a DDL statement."); } waitCompleted(); @@ -100,46 +105,48 @@ void assertExecute(final AssertionTestParameter testParam) throws Exception { if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(containerComposer, singleE2EContext); try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - if (SQLExecuteType.Literal == containerComposer.getSqlExecuteType()) { - executeForStatement(containerComposer, connection); + if (SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType()) { + executeForStatement(singleE2EContext, connection); } else { - executeForPreparedStatement(containerComposer, connection); + executeForPreparedStatement(singleE2EContext, connection); } - assertTableMetaData(testParam, containerComposer); + assertTableMetaData(testParam, containerComposer, singleE2EContext); } - tearDown(containerComposer); + tearDown(containerComposer, singleE2EContext); } - private void executeForStatement(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private void executeForStatement(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(containerComposer.getSQL()), "Not a DDL statement."); + assertFalse(statement.execute(singleE2EContext.getSQL()), "Not a DDL statement."); } waitCompleted(); } - private void executeForPreparedStatement(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL())) { + private void executeForPreparedStatement(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL())) { assertFalse(preparedStatement.execute(), "Not a DDL statement."); } waitCompleted(); } - private void init(final SingleE2EContainerComposer containerComposer) throws SQLException { - assertNotNull(containerComposer.getAssertion().getInitialSQL(), "Init SQL is required"); - assertNotNull(containerComposer.getAssertion().getInitialSQL().getAffectedTable(), "Expected affected table is required"); + private void init(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { + assertNotNull(singleE2EContext.getAssertion().getInitialSQL(), "Init SQL is required"); + assertNotNull(singleE2EContext.getAssertion().getInitialSQL().getAffectedTable(), "Expected affected table is required"); try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - executeInitSQLs(containerComposer, connection); + executeInitSQLs(singleE2EContext, connection); } } - private void executeInitSQLs(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - if (null == containerComposer.getAssertion().getInitialSQL().getSql()) { + private void executeInitSQLs(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + if (null == singleE2EContext.getAssertion().getInitialSQL().getSql()) { return; } - for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) { + for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(singleE2EContext.getAssertion().getInitialSQL().getSql())) { try (PreparedStatement preparedStatement = connection.prepareStatement(each)) { preparedStatement.executeUpdate(); } @@ -147,19 +154,19 @@ private void executeInitSQLs(final SingleE2EContainerComposer containerComposer, } } - private void tearDown(final SingleE2EContainerComposer containerComposer) throws SQLException { - if (null != containerComposer.getAssertion().getDestroySQL()) { + private void tearDown(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { + if (null != singleE2EContext.getAssertion().getDestroySQL()) { try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - executeDestroySQLs(containerComposer, connection); + executeDestroySQLs(singleE2EContext, connection); } } } - private void executeDestroySQLs(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - if (null == containerComposer.getAssertion().getDestroySQL().getSql()) { + private void executeDestroySQLs(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + if (null == singleE2EContext.getAssertion().getDestroySQL().getSql()) { return; } - for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) { + for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(singleE2EContext.getAssertion().getDestroySQL().getSql())) { try (PreparedStatement preparedStatement = connection.prepareStatement(each)) { preparedStatement.executeUpdate(); } @@ -167,9 +174,9 @@ private void executeDestroySQLs(final SingleE2EContainerComposer containerCompos } } - private void assertTableMetaData(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException { - String tableName = containerComposer.getAssertion().getInitialSQL().getAffectedTable(); - DataSetMetaData expected = containerComposer.getDataSet().findMetaData(tableName); + private void assertTableMetaData(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { + String tableName = singleE2EContext.getAssertion().getInitialSQL().getAffectedTable(); + DataSetMetaData expected = singleE2EContext.getDataSet().findMetaData(tableName); Collection dataNodes = InlineExpressionParserFactory.newInstance(expected.getDataNodes()).splitAndEvaluate().stream().map(DataNode::new).collect(Collectors.toList()); if (expected.getColumns().isEmpty()) { assertNotContainsTable(containerComposer, dataNodes); @@ -183,7 +190,7 @@ private void assertTableMetaData(final AssertionTestParameter testParam, final L assertIndexMetaData(actualIndexes, expected.getIndexes()); } - private void assertNotContainsTable(final SingleE2EContainerComposer containerComposer, final Collection dataNodes) throws SQLException { + private void assertNotContainsTable(final E2EContainerComposer containerComposer, final Collection dataNodes) throws SQLException { for (DataNode each : dataNodes) { try (Connection connection = containerComposer.getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) { assertNotContainsTable(connection, each.getTableName()); @@ -195,7 +202,7 @@ private void assertNotContainsTable(final Connection connection, final String ta assertFalse(connection.getMetaData().getTables(null, null, tableName, new String[]{"TABLE"}).next(), String.format("Table `%s` should not existed", tableName)); } - private List getActualColumns(final SingleE2EContainerComposer containerComposer, final Collection dataNodes) throws SQLException { + private List getActualColumns(final E2EContainerComposer containerComposer, final Collection dataNodes) throws SQLException { Set result = new LinkedHashSet<>(); for (DataNode each : dataNodes) { try (Connection connection = containerComposer.getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) { @@ -220,7 +227,7 @@ private List getActualColumns(final Connection connection, final } } - private List getActualIndexes(final SingleE2EContainerComposer containerComposer, final Collection dataNodes) throws SQLException { + private List getActualIndexes(final E2EContainerComposer containerComposer, final Collection dataNodes) throws SQLException { Set result = new LinkedHashSet<>(); for (DataNode each : dataNodes) { try (Connection connection = containerComposer.getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) { diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RALE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RALE2EIT.java index ea0383c0dabe7..4490fe970e21a 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RALE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RALE2EIT.java @@ -18,13 +18,16 @@ package org.apache.shardingsphere.test.e2e.engine.type; import com.google.common.base.Splitter; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetColumn; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetMetaData; import org.apache.shardingsphere.test.e2e.cases.dataset.row.DataSetRow; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; import org.junit.jupiter.api.condition.EnabledIf; @@ -59,33 +62,35 @@ void assertExecute(final AssertionTestParameter testParam) throws SQLException { if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(containerComposer); - assertExecute(containerComposer); - tearDown(containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(containerComposer, singleE2EContext); + assertExecute(containerComposer, singleE2EContext); + tearDown(containerComposer, singleE2EContext); } - private void assertExecute(final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecute(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { try (Statement statement = connection.createStatement()) { - assertResultSet(containerComposer, statement); + assertResultSet(singleE2EContext, statement); } } } - private void init(final SingleE2EContainerComposer containerComposer) throws SQLException { - if (null != containerComposer.getAssertion().getInitialSQL()) { + private void init(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { + if (null != singleE2EContext.getAssertion().getInitialSQL()) { try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - executeInitSQLs(containerComposer, connection); + executeInitSQLs(singleE2EContext, connection); } } } - private void executeInitSQLs(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - if (null == containerComposer.getAssertion().getInitialSQL().getSql()) { + private void executeInitSQLs(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + if (null == singleE2EContext.getAssertion().getInitialSQL().getSql()) { return; } - for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) { + for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(singleE2EContext.getAssertion().getInitialSQL().getSql())) { try (PreparedStatement preparedStatement = connection.prepareStatement(each)) { preparedStatement.executeUpdate(); } @@ -93,19 +98,19 @@ private void executeInitSQLs(final SingleE2EContainerComposer containerComposer, Awaitility.await().pollDelay(1L, TimeUnit.SECONDS).until(() -> true); } - private void tearDown(final SingleE2EContainerComposer containerComposer) throws SQLException { - if (null != containerComposer.getAssertion().getDestroySQL()) { + private void tearDown(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { + if (null != singleE2EContext.getAssertion().getDestroySQL()) { try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - executeDestroySQLs(containerComposer, connection); + executeDestroySQLs(singleE2EContext, connection); } } } - private void executeDestroySQLs(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - if (null == containerComposer.getAssertion().getDestroySQL().getSql()) { + private void executeDestroySQLs(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + if (null == singleE2EContext.getAssertion().getDestroySQL().getSql()) { return; } - for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) { + for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(singleE2EContext.getAssertion().getDestroySQL().getSql())) { try (PreparedStatement preparedStatement = connection.prepareStatement(each)) { preparedStatement.executeUpdate(); } @@ -113,39 +118,39 @@ private void executeDestroySQLs(final SingleE2EContainerComposer containerCompos Awaitility.await().pollDelay(1L, TimeUnit.SECONDS).until(() -> true); } - private void assertResultSet(final SingleE2EContainerComposer containerComposer, final Statement statement) throws SQLException { - if (null == containerComposer.getAssertion().getAssertionSQL()) { - assertResultSet(containerComposer, statement, containerComposer.getSQL()); + private void assertResultSet(final SingleE2EContext singleE2EContext, final Statement statement) throws SQLException { + if (null == singleE2EContext.getAssertion().getAssertionSQL()) { + assertResultSet(singleE2EContext, statement, singleE2EContext.getSQL()); } else { - statement.execute(containerComposer.getSQL()); + statement.execute(singleE2EContext.getSQL()); Awaitility.await().pollDelay(2L, TimeUnit.SECONDS).until(() -> true); - assertResultSet(containerComposer, statement, containerComposer.getAssertion().getAssertionSQL().getSql()); + assertResultSet(singleE2EContext, statement, singleE2EContext.getAssertion().getAssertionSQL().getSql()); } } - private void assertResultSet(final SingleE2EContainerComposer containerComposer, final Statement statement, final String sql) throws SQLException { + private void assertResultSet(final SingleE2EContext singleE2EContext, final Statement statement, final String sql) throws SQLException { statement.execute(sql); try (ResultSet resultSet = statement.getResultSet()) { - assertResultSet(containerComposer, resultSet); + assertResultSet(singleE2EContext, resultSet); } } - private void assertResultSet(final SingleE2EContainerComposer containerComposer, final ResultSet resultSet) throws SQLException { - assertMetaData(resultSet.getMetaData(), getExpectedColumns(containerComposer)); - assertRows(resultSet, getIgnoreAssertColumns(containerComposer), containerComposer.getDataSet().getRows()); + private void assertResultSet(final SingleE2EContext singleE2EContext, final ResultSet resultSet) throws SQLException { + assertMetaData(resultSet.getMetaData(), getExpectedColumns(singleE2EContext)); + assertRows(resultSet, getIgnoreAssertColumns(singleE2EContext), singleE2EContext.getDataSet().getRows()); } - private Collection getExpectedColumns(final SingleE2EContainerComposer containerComposer) { + private Collection getExpectedColumns(final SingleE2EContext singleE2EContext) { Collection result = new LinkedList<>(); - for (DataSetMetaData each : containerComposer.getDataSet().getMetaDataList()) { + for (DataSetMetaData each : singleE2EContext.getDataSet().getMetaDataList()) { result.addAll(each.getColumns()); } return result; } - private Collection getIgnoreAssertColumns(final SingleE2EContainerComposer containerComposer) { + private Collection getIgnoreAssertColumns(final SingleE2EContext singleE2EContext) { Collection result = new LinkedList<>(); - for (DataSetMetaData each : containerComposer.getDataSet().getMetaDataList()) { + for (DataSetMetaData each : singleE2EContext.getDataSet().getMetaDataList()) { result.addAll(each.getColumns().stream().filter(DataSetColumn::isIgnoreAssertData).map(DataSetColumn::getName).collect(Collectors.toList())); } return result; diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RDLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RDLE2EIT.java index 22c3ffe13888c..d8a83a15b0dea 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RDLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RDLE2EIT.java @@ -18,13 +18,16 @@ package org.apache.shardingsphere.test.e2e.engine.type; import com.google.common.base.Splitter; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetColumn; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetMetaData; import org.apache.shardingsphere.test.e2e.cases.dataset.row.DataSetRow; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; import org.junit.jupiter.api.condition.EnabledIf; @@ -59,47 +62,49 @@ void assertExecute(final AssertionTestParameter testParam) throws SQLException { if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(containerComposer); - assertExecute(testParam, containerComposer); - tearDown(containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(containerComposer, singleE2EContext); + assertExecute(testParam, containerComposer, singleE2EContext); + tearDown(containerComposer, singleE2EContext); } - private void assertExecute(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecute(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { assertNotNull(testParam.getAssertion().getAssertionSQL(), "Assertion SQL is required"); try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { try (Statement statement = connection.createStatement()) { - executeSQLCase(containerComposer, statement); + executeSQLCase(singleE2EContext, statement); Awaitility.await().pollDelay(2L, TimeUnit.SECONDS).until(() -> true); - assertResultSet(containerComposer, statement); + assertResultSet(singleE2EContext, statement); } } } - private void executeSQLCase(final SingleE2EContainerComposer containerComposer, final Statement statement) throws SQLException { - statement.execute(containerComposer.getSQL()); + private void executeSQLCase(final SingleE2EContext singleE2EContext, final Statement statement) throws SQLException { + statement.execute(singleE2EContext.getSQL()); } - private void init(final SingleE2EContainerComposer containerComposer) throws SQLException { + private void init(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - executeInitSQLs(containerComposer, connection); + executeInitSQLs(singleE2EContext, connection); } } - private void tearDown(final SingleE2EContainerComposer containerComposer) throws SQLException { - if (null != containerComposer.getAssertion().getDestroySQL()) { + private void tearDown(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { + if (null != singleE2EContext.getAssertion().getDestroySQL()) { try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - executeDestroySQLs(containerComposer, connection); + executeDestroySQLs(singleE2EContext, connection); } } Awaitility.await().pollDelay(2L, TimeUnit.SECONDS).until(() -> true); } - private void executeInitSQLs(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - if (null == containerComposer.getAssertion().getInitialSQL() || null == containerComposer.getAssertion().getInitialSQL().getSql()) { + private void executeInitSQLs(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + if (null == singleE2EContext.getAssertion().getInitialSQL() || null == singleE2EContext.getAssertion().getInitialSQL().getSql()) { return; } - for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getInitialSQL().getSql())) { + for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(singleE2EContext.getAssertion().getInitialSQL().getSql())) { try (PreparedStatement preparedStatement = connection.prepareStatement(each)) { preparedStatement.executeUpdate(); Awaitility.await().pollDelay(2L, TimeUnit.SECONDS).until(() -> true); @@ -107,11 +112,11 @@ private void executeInitSQLs(final SingleE2EContainerComposer containerComposer, } } - private void executeDestroySQLs(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - if (null == containerComposer.getAssertion().getDestroySQL().getSql()) { + private void executeDestroySQLs(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + if (null == singleE2EContext.getAssertion().getDestroySQL().getSql()) { return; } - for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(containerComposer.getAssertion().getDestroySQL().getSql())) { + for (String each : Splitter.on(";").trimResults().omitEmptyStrings().splitToList(singleE2EContext.getAssertion().getDestroySQL().getSql())) { try (PreparedStatement preparedStatement = connection.prepareStatement(each)) { preparedStatement.executeUpdate(); Awaitility.await().pollDelay(2L, TimeUnit.SECONDS).until(() -> true); @@ -119,20 +124,20 @@ private void executeDestroySQLs(final SingleE2EContainerComposer containerCompos } } - private void assertResultSet(final SingleE2EContainerComposer containerComposer, final Statement statement) throws SQLException { - try (ResultSet resultSet = statement.executeQuery(containerComposer.getAssertion().getAssertionSQL().getSql())) { - assertResultSet(containerComposer, resultSet); + private void assertResultSet(final SingleE2EContext singleE2EContext, final Statement statement) throws SQLException { + try (ResultSet resultSet = statement.executeQuery(singleE2EContext.getAssertion().getAssertionSQL().getSql())) { + assertResultSet(singleE2EContext, resultSet); } } - private void assertResultSet(final SingleE2EContainerComposer containerComposer, final ResultSet resultSet) throws SQLException { - assertMetaData(resultSet.getMetaData(), getExpectedColumns(containerComposer)); - assertRows(resultSet, containerComposer.getDataSet().getRows()); + private void assertResultSet(final SingleE2EContext singleE2EContext, final ResultSet resultSet) throws SQLException { + assertMetaData(resultSet.getMetaData(), getExpectedColumns(singleE2EContext)); + assertRows(resultSet, singleE2EContext.getDataSet().getRows()); } - private Collection getExpectedColumns(final SingleE2EContainerComposer containerComposer) { + private Collection getExpectedColumns(final SingleE2EContext singleE2EContext) { Collection result = new LinkedList<>(); - for (DataSetMetaData each : containerComposer.getDataSet().getMetaDataList()) { + for (DataSetMetaData each : singleE2EContext.getDataSet().getMetaDataList()) { result.addAll(each.getColumns()); } return result; diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RQLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RQLE2EIT.java index 1868ebf61d935..a99a5b7b111fc 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RQLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/RQLE2EIT.java @@ -17,13 +17,16 @@ package org.apache.shardingsphere.test.e2e.engine.type; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetColumn; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetMetaData; import org.apache.shardingsphere.test.e2e.cases.dataset.row.DataSetRow; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; import org.junit.jupiter.api.condition.EnabledIf; @@ -54,29 +57,31 @@ void assertExecute(final AssertionTestParameter testParam) throws SQLException { if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - assertExecute(containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + assertExecute(containerComposer, singleE2EContext); } - private void assertExecute(final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecute(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { try ( Connection connection = containerComposer.getTargetDataSource().getConnection(); Statement statement = connection.createStatement()) { - statement.execute(containerComposer.getSQL()); + statement.execute(singleE2EContext.getSQL()); try (ResultSet resultSet = statement.getResultSet()) { - assertResultSet(containerComposer, resultSet); + assertResultSet(singleE2EContext, resultSet); } } } - private void assertResultSet(final SingleE2EContainerComposer containerComposer, final ResultSet resultSet) throws SQLException { - assertMetaData(resultSet.getMetaData(), getExpectedColumns(containerComposer)); - assertRows(resultSet, containerComposer.getDataSet().getRows()); + private void assertResultSet(final SingleE2EContext singleE2EContext, final ResultSet resultSet) throws SQLException { + assertMetaData(resultSet.getMetaData(), getExpectedColumns(singleE2EContext)); + assertRows(resultSet, singleE2EContext.getDataSet().getRows()); } - private Collection getExpectedColumns(final SingleE2EContainerComposer containerComposer) { + private Collection getExpectedColumns(final SingleE2EContext singleE2EContext) { Collection result = new LinkedList<>(); - for (DataSetMetaData each : containerComposer.getDataSet().getMetaDataList()) { + for (DataSetMetaData each : singleE2EContext.getDataSet().getMetaDataList()) { result.addAll(each.getColumns()); } return result; diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/AdditionalDMLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/AdditionalDMLE2EIT.java index ad2f4964516fb..06d2312849a0f 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/AdditionalDMLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/AdditionalDMLE2EIT.java @@ -17,12 +17,15 @@ package org.apache.shardingsphere.test.e2e.engine.type.dml; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import org.apache.shardingsphere.test.e2e.cases.value.SQLValue; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; import org.apache.shardingsphere.test.e2e.env.runtime.E2ETestEnvironment; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; @@ -54,15 +57,17 @@ void assertExecuteUpdateWithAutoGeneratedKeys(final AssertionTestParameter testP if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType()) || isOracleInsertStatement(testParam.getDatabaseType().getType(), testParam.getTestCaseContext().getTestCase().getSql())) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeUpdateForStatementWithAutoGeneratedKeys(testParam, containerComposer, connection) - : executeUpdateForPreparedStatementWithAutoGeneratedKeys(testParam, containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeUpdateForStatementWithAutoGeneratedKeys(testParam, singleE2EContext, connection) + : executeUpdateForPreparedStatementWithAutoGeneratedKeys(testParam, singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } // TODO support oracle insert statement return auto generated keys @@ -75,22 +80,22 @@ private boolean isPostgreSQLOrOpenGauss(final String databaseType) { } private int executeUpdateForStatementWithAutoGeneratedKeys(final AssertionTestParameter testParam, - final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - int result = statement.executeUpdate(containerComposer.getSQL(), Statement.RETURN_GENERATED_KEYS); - assertGeneratedKeys(containerComposer, statement.getGeneratedKeys(), testParam.getDatabaseType()); + int result = statement.executeUpdate(singleE2EContext.getSQL(), Statement.RETURN_GENERATED_KEYS); + assertGeneratedKeys(testParam, statement.getGeneratedKeys(), testParam.getDatabaseType()); return result; } } private int executeUpdateForPreparedStatementWithAutoGeneratedKeys(final AssertionTestParameter testParam, - final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL(), Statement.RETURN_GENERATED_KEYS)) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL(), Statement.RETURN_GENERATED_KEYS)) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } int result = preparedStatement.executeUpdate(); - assertGeneratedKeys(containerComposer, preparedStatement.getGeneratedKeys(), testParam.getDatabaseType()); + assertGeneratedKeys(testParam, preparedStatement.getGeneratedKeys(), testParam.getDatabaseType()); return result; } } @@ -104,26 +109,28 @@ void assertExecuteUpdateWithColumnIndexes(final AssertionTestParameter testParam if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeUpdateForStatementWithColumnIndexes(containerComposer, connection) - : executeUpdateForPreparedStatementWithColumnIndexes(containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeUpdateForStatementWithColumnIndexes(singleE2EContext, connection) + : executeUpdateForPreparedStatementWithColumnIndexes(singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } - private int executeUpdateForStatementWithColumnIndexes(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private int executeUpdateForStatementWithColumnIndexes(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - return statement.executeUpdate(containerComposer.getSQL(), new int[]{1}); + return statement.executeUpdate(singleE2EContext.getSQL(), new int[]{1}); } } - private int executeUpdateForPreparedStatementWithColumnIndexes(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL(), new int[]{1})) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + private int executeUpdateForPreparedStatementWithColumnIndexes(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL(), new int[]{1})) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } return preparedStatement.executeUpdate(); @@ -139,26 +146,28 @@ void assertExecuteUpdateWithColumnNames(final AssertionTestParameter testParam) if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeUpdateForStatementWithColumnNames(containerComposer, connection) - : executeUpdateForPreparedStatementWithColumnNames(containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeUpdateForStatementWithColumnNames(singleE2EContext, connection) + : executeUpdateForPreparedStatementWithColumnNames(singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } - private int executeUpdateForStatementWithColumnNames(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private int executeUpdateForStatementWithColumnNames(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - return statement.executeUpdate(containerComposer.getSQL()); + return statement.executeUpdate(singleE2EContext.getSQL()); } } - private int executeUpdateForPreparedStatementWithColumnNames(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL(), new String[]{"TODO"})) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + private int executeUpdateForPreparedStatementWithColumnNames(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL(), new String[]{"TODO"})) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } return preparedStatement.executeUpdate(); @@ -176,27 +185,29 @@ void assertExecuteWithoutAutoGeneratedKeys(final AssertionTestParameter testPara if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeForStatementWithoutAutoGeneratedKeys(containerComposer, connection) - : executeForPreparedStatementWithoutAutoGeneratedKeys(containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeForStatementWithoutAutoGeneratedKeys(singleE2EContext, connection) + : executeForPreparedStatementWithoutAutoGeneratedKeys(singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } - private int executeForStatementWithoutAutoGeneratedKeys(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private int executeForStatementWithoutAutoGeneratedKeys(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(containerComposer.getSQL(), Statement.NO_GENERATED_KEYS), "Not a DML statement."); + assertFalse(statement.execute(singleE2EContext.getSQL(), Statement.NO_GENERATED_KEYS), "Not a DML statement."); return statement.getUpdateCount(); } } - private int executeForPreparedStatementWithoutAutoGeneratedKeys(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL(), Statement.NO_GENERATED_KEYS)) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + private int executeForPreparedStatementWithoutAutoGeneratedKeys(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL(), Statement.NO_GENERATED_KEYS)) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } assertFalse(preparedStatement.execute(), "Not a DML statement."); @@ -215,34 +226,36 @@ void assertExecuteWithAutoGeneratedKeys(final AssertionTestParameter testParam) if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType()) || isOracleInsertStatement(testParam.getDatabaseType().getType(), testParam.getTestCaseContext().getTestCase().getSql())) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeForStatementWithAutoGeneratedKeys(testParam, containerComposer, connection) - : executeForPreparedStatementWithAutoGeneratedKeys(testParam, containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeForStatementWithAutoGeneratedKeys(testParam, singleE2EContext, connection) + : executeForPreparedStatementWithAutoGeneratedKeys(testParam, singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } private int executeForStatementWithAutoGeneratedKeys(final AssertionTestParameter testParam, - final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(containerComposer.getSQL(), Statement.RETURN_GENERATED_KEYS), "Not a DML statement."); - assertGeneratedKeys(containerComposer, statement.getGeneratedKeys(), testParam.getDatabaseType()); + assertFalse(statement.execute(singleE2EContext.getSQL(), Statement.RETURN_GENERATED_KEYS), "Not a DML statement."); + assertGeneratedKeys(testParam, statement.getGeneratedKeys(), testParam.getDatabaseType()); return statement.getUpdateCount(); } } private int executeForPreparedStatementWithAutoGeneratedKeys(final AssertionTestParameter testParam, - final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL(), Statement.RETURN_GENERATED_KEYS)) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL(), Statement.RETURN_GENERATED_KEYS)) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } assertFalse(preparedStatement.execute(), "Not a DML statement."); - assertGeneratedKeys(containerComposer, preparedStatement.getGeneratedKeys(), testParam.getDatabaseType()); + assertGeneratedKeys(testParam, preparedStatement.getGeneratedKeys(), testParam.getDatabaseType()); return preparedStatement.getUpdateCount(); } } @@ -256,27 +269,29 @@ void assertExecuteWithColumnIndexes(final AssertionTestParameter testParam) thro if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeForStatementWithColumnIndexes(containerComposer, connection) - : executeForPreparedStatementWithColumnIndexes(containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeForStatementWithColumnIndexes(singleE2EContext, connection) + : executeForPreparedStatementWithColumnIndexes(singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } - private int executeForStatementWithColumnIndexes(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private int executeForStatementWithColumnIndexes(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(containerComposer.getSQL(), new int[]{1}), "Not a DML statement."); + assertFalse(statement.execute(singleE2EContext.getSQL(), new int[]{1}), "Not a DML statement."); return statement.getUpdateCount(); } } - private int executeForPreparedStatementWithColumnIndexes(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL(), new int[]{1})) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + private int executeForPreparedStatementWithColumnIndexes(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL(), new int[]{1})) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } assertFalse(preparedStatement.execute(), "Not a DML statement."); @@ -293,27 +308,29 @@ void assertExecuteWithColumnNames(final AssertionTestParameter testParam) throws if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeForStatementWithColumnNames(containerComposer, connection) - : executeForPreparedStatementWithColumnNames(containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeForStatementWithColumnNames(singleE2EContext, connection) + : executeForPreparedStatementWithColumnNames(singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } - private int executeForStatementWithColumnNames(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private int executeForStatementWithColumnNames(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(containerComposer.getSQL(), new String[]{"TODO"}), "Not a DML statement."); + assertFalse(statement.execute(singleE2EContext.getSQL(), new String[]{"TODO"}), "Not a DML statement."); return statement.getUpdateCount(); } } - private int executeForPreparedStatementWithColumnNames(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL(), new String[]{"TODO"})) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + private int executeForPreparedStatementWithColumnNames(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL(), new String[]{"TODO"})) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } assertFalse(preparedStatement.execute(), "Not a DML statement."); diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/BaseDMLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/BaseDMLE2EIT.java index f7b222f516eba..5a8a5b0096b22 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/BaseDMLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/BaseDMLE2EIT.java @@ -21,12 +21,14 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory; import org.apache.shardingsphere.infra.util.datetime.DateTimeFormatterFactory; +import org.apache.shardingsphere.test.e2e.cases.casse.assertion.E2ETestCaseAssertion; +import org.apache.shardingsphere.test.e2e.cases.dataset.DataSet; +import org.apache.shardingsphere.test.e2e.cases.dataset.DataSetLoader; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetColumn; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetMetaData; import org.apache.shardingsphere.test.e2e.cases.dataset.row.DataSetRow; -import org.apache.shardingsphere.test.e2e.engine.composer.BatchE2EContainerComposer; import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; import org.apache.shardingsphere.test.e2e.env.DataSetEnvironmentManager; import org.apache.shardingsphere.test.e2e.env.runtime.scenario.database.DatabaseEnvironmentManager; import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath; @@ -46,12 +48,17 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import java.sql.Statement; import java.sql.Types; import java.util.Arrays; import java.util.Collection; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -71,7 +78,7 @@ public abstract class BaseDMLE2EIT { * @throws IOException IO exception * @throws JAXBException JAXB exception */ - public final void init(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException, IOException, JAXBException { + public final void init(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer) throws SQLException, IOException, JAXBException { dataSetEnvironmentManager = new DataSetEnvironmentManager(new ScenarioDataPath(testParam.getScenario()).getDataSetFile(Type.ACTUAL), containerComposer.getActualDataSourceMap(), testParam.getDatabaseType()); dataSetEnvironmentManager.fillData(); @@ -85,14 +92,66 @@ void tearDown() { } } - protected final void assertDataSet(final SingleE2EContainerComposer containerComposer, final int actualUpdateCount, final AssertionTestParameter testParam) throws SQLException { - assertThat(actualUpdateCount, is(containerComposer.getDataSet().getUpdateCount())); - for (DataSetMetaData each : containerComposer.getDataSet().getMetaDataList()) { - assertDataSet(containerComposer, each, testParam); + /** + * Get data set. + * + * @param actualUpdateCounts actual update counts + * @param dataSets data sets + * @return data set + */ + public DataSet getDataSet(final int[] actualUpdateCounts, final Collection dataSets) { + Collection result = new LinkedList<>(); + assertThat(actualUpdateCounts.length, is(dataSets.size())); + int count = 0; + for (DataSet each : dataSets) { + if (Statement.SUCCESS_NO_INFO != actualUpdateCounts[count]) { + assertThat(actualUpdateCounts[count], is(each.getUpdateCount())); + } + result.add(each); + count++; + } + return mergeDataSets(result); + } + + private DataSet mergeDataSets(final Collection dataSets) { + DataSet result = new DataSet(); + Set existedRows = new HashSet<>(); + for (DataSet each : dataSets) { + mergeMetaData(each, result); + mergeRow(each, result, existedRows); + } + sortRow(result); + return result; + } + + private void mergeMetaData(final DataSet original, final DataSet dist) { + if (dist.getMetaDataList().isEmpty()) { + dist.getMetaDataList().addAll(original.getMetaDataList()); } } - private void assertDataSet(final SingleE2EContainerComposer containerComposer, final DataSetMetaData expectedDataSetMetaData, final AssertionTestParameter testParam) throws SQLException { + private void mergeRow(final DataSet original, final DataSet dist, final Set existedRows) { + for (DataSetRow each : original.getRows()) { + if (existedRows.add(each)) { + dist.getRows().add(each); + } + } + } + + private void sortRow(final DataSet dataSet) { + dataSet.getRows().sort(Comparator.comparingLong(o -> Long.parseLong(o.splitValues(",").get(0)))); + } + + protected final void assertDataSet(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext, final int actualUpdateCount, + final AssertionTestParameter testParam) throws SQLException { + assertThat(actualUpdateCount, is(singleE2EContext.getDataSet().getUpdateCount())); + for (DataSetMetaData each : singleE2EContext.getDataSet().getMetaDataList()) { + assertDataSet(containerComposer, singleE2EContext, each, testParam); + } + } + + private void assertDataSet(final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext, final DataSetMetaData expectedDataSetMetaData, + final AssertionTestParameter testParam) throws SQLException { Map databaseTypes = DatabaseEnvironmentManager.getDatabaseTypes(testParam.getScenario(), testParam.getDatabaseType()); for (String each : InlineExpressionParserFactory.newInstance(expectedDataSetMetaData.getDataNodes()).splitAndEvaluate()) { DataNode dataNode = new DataNode(each); @@ -101,7 +160,7 @@ private void assertDataSet(final SingleE2EContainerComposer containerComposer, f try ( Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(generateFetchActualDataSQL(containerComposer.getActualDataSourceMap(), dataNode, databaseType))) { - assertDataSet(preparedStatement, expectedDataSetMetaData, containerComposer.getDataSet().findRows(dataNode), databaseType); + assertDataSet(preparedStatement, expectedDataSetMetaData, singleE2EContext.getDataSet().findRows(dataNode), databaseType); } } } @@ -114,14 +173,19 @@ private void assertDataSet(final PreparedStatement actualPreparedStatement, fina } } - protected final void assertDataSet(final BatchE2EContainerComposer containerComposer, final int[] actualUpdateCounts, final CaseTestParameter testParam) throws SQLException { - for (DataSetMetaData each : containerComposer.getDataSet(actualUpdateCounts).getMetaDataList()) { - assertDataSet(containerComposer, actualUpdateCounts, each, testParam); + protected final void assertDataSet(final E2EContainerComposer containerComposer, final int[] actualUpdateCounts, final CaseTestParameter testParam) throws SQLException { + Collection dataSets = new LinkedList<>(); + for (E2ETestCaseAssertion each : testParam.getTestCaseContext().getTestCase().getAssertions()) { + dataSets.add(DataSetLoader.load(testParam.getTestCaseContext().getParentPath(), testParam.getScenario(), testParam.getDatabaseType(), testParam.getMode(), each.getExpectedDataFile())); + } + DataSet dataSet = getDataSet(actualUpdateCounts, dataSets); + for (DataSetMetaData each : dataSet.getMetaDataList()) { + assertDataSet(containerComposer, each, testParam, dataSet); } } - private void assertDataSet(final BatchE2EContainerComposer containerComposer, final int[] actualUpdateCounts, final DataSetMetaData expectedDataSetMetaData, - final CaseTestParameter testParam) throws SQLException { + private void assertDataSet(final E2EContainerComposer containerComposer, final DataSetMetaData expectedDataSetMetaData, final CaseTestParameter testParam, + final DataSet dataSet) throws SQLException { Map databaseTypes = DatabaseEnvironmentManager.getDatabaseTypes(testParam.getScenario(), testParam.getDatabaseType()); for (String each : InlineExpressionParserFactory.newInstance(expectedDataSetMetaData.getDataNodes()).splitAndEvaluate()) { DataNode dataNode = new DataNode(each); @@ -130,7 +194,7 @@ private void assertDataSet(final BatchE2EContainerComposer containerComposer, fi try ( Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(generateFetchActualDataSQL(containerComposer.getActualDataSourceMap(), dataNode, databaseType))) { - assertDataSet(preparedStatement, expectedDataSetMetaData, containerComposer.getDataSet(actualUpdateCounts).findRows(dataNode), databaseType); + assertDataSet(preparedStatement, expectedDataSetMetaData, dataSet.findRows(dataNode), databaseType); } } } @@ -196,12 +260,17 @@ private boolean isPostgreSQLOrOpenGaussMoney(final String columnTypeName, final return "money".equalsIgnoreCase(columnTypeName) && ("PostgreSQL".equals(databaseType.getType()) || "openGauss".equals(databaseType.getType())); } - protected void assertGeneratedKeys(final SingleE2EContainerComposer containerComposer, final ResultSet generatedKeys, final DatabaseType databaseType) throws SQLException { - if (null == containerComposer.getGeneratedKeyDataSet()) { + protected void assertGeneratedKeys(final AssertionTestParameter testParam, final ResultSet generatedKeys, final DatabaseType databaseType) throws SQLException { + DataSet generatedKeyDataSet = null == testParam.getAssertion() || null == testParam.getAssertion().getExpectedGeneratedKeyDataFile() + ? null + : DataSetLoader.load( + testParam.getTestCaseContext().getParentPath(), testParam.getScenario(), testParam.getDatabaseType(), testParam.getMode(), + testParam.getAssertion().getExpectedGeneratedKeyDataFile()); + if (null == generatedKeyDataSet) { return; } - assertThat("Only support single table for DML.", containerComposer.getGeneratedKeyDataSet().getMetaDataList().size(), is(1)); - assertMetaData(generatedKeys.getMetaData(), containerComposer.getGeneratedKeyDataSet().getMetaDataList().get(0).getColumns()); - assertRows(generatedKeys, containerComposer.getGeneratedKeyDataSet().getRows(), databaseType); + assertThat("Only support single table for DML.", generatedKeyDataSet.getMetaDataList().size(), is(1)); + assertMetaData(generatedKeys.getMetaData(), generatedKeyDataSet.getMetaDataList().get(0).getColumns()); + assertRows(generatedKeys, generatedKeyDataSet.getRows(), databaseType); } } diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/BatchDMLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/BatchDMLE2EIT.java index aec207b21ae0a..3bc7e85c857bd 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/BatchDMLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/BatchDMLE2EIT.java @@ -17,14 +17,19 @@ package org.apache.shardingsphere.test.e2e.engine.type.dml; -import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.cases.casse.assertion.E2ETestCaseAssertion; import org.apache.shardingsphere.test.e2e.cases.value.SQLValue; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.BatchE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; +import org.apache.shardingsphere.test.e2e.env.DataSetEnvironmentManager; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; +import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.CaseTestParameter; +import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ArgumentsSource; @@ -41,6 +46,15 @@ @E2ETestCaseSettings(value = SQLCommandType.DML, batch = true) class BatchDMLE2EIT extends BaseDMLE2EIT { + private DataSetEnvironmentManager dataSetEnvironmentManager; + + @AfterEach + void tearDown() { + if (null != dataSetEnvironmentManager) { + dataSetEnvironmentManager.cleanData(); + } + } + @ParameterizedTest(name = "{0}") @EnabledIf("isEnabled") @ArgumentsSource(E2ETestCaseArgumentsProvider.class) @@ -49,13 +63,16 @@ void assertExecuteBatch(final CaseTestParameter testParam) throws SQLException, if (null == testParam.getTestCaseContext()) { return; } - try (BatchE2EContainerComposer containerComposer = new BatchE2EContainerComposer(testParam)) { - int[] actualUpdateCounts; - try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCounts = executeBatchForPreparedStatement(testParam, connection); - } - assertDataSet(containerComposer, actualUpdateCounts, testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + dataSetEnvironmentManager = new DataSetEnvironmentManager(new ScenarioDataPath(testParam.getScenario()).getDataSetFile(ScenarioDataPath.Type.ACTUAL), + containerComposer.getActualDataSourceMap(), testParam.getDatabaseType()); + dataSetEnvironmentManager.fillData(); + int[] actualUpdateCounts; + try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { + actualUpdateCounts = executeBatchForPreparedStatement(testParam, connection); } + assertDataSet(containerComposer, actualUpdateCounts, testParam); } private int[] executeBatchForPreparedStatement(final CaseTestParameter testParam, final Connection connection) throws SQLException { @@ -82,16 +99,19 @@ void assertClearBatch(final CaseTestParameter testParam) throws SQLException, JA if (null == testParam.getTestCaseContext()) { return; } - try (BatchE2EContainerComposer containerComposer = new BatchE2EContainerComposer(testParam)) { - try ( - Connection connection = containerComposer.getTargetDataSource().getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement(testParam.getTestCaseContext().getTestCase().getSql())) { - for (E2ETestCaseAssertion each : testParam.getTestCaseContext().getTestCase().getAssertions()) { - addBatch(preparedStatement, each); - } - preparedStatement.clearBatch(); - assertThat(preparedStatement.executeBatch().length, is(0)); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + dataSetEnvironmentManager = new DataSetEnvironmentManager(new ScenarioDataPath(testParam.getScenario()).getDataSetFile(ScenarioDataPath.Type.ACTUAL), + containerComposer.getActualDataSourceMap(), testParam.getDatabaseType()); + dataSetEnvironmentManager.fillData(); + try ( + Connection connection = containerComposer.getTargetDataSource().getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(testParam.getTestCaseContext().getTestCase().getSql())) { + for (E2ETestCaseAssertion each : testParam.getTestCaseContext().getTestCase().getAssertions()) { + addBatch(preparedStatement, each); } + preparedStatement.clearBatch(); + assertThat(preparedStatement.executeBatch().length, is(0)); } } diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/GeneralDMLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/GeneralDMLE2EIT.java index 6a2fc6048ad99..26c8e240eb04e 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/GeneralDMLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/GeneralDMLE2EIT.java @@ -17,12 +17,15 @@ package org.apache.shardingsphere.test.e2e.engine.type.dml; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import org.apache.shardingsphere.test.e2e.cases.value.SQLValue; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; import org.junit.jupiter.api.condition.EnabledIf; @@ -49,26 +52,28 @@ void assertExecuteUpdate(final AssertionTestParameter testParam) throws SQLExcep if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeUpdateForStatement(containerComposer, connection) - : executeUpdateForPreparedStatement(containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeUpdateForStatement(singleE2EContext, connection) + : executeUpdateForPreparedStatement(singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } - private int executeUpdateForStatement(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private int executeUpdateForStatement(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - return statement.executeUpdate(containerComposer.getSQL()); + return statement.executeUpdate(singleE2EContext.getSQL()); } } - private int executeUpdateForPreparedStatement(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL())) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + private int executeUpdateForPreparedStatement(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL())) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } return preparedStatement.executeUpdate(); @@ -83,27 +88,29 @@ void assertExecute(final AssertionTestParameter testParam) throws SQLException, if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); init(testParam, containerComposer); int actualUpdateCount; try (Connection connection = containerComposer.getTargetDataSource().getConnection()) { - actualUpdateCount = SQLExecuteType.Literal == containerComposer.getSqlExecuteType() - ? executeForStatement(containerComposer, connection) - : executeForPreparedStatement(containerComposer, connection); + actualUpdateCount = SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType() + ? executeForStatement(singleE2EContext, connection) + : executeForPreparedStatement(singleE2EContext, connection); } - assertDataSet(containerComposer, actualUpdateCount, testParam); + assertDataSet(containerComposer, singleE2EContext, actualUpdateCount, testParam); } - private int executeForStatement(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { + private int executeForStatement(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(containerComposer.getSQL()), "Not a DML statement."); + assertFalse(statement.execute(singleE2EContext.getSQL()), "Not a DML statement."); return statement.getUpdateCount(); } } - private int executeForPreparedStatement(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { - try (PreparedStatement preparedStatement = connection.prepareStatement(containerComposer.getSQL())) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + private int executeForPreparedStatement(final SingleE2EContext singleE2EContext, final Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(singleE2EContext.getSQL())) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { preparedStatement.setObject(each.getIndex(), each.getValue()); } assertFalse(preparedStatement.execute(), "Not a DML statement."); diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/AdditionalDQLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/AdditionalDQLE2EIT.java index 74c9f7c61dd60..5a72d5767e8dc 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/AdditionalDQLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/AdditionalDQLE2EIT.java @@ -17,15 +17,18 @@ package org.apache.shardingsphere.test.e2e.engine.type.dql; -import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; -import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import org.apache.shardingsphere.test.e2e.cases.value.SQLValue; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.env.runtime.E2ETestEnvironment; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; +import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; +import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ArgumentsSource; @@ -51,16 +54,18 @@ void assertExecuteQueryWithResultSetTypeAndConcurrency(final AssertionTestParame if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(testParam, containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(testParam, containerComposer, singleE2EContext); // TODO fix e2e test blocked exception with PostgreSQL or openGauss in #23643 if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } if (isUseXMLAsExpectedDataset()) { - assertExecuteQueryWithXMLExpected(testParam, containerComposer, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + assertExecuteQueryWithXMLExpected(testParam, containerComposer, singleE2EContext, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } else { - assertExecuteQueryWithExpectedDataSource(testParam, containerComposer, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + assertExecuteQueryWithExpectedDataSource(testParam, containerComposer, singleE2EContext, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } } @@ -72,16 +77,18 @@ void assertExecuteQueryWithResultSetTypeAndConcurrencyAndHoldability(final Asser if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(testParam, containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(testParam, containerComposer, singleE2EContext); // TODO fix e2e test blocked exception with PostgreSQL or openGauss in #23643 if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } if (isUseXMLAsExpectedDataset()) { - assertExecuteQueryWithXMLExpected(testParam, containerComposer, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + assertExecuteQueryWithXMLExpected(testParam, containerComposer, singleE2EContext, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); } else { - assertExecuteQueryWithExpectedDataSource(testParam, containerComposer, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + assertExecuteQueryWithExpectedDataSource(testParam, containerComposer, singleE2EContext, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); } } @@ -93,16 +100,18 @@ void assertExecuteWithResultSetTypeAndConcurrency(final AssertionTestParameter t if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(testParam, containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(testParam, containerComposer, singleE2EContext); // TODO fix e2e test blocked exception with PostgreSQL or openGauss in #23643 if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } if (isUseXMLAsExpectedDataset()) { - assertExecuteWithXMLExpected(testParam, containerComposer, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + assertExecuteWithXMLExpected(testParam, containerComposer, singleE2EContext, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } else { - assertExecuteWithExpectedDataSource(testParam, containerComposer, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + assertExecuteWithExpectedDataSource(testParam, containerComposer, singleE2EContext, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } } @@ -114,16 +123,18 @@ void assertExecuteWithResultSetTypeAndConcurrencyAndHoldability(final AssertionT if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(testParam, containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(testParam, containerComposer, singleE2EContext); // TODO fix e2e test blocked exception with PostgreSQL or openGauss in #23643 if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { return; } if (isUseXMLAsExpectedDataset()) { - assertExecuteWithXMLExpected(testParam, containerComposer, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + assertExecuteWithXMLExpected(testParam, containerComposer, singleE2EContext, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); } else { - assertExecuteWithExpectedDataSource(testParam, containerComposer, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + assertExecuteWithExpectedDataSource(testParam, containerComposer, singleE2EContext, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); } } @@ -132,7 +143,7 @@ private boolean isPostgreSQLOrOpenGauss(final String databaseType) { } private void assertExecuteQueryWithXMLExpected(final AssertionTestParameter testParam, - final SingleE2EContainerComposer containerComposer, final int... resultSetTypes) throws SQLException { + final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext, final int... resultSetTypes) throws SQLException { // TODO Fix jdbc adapter if ("jdbc".equals(testParam.getAdapter())) { return; @@ -141,45 +152,46 @@ private void assertExecuteQueryWithXMLExpected(final AssertionTestParameter test Connection connection = containerComposer.getTargetDataSource().getConnection(); Statement statement = 2 == resultSetTypes.length ? connection.createStatement(resultSetTypes[0], resultSetTypes[1]) : connection.createStatement(resultSetTypes[0], resultSetTypes[1], resultSetTypes[2]); - ResultSet resultSet = statement.executeQuery(containerComposer.getSQL())) { - assertResultSet(containerComposer, resultSet); + ResultSet resultSet = statement.executeQuery(singleE2EContext.getSQL())) { + assertResultSet(singleE2EContext, resultSet); } } - private void assertExecuteQueryWithExpectedDataSource(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer, final int... resultSetTypes) throws SQLException { + private void assertExecuteQueryWithExpectedDataSource(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext, + final int... resultSetTypes) throws SQLException { try ( Connection actualConnection = containerComposer.getTargetDataSource().getConnection(); Connection expectedConnection = getExpectedDataSource().getConnection()) { - if (SQLExecuteType.Literal == containerComposer.getSqlExecuteType()) { - assertExecuteQueryForStatementWithResultSetTypes(containerComposer, actualConnection, expectedConnection, testParam, resultSetTypes); + if (SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType()) { + assertExecuteQueryForStatementWithResultSetTypes(singleE2EContext, actualConnection, expectedConnection, testParam, resultSetTypes); } else { - assertExecuteQueryForPreparedStatementWithResultSetTypes(containerComposer, actualConnection, expectedConnection, testParam, resultSetTypes); + assertExecuteQueryForPreparedStatementWithResultSetTypes(singleE2EContext, actualConnection, expectedConnection, testParam, resultSetTypes); } } } - private void assertExecuteQueryForStatementWithResultSetTypes(final SingleE2EContainerComposer containerComposer, + private void assertExecuteQueryForStatementWithResultSetTypes(final SingleE2EContext singleE2EContext, final Connection actualConnection, final Connection expectedConnection, final AssertionTestParameter testParam, final int... resultSetTypes) throws SQLException { try ( Statement actualStatement = 2 == resultSetTypes.length ? actualConnection.createStatement(resultSetTypes[0], resultSetTypes[1]) : actualConnection.createStatement(resultSetTypes[0], resultSetTypes[1], resultSetTypes[2]); - ResultSet actualResultSet = actualStatement.executeQuery(containerComposer.getSQL()); + ResultSet actualResultSet = actualStatement.executeQuery(singleE2EContext.getSQL()); Statement expectedStatement = 2 == resultSetTypes.length ? expectedConnection.createStatement(resultSetTypes[0], resultSetTypes[1]) : expectedConnection.createStatement(resultSetTypes[0], resultSetTypes[1], resultSetTypes[2]); - ResultSet expectedResultSet = expectedStatement.executeQuery(containerComposer.getSQL())) { + ResultSet expectedResultSet = expectedStatement.executeQuery(singleE2EContext.getSQL())) { assertResultSet(actualResultSet, expectedResultSet, testParam); } } - private void assertExecuteQueryForPreparedStatementWithResultSetTypes(final SingleE2EContainerComposer containerComposer, final Connection actualConnection, final Connection expectedConnection, + private void assertExecuteQueryForPreparedStatementWithResultSetTypes(final SingleE2EContext singleE2EContext, final Connection actualConnection, final Connection expectedConnection, final AssertionTestParameter testParam, final int... resultSetTypes) throws SQLException { try ( - PreparedStatement actualPreparedStatement = 2 == resultSetTypes.length ? actualConnection.prepareStatement(containerComposer.getSQL(), resultSetTypes[0], resultSetTypes[1]) - : actualConnection.prepareStatement(containerComposer.getSQL(), resultSetTypes[0], resultSetTypes[1], resultSetTypes[2]); - PreparedStatement expectedPreparedStatement = 2 == resultSetTypes.length ? expectedConnection.prepareStatement(containerComposer.getSQL(), resultSetTypes[0], resultSetTypes[1]) - : expectedConnection.prepareStatement(containerComposer.getSQL(), resultSetTypes[0], resultSetTypes[1], resultSetTypes[2])) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + PreparedStatement actualPreparedStatement = 2 == resultSetTypes.length ? actualConnection.prepareStatement(singleE2EContext.getSQL(), resultSetTypes[0], resultSetTypes[1]) + : actualConnection.prepareStatement(singleE2EContext.getSQL(), resultSetTypes[0], resultSetTypes[1], resultSetTypes[2]); + PreparedStatement expectedPreparedStatement = 2 == resultSetTypes.length ? expectedConnection.prepareStatement(singleE2EContext.getSQL(), resultSetTypes[0], resultSetTypes[1]) + : expectedConnection.prepareStatement(singleE2EContext.getSQL(), resultSetTypes[0], resultSetTypes[1], resultSetTypes[2])) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { actualPreparedStatement.setObject(each.getIndex(), each.getValue()); expectedPreparedStatement.setObject(each.getIndex(), each.getValue()); } @@ -192,7 +204,7 @@ private void assertExecuteQueryForPreparedStatementWithResultSetTypes(final Sing } private void assertExecuteWithXMLExpected(final AssertionTestParameter testParam, - final SingleE2EContainerComposer containerComposer, final int... resultSetTypes) throws SQLException { + final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext, final int... resultSetTypes) throws SQLException { // TODO Fix jdbc adapter if ("jdbc".equals(testParam.getAdapter())) { return; @@ -201,32 +213,33 @@ private void assertExecuteWithXMLExpected(final AssertionTestParameter testParam Connection connection = containerComposer.getTargetDataSource().getConnection(); Statement statement = 2 == resultSetTypes.length ? connection.createStatement(resultSetTypes[0], resultSetTypes[1]) : connection.createStatement(resultSetTypes[0], resultSetTypes[1], resultSetTypes[2])) { - assertTrue(statement.execute(containerComposer.getSQL()), "Not a query statement."); + assertTrue(statement.execute(singleE2EContext.getSQL()), "Not a query statement."); ResultSet resultSet = statement.getResultSet(); - assertResultSet(containerComposer, resultSet); + assertResultSet(singleE2EContext, resultSet); } } - private void assertExecuteWithExpectedDataSource(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer, final int... resultSetTypes) throws SQLException { + private void assertExecuteWithExpectedDataSource(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext, + final int... resultSetTypes) throws SQLException { try ( Connection actualConnection = containerComposer.getTargetDataSource().getConnection(); Connection expectedConnection = getExpectedDataSource().getConnection()) { - if (SQLExecuteType.Literal == containerComposer.getSqlExecuteType()) { - assertExecuteForStatementWithResultSetTypes(containerComposer, actualConnection, expectedConnection, testParam, resultSetTypes); + if (SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType()) { + assertExecuteForStatementWithResultSetTypes(singleE2EContext, actualConnection, expectedConnection, testParam, resultSetTypes); } else { - assertExecuteForPreparedStatementWithResultSetTypes(containerComposer, actualConnection, expectedConnection, testParam, resultSetTypes); + assertExecuteForPreparedStatementWithResultSetTypes(singleE2EContext, actualConnection, expectedConnection, testParam, resultSetTypes); } } } - private void assertExecuteForStatementWithResultSetTypes(final SingleE2EContainerComposer containerComposer, final Connection actualConnection, final Connection expectedConnection, + private void assertExecuteForStatementWithResultSetTypes(final SingleE2EContext singleE2EContext, final Connection actualConnection, final Connection expectedConnection, final AssertionTestParameter testParam, final int... resultSetTypes) throws SQLException { try ( Statement actualStatement = 2 == resultSetTypes.length ? actualConnection.createStatement(resultSetTypes[0], resultSetTypes[1]) : actualConnection.createStatement(resultSetTypes[0], resultSetTypes[1], resultSetTypes[2]); Statement expectedStatement = 2 == resultSetTypes.length ? expectedConnection.createStatement(resultSetTypes[0], resultSetTypes[1]) : expectedConnection.createStatement(resultSetTypes[0], resultSetTypes[1], resultSetTypes[2])) { - assertTrue(actualStatement.execute(containerComposer.getSQL()) && expectedStatement.execute(containerComposer.getSQL()), "Not a query statement."); + assertTrue(actualStatement.execute(singleE2EContext.getSQL()) && expectedStatement.execute(singleE2EContext.getSQL()), "Not a query statement."); try ( ResultSet actualResultSet = actualStatement.getResultSet(); ResultSet expectedResultSet = expectedStatement.getResultSet()) { @@ -235,14 +248,14 @@ private void assertExecuteForStatementWithResultSetTypes(final SingleE2EContaine } } - private void assertExecuteForPreparedStatementWithResultSetTypes(final SingleE2EContainerComposer containerComposer, final Connection actualConnection, final Connection expectedConnection, + private void assertExecuteForPreparedStatementWithResultSetTypes(final SingleE2EContext singleE2EContext, final Connection actualConnection, final Connection expectedConnection, final AssertionTestParameter testParam, final int... resultSetTypes) throws SQLException { try ( - PreparedStatement actualPreparedStatement = 2 == resultSetTypes.length ? actualConnection.prepareStatement(containerComposer.getSQL(), resultSetTypes[0], resultSetTypes[1]) - : actualConnection.prepareStatement(containerComposer.getSQL(), resultSetTypes[0], resultSetTypes[1], resultSetTypes[2]); - PreparedStatement expectedPreparedStatement = 2 == resultSetTypes.length ? expectedConnection.prepareStatement(containerComposer.getSQL(), resultSetTypes[0], resultSetTypes[1]) - : expectedConnection.prepareStatement(containerComposer.getSQL(), resultSetTypes[0], resultSetTypes[1], resultSetTypes[2])) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + PreparedStatement actualPreparedStatement = 2 == resultSetTypes.length ? actualConnection.prepareStatement(singleE2EContext.getSQL(), resultSetTypes[0], resultSetTypes[1]) + : actualConnection.prepareStatement(singleE2EContext.getSQL(), resultSetTypes[0], resultSetTypes[1], resultSetTypes[2]); + PreparedStatement expectedPreparedStatement = 2 == resultSetTypes.length ? expectedConnection.prepareStatement(singleE2EContext.getSQL(), resultSetTypes[0], resultSetTypes[1]) + : expectedConnection.prepareStatement(singleE2EContext.getSQL(), resultSetTypes[0], resultSetTypes[1], resultSetTypes[2])) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { actualPreparedStatement.setObject(each.getIndex(), each.getValue()); expectedPreparedStatement.setObject(each.getIndex(), each.getValue()); } diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/BaseDQLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/BaseDQLE2EIT.java index c6addd239e06e..a136d1dfdb2d1 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/BaseDQLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/BaseDQLE2EIT.java @@ -23,7 +23,8 @@ import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetColumn; import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetMetaData; import org.apache.shardingsphere.test.e2e.cases.dataset.row.DataSetRow; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; import org.apache.shardingsphere.test.e2e.env.DataSetEnvironmentManager; import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath; import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type; @@ -63,18 +64,19 @@ public abstract class BaseDQLE2EIT { private boolean useXMLAsExpectedDataset; - protected final void init(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException, IOException, JAXBException { + protected final void init(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, + final SingleE2EContext singleE2EContext) throws SQLException, IOException, JAXBException { fillDataOnlyOnce(testParam, containerComposer); - expectedDataSource = null == containerComposer.getAssertion().getExpectedDataSourceName() || 1 == containerComposer.getExpectedDataSourceMap().size() + expectedDataSource = null == singleE2EContext.getAssertion().getExpectedDataSourceName() || 1 == containerComposer.getExpectedDataSourceMap().size() ? getFirstExpectedDataSource(containerComposer.getExpectedDataSourceMap().values()) - : containerComposer.getExpectedDataSourceMap().get(containerComposer.getAssertion().getExpectedDataSourceName()); - useXMLAsExpectedDataset = null != containerComposer.getAssertion().getExpectedDataFile(); + : containerComposer.getExpectedDataSourceMap().get(singleE2EContext.getAssertion().getExpectedDataSourceName()); + useXMLAsExpectedDataset = null != singleE2EContext.getAssertion().getExpectedDataFile(); if (0 != testParam.getTestCaseContext().getTestCase().getDelayAssertionSeconds()) { Awaitility.await().atMost(Duration.ofMinutes(5L)).pollDelay(testParam.getTestCaseContext().getTestCase().getDelayAssertionSeconds(), TimeUnit.SECONDS).until(() -> true); } } - private void fillDataOnlyOnce(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws IOException, JAXBException { + private void fillDataOnlyOnce(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer) throws IOException, JAXBException { String cacheKey = testParam.getKey() + "-" + System.identityHashCode(containerComposer.getActualDataSourceMap()); if (!FILLED_SUITES.contains(cacheKey)) { synchronized (FILLED_SUITES) { @@ -98,22 +100,22 @@ protected final void assertResultSet(final ResultSet actualResultSet, final Resu assertRows(actualResultSet, expectedResultSet); } - protected final void assertResultSet(final SingleE2EContainerComposer containerComposer, final ResultSet resultSet) throws SQLException { - assertMetaData(resultSet.getMetaData(), getExpectedColumns(containerComposer)); - assertRows(resultSet, getIgnoreAssertColumns(containerComposer), containerComposer.getDataSet().getRows()); + protected final void assertResultSet(final SingleE2EContext singleE2EContext, final ResultSet resultSet) throws SQLException { + assertMetaData(resultSet.getMetaData(), getExpectedColumns(singleE2EContext)); + assertRows(resultSet, getIgnoreAssertColumns(singleE2EContext), singleE2EContext.getDataSet().getRows()); } - private Collection getExpectedColumns(final SingleE2EContainerComposer containerComposer) { + private Collection getExpectedColumns(final SingleE2EContext singleE2EContext) { Collection result = new LinkedList<>(); - for (DataSetMetaData each : containerComposer.getDataSet().getMetaDataList()) { + for (DataSetMetaData each : singleE2EContext.getDataSet().getMetaDataList()) { result.addAll(each.getColumns()); } return result; } - private Collection getIgnoreAssertColumns(final SingleE2EContainerComposer containerComposer) { + private Collection getIgnoreAssertColumns(final SingleE2EContext singleE2EContext) { Collection result = new LinkedList<>(); - for (DataSetMetaData each : containerComposer.getDataSet().getMetaDataList()) { + for (DataSetMetaData each : singleE2EContext.getDataSet().getMetaDataList()) { result.addAll(each.getColumns().stream().filter(DataSetColumn::isIgnoreAssertData).map(DataSetColumn::getName).collect(Collectors.toList())); } return result; diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/GeneralDQLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/GeneralDQLE2EIT.java index 6e09226755deb..576bcc7121247 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/GeneralDQLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/GeneralDQLE2EIT.java @@ -17,12 +17,15 @@ package org.apache.shardingsphere.test.e2e.engine.type.dql; +import org.apache.shardingsphere.test.e2e.engine.context.SingleE2EContext; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterMode; +import org.apache.shardingsphere.test.e2e.env.container.atomic.enums.AdapterType; import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType; import org.apache.shardingsphere.test.e2e.framework.type.SQLExecuteType; import org.apache.shardingsphere.test.e2e.cases.value.SQLValue; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider; import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings; -import org.apache.shardingsphere.test.e2e.engine.composer.SingleE2EContainerComposer; +import org.apache.shardingsphere.test.e2e.engine.composer.E2EContainerComposer; import org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory; import org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter; import org.junit.jupiter.api.condition.EnabledIf; @@ -50,20 +53,23 @@ void assertExecuteQuery(final AssertionTestParameter testParam) throws SQLExcept if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(testParam, containerComposer); - assertExecuteQuery(testParam, containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(testParam, containerComposer, singleE2EContext); + assertExecuteQuery(testParam, containerComposer, singleE2EContext); } - private void assertExecuteQuery(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecuteQuery(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { if (isUseXMLAsExpectedDataset()) { - assertExecuteQueryWithXmlExpected(testParam, containerComposer); + assertExecuteQueryWithXmlExpected(testParam, containerComposer, singleE2EContext); } else { - assertExecuteQueryWithExpectedDataSource(testParam, containerComposer); + assertExecuteQueryWithExpectedDataSource(testParam, containerComposer, singleE2EContext); } } - private void assertExecuteQueryWithXmlExpected(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecuteQueryWithXmlExpected(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, + final SingleE2EContext singleE2EContext) throws SQLException { // TODO Fix jdbc adapter and empty_storage_units proxy adapter if ("jdbc".equals(testParam.getAdapter()) && !"empty_storage_units".equalsIgnoreCase(testParam.getScenario()) || "proxy".equals(testParam.getAdapter()) && "empty_storage_units".equalsIgnoreCase(testParam.getScenario())) { @@ -72,40 +78,41 @@ private void assertExecuteQueryWithXmlExpected(final AssertionTestParameter test try ( Connection connection = containerComposer.getTargetDataSource().getConnection(); Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery(containerComposer.getSQL())) { - assertResultSet(containerComposer, resultSet); + ResultSet resultSet = statement.executeQuery(singleE2EContext.getSQL())) { + assertResultSet(singleE2EContext, resultSet); } } - private void assertExecuteQueryWithExpectedDataSource(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecuteQueryWithExpectedDataSource(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, + final SingleE2EContext singleE2EContext) throws SQLException { try ( Connection actualConnection = containerComposer.getTargetDataSource().getConnection(); Connection expectedConnection = getExpectedDataSource().getConnection()) { - if (SQLExecuteType.Literal == containerComposer.getSqlExecuteType()) { - assertExecuteQueryForStatement(containerComposer, actualConnection, expectedConnection, testParam); + if (SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType()) { + assertExecuteQueryForStatement(singleE2EContext, actualConnection, expectedConnection, testParam); } else { - assertExecuteQueryForPreparedStatement(containerComposer, actualConnection, expectedConnection, testParam); + assertExecuteQueryForPreparedStatement(singleE2EContext, actualConnection, expectedConnection, testParam); } } } - private void assertExecuteQueryForStatement(final SingleE2EContainerComposer containerComposer, final Connection actualConnection, final Connection expectedConnection, + private void assertExecuteQueryForStatement(final SingleE2EContext singleE2EContext, final Connection actualConnection, final Connection expectedConnection, final AssertionTestParameter testParam) throws SQLException { try ( Statement actualStatement = actualConnection.createStatement(); - ResultSet actualResultSet = actualStatement.executeQuery(containerComposer.getSQL()); + ResultSet actualResultSet = actualStatement.executeQuery(singleE2EContext.getSQL()); Statement expectedStatement = expectedConnection.createStatement(); - ResultSet expectedResultSet = expectedStatement.executeQuery(containerComposer.getSQL())) { + ResultSet expectedResultSet = expectedStatement.executeQuery(singleE2EContext.getSQL())) { assertResultSet(actualResultSet, expectedResultSet, testParam); } } - private void assertExecuteQueryForPreparedStatement(final SingleE2EContainerComposer containerComposer, final Connection actualConnection, final Connection expectedConnection, + private void assertExecuteQueryForPreparedStatement(final SingleE2EContext singleE2EContext, final Connection actualConnection, final Connection expectedConnection, final AssertionTestParameter testParam) throws SQLException { try ( - PreparedStatement actualPreparedStatement = actualConnection.prepareStatement(containerComposer.getSQL()); - PreparedStatement expectedPreparedStatement = expectedConnection.prepareStatement(containerComposer.getSQL())) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + PreparedStatement actualPreparedStatement = actualConnection.prepareStatement(singleE2EContext.getSQL()); + PreparedStatement expectedPreparedStatement = expectedConnection.prepareStatement(singleE2EContext.getSQL())) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { actualPreparedStatement.setObject(each.getIndex(), each.getValue()); expectedPreparedStatement.setObject(each.getIndex(), each.getValue()); } @@ -125,20 +132,22 @@ void assertExecute(final AssertionTestParameter testParam) throws SQLException, if (null == testParam.getTestCaseContext()) { return; } - SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); - init(testParam, containerComposer); - assertExecute(testParam, containerComposer); + E2EContainerComposer containerComposer = new E2EContainerComposer(testParam.getKey(), testParam.getScenario(), testParam.getDatabaseType(), + AdapterMode.valueOf(testParam.getMode().toUpperCase()), AdapterType.valueOf(testParam.getAdapter().toUpperCase())); + SingleE2EContext singleE2EContext = new SingleE2EContext(testParam); + init(testParam, containerComposer, singleE2EContext); + assertExecute(testParam, containerComposer, singleE2EContext); } - private void assertExecute(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecute(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { if (isUseXMLAsExpectedDataset()) { - assertExecuteWithXmlExpected(testParam, containerComposer); + assertExecuteWithXmlExpected(testParam, containerComposer, singleE2EContext); } else { - assertExecuteWithExpectedDataSource(testParam, containerComposer); + assertExecuteWithExpectedDataSource(testParam, containerComposer, singleE2EContext); } } - private void assertExecuteWithXmlExpected(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecuteWithXmlExpected(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, final SingleE2EContext singleE2EContext) throws SQLException { // TODO Fix jdbc adapter if ("jdbc".equals(testParam.getAdapter())) { return; @@ -146,30 +155,31 @@ private void assertExecuteWithXmlExpected(final AssertionTestParameter testParam try ( Connection connection = containerComposer.getTargetDataSource().getConnection(); Statement statement = connection.createStatement()) { - assertTrue(statement.execute(containerComposer.getSQL()), "Not a query statement."); + assertTrue(statement.execute(singleE2EContext.getSQL()), "Not a query statement."); ResultSet resultSet = statement.getResultSet(); - assertResultSet(containerComposer, resultSet); + assertResultSet(singleE2EContext, resultSet); } } - private void assertExecuteWithExpectedDataSource(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer) throws SQLException { + private void assertExecuteWithExpectedDataSource(final AssertionTestParameter testParam, final E2EContainerComposer containerComposer, + final SingleE2EContext singleE2EContext) throws SQLException { try ( Connection actualConnection = containerComposer.getTargetDataSource().getConnection(); Connection expectedConnection = getExpectedDataSource().getConnection()) { - if (SQLExecuteType.Literal == containerComposer.getSqlExecuteType()) { - assertExecuteForStatement(containerComposer, actualConnection, expectedConnection, testParam); + if (SQLExecuteType.Literal == singleE2EContext.getSqlExecuteType()) { + assertExecuteForStatement(singleE2EContext, actualConnection, expectedConnection, testParam); } else { - assertExecuteForPreparedStatement(containerComposer, actualConnection, expectedConnection, testParam); + assertExecuteForPreparedStatement(singleE2EContext, actualConnection, expectedConnection, testParam); } } } - private void assertExecuteForStatement(final SingleE2EContainerComposer containerComposer, final Connection actualConnection, final Connection expectedConnection, + private void assertExecuteForStatement(final SingleE2EContext singleE2EContext, final Connection actualConnection, final Connection expectedConnection, final AssertionTestParameter testParam) throws SQLException { try ( Statement actualStatement = actualConnection.createStatement(); Statement expectedStatement = expectedConnection.createStatement()) { - assertTrue(actualStatement.execute(containerComposer.getSQL()) && expectedStatement.execute(containerComposer.getSQL()), "Not a query statement."); + assertTrue(actualStatement.execute(singleE2EContext.getSQL()) && expectedStatement.execute(singleE2EContext.getSQL()), "Not a query statement."); try ( ResultSet actualResultSet = actualStatement.getResultSet(); ResultSet expectedResultSet = expectedStatement.getResultSet()) { @@ -178,12 +188,12 @@ private void assertExecuteForStatement(final SingleE2EContainerComposer containe } } - private void assertExecuteForPreparedStatement(final SingleE2EContainerComposer containerComposer, final Connection actualConnection, final Connection expectedConnection, + private void assertExecuteForPreparedStatement(final SingleE2EContext singleE2EContext, final Connection actualConnection, final Connection expectedConnection, final AssertionTestParameter testParam) throws SQLException { try ( - PreparedStatement actualPreparedStatement = actualConnection.prepareStatement(containerComposer.getSQL()); - PreparedStatement expectedPreparedStatement = expectedConnection.prepareStatement(containerComposer.getSQL())) { - for (SQLValue each : containerComposer.getAssertion().getSQLValues()) { + PreparedStatement actualPreparedStatement = actualConnection.prepareStatement(singleE2EContext.getSQL()); + PreparedStatement expectedPreparedStatement = expectedConnection.prepareStatement(singleE2EContext.getSQL())) { + for (SQLValue each : singleE2EContext.getAssertion().getSQLValues()) { actualPreparedStatement.setObject(each.getIndex(), each.getValue()); expectedPreparedStatement.setObject(each.getIndex(), each.getValue()); }