diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java index aaed3ccf2ad03..fc82caf0a1252 100644 --- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java +++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java @@ -58,10 +58,10 @@ public abstract class AbstractStatementAdapter extends AbstractUnsupportedOperat private boolean closed; protected final boolean isNeedImplicitCommitTransaction(final ShardingSphereConnection connection, final ExecutionContext executionContext) { - return isInDistributedTransaction(connection) && isModifiedSQL(executionContext) && executionContext.getExecutionUnits().size() > 1; + return connection.getAutoCommit() && isNotInDistributedTransaction(connection) && isModifiedSQL(executionContext) && executionContext.getExecutionUnits().size() > 1; } - private boolean isInDistributedTransaction(final ShardingSphereConnection connection) { + private boolean isNotInDistributedTransaction(final ShardingSphereConnection connection) { ConnectionTransaction connectionTransaction = connection.getDatabaseConnectionManager().getConnectionTransaction(); boolean isInTransaction = connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction(); return TransactionType.isDistributedTransaction(connectionTransaction.getTransactionType()) && !isInTransaction; diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java index 055b0840022a6..c4f0d7631bf91 100644 --- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java +++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.transaction.api.TransactionType; import java.sql.Array; import java.sql.CallableStatement; @@ -152,7 +153,7 @@ public void setAutoCommit(final boolean autoCommit) throws SQLException { if (databaseConnectionManager.getConnectionTransaction().isLocalTransaction()) { processLocalTransaction(); } else { - processDistributeTransaction(); + processDistributedTransaction(); } } @@ -163,12 +164,10 @@ private void processLocalTransaction() throws SQLException { } } - private void processDistributeTransaction() throws SQLException { + private void processDistributedTransaction() throws SQLException { switch (databaseConnectionManager.getConnectionTransaction().getDistributedTransactionOperationType(autoCommit)) { case BEGIN: - databaseConnectionManager.close(); - databaseConnectionManager.getConnectionTransaction().begin(); - getConnectionContext().getTransactionContext().setInTransaction(true); + beginDistributedTransaction(); break; case COMMIT: databaseConnectionManager.getConnectionTransaction().commit(); @@ -178,6 +177,24 @@ private void processDistributeTransaction() throws SQLException { } } + private void beginDistributedTransaction() throws SQLException { + databaseConnectionManager.close(); + databaseConnectionManager.getConnectionTransaction().begin(); + getConnectionContext().getTransactionContext().setInTransaction(true); + } + + /** + * Handle auto commit. + * + * @throws SQLException SQL exception + */ + public void handleAutoCommit() throws SQLException { + if (!autoCommit && TransactionType.isDistributedTransaction(databaseConnectionManager.getConnectionTransaction().getTransactionType()) + && !databaseConnectionManager.getConnectionTransaction().isInTransaction()) { + beginDistributedTransaction(); + } + } + @Override public void commit() throws SQLException { try { diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java index c2bba63790112..2fdb560aa3341 100644 --- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java +++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java @@ -87,6 +87,7 @@ import org.apache.shardingsphere.traffic.engine.TrafficEngine; import org.apache.shardingsphere.traffic.exception.metadata.EmptyTrafficExecutionUnitException; import org.apache.shardingsphere.traffic.rule.TrafficRule; +import org.apache.shardingsphere.transaction.util.AutoCommitUtils; import java.sql.Connection; import java.sql.ParameterMetaData; @@ -267,6 +268,12 @@ private boolean decide(final QueryContext queryContext, final ShardingSphereData return executor.getSqlFederationEngine().decide(queryContext.getSqlStatementContext(), queryContext.getParameters(), database, globalRuleMetaData); } + private void handleAutoCommit(final QueryContext queryContext) throws SQLException { + if (AutoCommitUtils.needOpenTransaction(queryContext.getSqlStatementContext().getSqlStatement())) { + connection.handleAutoCommit(); + } + } + private JDBCExecutionUnit createTrafficExecutionUnit(final String trafficInstanceId, final QueryContext queryContext) throws SQLException { DriverExecutionPrepareEngine prepareEngine = createDriverExecutionPrepareEngine(); ExecutionUnit executionUnit = new ExecutionUnit(trafficInstanceId, new SQLUnit(queryContext.getSql(), queryContext.getParameters())); @@ -338,6 +345,7 @@ public int executeUpdate() throws SQLException { } clearPrevious(); QueryContext queryContext = createQueryContext(); + handleAutoCommit(queryContext); trafficInstanceId = getInstanceIdAndSet(queryContext).orElse(null); if (null != trafficInstanceId) { JDBCExecutionUnit executionUnit = createTrafficExecutionUnit(trafficInstanceId, queryContext); @@ -400,6 +408,7 @@ public boolean execute() throws SQLException { } clearPrevious(); QueryContext queryContext = createQueryContext(); + handleAutoCommit(queryContext); trafficInstanceId = getInstanceIdAndSet(queryContext).orElse(null); if (null != trafficInstanceId) { JDBCExecutionUnit executionUnit = createTrafficExecutionUnit(trafficInstanceId, queryContext); @@ -454,6 +463,8 @@ private boolean executeWithImplicitCommitTransaction() throws SQLException { // CHECKSTYLE:ON connection.rollback(); throw SQLExceptionTransformEngine.toSQLException(ex, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()); + } finally { + connection.setAutoCommit(true); } return result; } @@ -469,6 +480,8 @@ private int executeUpdateWithImplicitCommitTransaction() throws SQLException { // CHECKSTYLE:ON connection.rollback(); throw SQLExceptionTransformEngine.toSQLException(ex, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()); + } finally { + connection.setAutoCommit(true); } return result; } diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java index fe78fd1d84388..8966b3eb1f23e 100644 --- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java +++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java @@ -81,6 +81,7 @@ import org.apache.shardingsphere.traffic.exception.metadata.EmptyTrafficExecutionUnitException; import org.apache.shardingsphere.traffic.executor.TrafficExecutorCallback; import org.apache.shardingsphere.traffic.rule.TrafficRule; +import org.apache.shardingsphere.transaction.util.AutoCommitUtils; import java.sql.Connection; import java.sql.ResultSet; @@ -310,6 +311,7 @@ private int executeUpdate(final ExecuteUpdateCallback updateCallback, final SQLS private int executeUpdate0(final String sql, final ExecuteUpdateCallback updateCallback, final TrafficExecutorCallback trafficCallback) throws SQLException { QueryContext queryContext = createQueryContext(sql); + handleAutoCommit(queryContext); databaseName = queryContext.getDatabaseNameFromSQLStatement().orElse(connection.getDatabaseName()); connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabase(databaseName); trafficInstanceId = getInstanceIdAndSet(queryContext).orElse(null); @@ -335,6 +337,8 @@ private int executeUpdateWithImplicitCommitTransaction(final ExecuteUpdateCallba // CHECKSTYLE:ON connection.rollback(); throw SQLExceptionTransformEngine.toSQLException(ex, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()); + } finally { + connection.setAutoCommit(true); } return result; } @@ -428,6 +432,7 @@ public boolean execute(final String sql, final String[] columnNames) throws SQLE private boolean execute0(final String sql, final ExecuteCallback executeCallback, final TrafficExecutorCallback trafficCallback) throws SQLException { try { QueryContext queryContext = createQueryContext(sql); + handleAutoCommit(queryContext); databaseName = queryContext.getDatabaseNameFromSQLStatement().orElse(connection.getDatabaseName()); connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabase(databaseName); trafficInstanceId = getInstanceIdAndSet(queryContext).orElse(null); @@ -452,6 +457,12 @@ private boolean execute0(final String sql, final ExecuteCallback executeCallback } } + private void handleAutoCommit(final QueryContext queryContext) throws SQLException { + if (AutoCommitUtils.needOpenTransaction(queryContext.getSqlStatementContext().getSqlStatement())) { + connection.handleAutoCommit(); + } + } + private JDBCExecutionUnit createTrafficExecutionUnit(final String trafficInstanceId, final QueryContext queryContext) throws SQLException { DriverExecutionPrepareEngine prepareEngine = createDriverExecutionPrepareEngine(); ExecutionUnit executionUnit = new ExecutionUnit(trafficInstanceId, new SQLUnit(queryContext.getSql(), queryContext.getParameters())); @@ -527,6 +538,8 @@ private boolean executeWithImplicitCommitTransaction(final ExecuteCallback callb // CHECKSTYLE:ON connection.rollback(); throw SQLExceptionTransformEngine.toSQLException(ex, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()); + } finally { + connection.setAutoCommit(true); } return result; } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java index 079fe4bea4669..536530e5829b4 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java @@ -180,6 +180,9 @@ private Collection generateExecutionContexts() { } private boolean isNeedImplicitCommitTransaction(final Collection executionContexts) { + if (!databaseConnectionManager.getConnectionSession().isAutoCommit()) { + return false; + } TransactionStatus transactionStatus = databaseConnectionManager.getConnectionSession().getTransactionStatus(); if (!TransactionType.isDistributedTransaction(transactionStatus.getTransactionType()) || transactionStatus.isInTransaction()) { return false; diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/alterresource/AddResourceTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/alterresource/AddResourceTestCase.java index e464224e42a73..5df2d02a741ea 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/alterresource/AddResourceTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/alterresource/AddResourceTestCase.java @@ -18,12 +18,10 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.alterresource; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -36,8 +34,8 @@ @TransactionTestCase(adapters = TransactionTestConstants.PROXY, scenario = "addResource") public final class AddResourceTestCase extends BaseTransactionTestCase { - public AddResourceTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public AddResourceTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/alterresource/CloseResourceTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/alterresource/CloseResourceTestCase.java index a008e8ab5d025..fbee253e27a60 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/alterresource/CloseResourceTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/alterresource/CloseResourceTestCase.java @@ -19,12 +19,10 @@ import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -35,8 +33,8 @@ @Slf4j public final class CloseResourceTestCase extends BaseTransactionTestCase { - public CloseResourceTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public CloseResourceTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/AutoCommitTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/AutoCommitTestCase.java new file mode 100644 index 0000000000000..41c271849d044 --- /dev/null +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/AutoCommitTestCase.java @@ -0,0 +1,92 @@ +/* + * 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.transaction.cases.autocommit; + +import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Auto commit transaction integration test. + */ +public abstract class AutoCommitTestCase extends BaseTransactionTestCase { + + protected AutoCommitTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); + } + + protected void assertAutoCommitWithStatement() throws SQLException { + try (Connection connection = getDataSource().getConnection()) { + connection.setAutoCommit(false); + executeWithLog(connection, "DELETE FROM account"); + assertFalse(connection.getAutoCommit()); + executeWithLog(connection, "INSERT INTO account VALUES (1, 1, 1)"); + connection.commit(); + assertFalse(connection.getAutoCommit()); + executeUpdateWithLog(connection, "INSERT INTO account VALUES (2, 2, 2)"); + connection.commit(); + assertFalse(connection.getAutoCommit()); + executeWithLog(connection, "INSERT INTO account VALUES (3, 3, 3)"); + connection.rollback(); + assertFalse(connection.getAutoCommit()); + assertAccountRowCount(connection, 2); + connection.setAutoCommit(true); + assertTrue(connection.getAutoCommit()); + executeWithLog(connection, "INSERT INTO account VALUES (4, 4, 4)"); + assertAccountRowCount(connection, 3); + } + } + + protected void assertAutoCommitWithPrepareStatement() throws SQLException { + try (Connection connection = getDataSource().getConnection()) { + PreparedStatement prepareStatement = connection.prepareStatement("INSERT INTO account VALUES(?, ?, ?)"); + connection.setAutoCommit(false); + executeWithLog(connection, "DELETE FROM account"); + assertFalse(connection.getAutoCommit()); + setPrepareStatementParameters(prepareStatement, 1); + prepareStatement.execute(); + connection.commit(); + assertFalse(connection.getAutoCommit()); + setPrepareStatementParameters(prepareStatement, 2); + prepareStatement.executeUpdate(); + connection.commit(); + assertFalse(connection.getAutoCommit()); + setPrepareStatementParameters(prepareStatement, 3); + prepareStatement.execute(); + connection.rollback(); + assertFalse(connection.getAutoCommit()); + assertAccountRowCount(connection, 2); + connection.setAutoCommit(true); + assertTrue(connection.getAutoCommit()); + setPrepareStatementParameters(prepareStatement, 4); + prepareStatement.execute(); + assertAccountRowCount(connection, 3); + } + } + + private void setPrepareStatementParameters(final PreparedStatement prepareStatement, final int value) throws SQLException { + prepareStatement.setInt(1, value); + prepareStatement.setInt(2, value); + prepareStatement.setInt(3, value); + } +} diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/MySQLAutoCommitTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/MySQLAutoCommitTestCase.java index c83052b34933f..9cbed536b22bf 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/MySQLAutoCommitTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/MySQLAutoCommitTestCase.java @@ -17,15 +17,12 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.autocommit; -import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.apache.shardingsphere.transaction.api.TransactionType; import org.awaitility.Awaitility; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.TimeUnit; @@ -36,16 +33,20 @@ /** * MySQL auto commit transaction integration test. */ -@TransactionTestCase(dbTypes = TransactionTestConstants.MYSQL, transactionTypes = TransactionType.LOCAL) -public final class MySQLAutoCommitTestCase extends BaseTransactionTestCase { +@TransactionTestCase(dbTypes = TransactionTestConstants.MYSQL) +public final class MySQLAutoCommitTestCase extends AutoCommitTestCase { - public MySQLAutoCommitTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MySQLAutoCommitTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override public void executeTest(final TransactionContainerComposer containerComposer) throws SQLException { - assertAutoCommit(); + if (TransactionType.LOCAL == getTransactionType()) { + assertAutoCommit(); + } + assertAutoCommitWithStatement(); + assertAutoCommitWithPrepareStatement(); } private void assertAutoCommit() throws SQLException { diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/PostgreSQLAutoCommitTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/PostgreSQLAutoCommitTestCase.java index 09b53eecaeaee..cba9de9467b74 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/PostgreSQLAutoCommitTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/autocommit/PostgreSQLAutoCommitTestCase.java @@ -17,15 +17,12 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.autocommit; -import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.apache.shardingsphere.transaction.api.TransactionType; import org.awaitility.Awaitility; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.TimeUnit; @@ -36,16 +33,20 @@ /** * PostgreSQL auto commit transaction integration test. */ -@TransactionTestCase(dbTypes = TransactionTestConstants.POSTGRESQL, transactionTypes = TransactionType.LOCAL) -public final class PostgreSQLAutoCommitTestCase extends BaseTransactionTestCase { +@TransactionTestCase(dbTypes = TransactionTestConstants.POSTGRESQL) +public final class PostgreSQLAutoCommitTestCase extends AutoCommitTestCase { - public PostgreSQLAutoCommitTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public PostgreSQLAutoCommitTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override public void executeTest(final TransactionContainerComposer containerComposer) throws SQLException { - assertAutoCommit(); + if (TransactionType.LOCAL == getTransactionType()) { + assertAutoCommit(); + } + assertAutoCommitWithStatement(); + assertAutoCommitWithPrepareStatement(); } private void assertAutoCommit() throws SQLException { diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/base/BaseTransactionTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/base/BaseTransactionTestCase.java index 1cb2ed2b0f625..ce01ca9869706 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/base/BaseTransactionTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/base/BaseTransactionTestCase.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; +import org.apache.shardingsphere.transaction.api.TransactionType; import javax.sql.DataSource; import java.sql.Connection; @@ -42,9 +43,7 @@ @Slf4j public abstract class BaseTransactionTestCase { - private final TransactionBaseE2EIT baseTransactionITCase; - - private final DataSource dataSource; + private final TransactionTestCaseParameter parameters; /** * Execute test cases. @@ -131,4 +130,27 @@ protected void assertAccountBalances(final Connection connection, final int... e private void assertBalance(final int actual, final int expected) { assertThat(String.format("Balance is %s, should be %s.", actual, expected), actual, is(expected)); } + + @Getter + @RequiredArgsConstructor + public static class TransactionTestCaseParameter { + + private final TransactionBaseE2EIT baseTransactionITCase; + + private final DataSource dataSource; + + private final TransactionType transactionType; + } + + protected DataSource getDataSource() { + return parameters.getDataSource(); + } + + protected TransactionBaseE2EIT getBaseTransactionITCase() { + return parameters.getBaseTransactionITCase(); + } + + protected TransactionType getTransactionType() { + return parameters.getTransactionType(); + } } diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/classictransfer/ClassicTransferTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/classictransfer/ClassicTransferTestCase.java index 8567c99996fe4..fe52a060dbfc9 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/classictransfer/ClassicTransferTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/classictransfer/ClassicTransferTestCase.java @@ -21,7 +21,6 @@ import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.testcontainers.shaded.org.awaitility.Awaitility; @@ -44,8 +43,8 @@ @TransactionTestCase public final class ClassicTransferTestCase extends BaseTransactionTestCase { - public ClassicTransferTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public ClassicTransferTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/BroadcastTableTransactionTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/BroadcastTableTransactionTestCase.java index 4f75236166755..4cc8bf644a236 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/BroadcastTableTransactionTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/BroadcastTableTransactionTestCase.java @@ -19,11 +19,9 @@ import lombok.SneakyThrows; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -35,8 +33,8 @@ public final class BroadcastTableTransactionTestCase extends BaseTransactionTest private static final String T_ADDRESS = "t_address"; - public BroadcastTableTransactionTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public BroadcastTableTransactionTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/ExceptionInTransactionTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/ExceptionInTransactionTestCase.java index 937d0cf85c2d5..499e3d9e543db 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/ExceptionInTransactionTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/ExceptionInTransactionTestCase.java @@ -19,12 +19,10 @@ import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -39,8 +37,8 @@ @Slf4j public final class ExceptionInTransactionTestCase extends BaseTransactionTestCase { - public ExceptionInTransactionTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public ExceptionInTransactionTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/ImplicitCommitTransactionTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/ImplicitCommitTransactionTestCase.java index e2b10f49037e9..ecddd7483d104 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/ImplicitCommitTransactionTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/ImplicitCommitTransactionTestCase.java @@ -18,16 +18,15 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.commitrollback; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.transaction.api.TransactionType; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Implicit commit transaction integration test. @@ -37,8 +36,8 @@ public final class ImplicitCommitTransactionTestCase extends BaseTransactionTest private static final String T_ADDRESS = "t_address"; - public ImplicitCommitTransactionTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public ImplicitCommitTransactionTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override @@ -61,7 +60,9 @@ protected void executeTest(final TransactionContainerComposer containerComposer) private void assertBroadcastTableImplicitCommit() throws SQLException { try (Connection connection = getDataSource().getConnection()) { + assertTrue(connection.getAutoCommit()); executeWithLog(connection, "INSERT INTO t_address (id, code, address) VALUES (1, '1', 'Nanjing')"); + assertTrue(connection.getAutoCommit()); assertThrows(SQLException.class, () -> executeWithLog(connection, "INSERT INTO t_address (id, code, address) VALUES (1, '1', 'Nanjing')")); } try (Connection connection = getDataSource().getConnection()) { @@ -71,7 +72,9 @@ private void assertBroadcastTableImplicitCommit() throws SQLException { private void assertShardingTableImplicitCommit() throws SQLException { try (Connection connection = getDataSource().getConnection()) { + assertTrue(connection.getAutoCommit()); executeWithLog(connection, "INSERT INTO account(id, balance, transaction_id) VALUES (1, 1, 1), (2, 2, 2)"); + assertTrue(connection.getAutoCommit()); assertThrows(SQLException.class, () -> executeWithLog(connection, "INSERT INTO account(id, balance, transaction_id) VALUES (1, 1, 1), (2, 2, 2)")); } try (Connection connection = getDataSource().getConnection()) { diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiJDBCConnectionsTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiJDBCConnectionsTestCase.java index bc60cb2fd8167..820ca74e6ff92 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiJDBCConnectionsTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiJDBCConnectionsTestCase.java @@ -18,13 +18,11 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.commitrollback; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.apache.shardingsphere.transaction.api.TransactionType; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -35,8 +33,8 @@ @TransactionTestCase(dbTypes = TransactionTestConstants.MYSQL, transactionTypes = TransactionType.XA) public final class MultiJDBCConnectionsTestCase extends BaseTransactionTestCase { - public MultiJDBCConnectionsTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MultiJDBCConnectionsTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java index 10ba4092a4ccd..8ab535bc678b7 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java @@ -18,11 +18,9 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.commitrollback; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -32,8 +30,8 @@ @TransactionTestCase public final class MultiOperationsCommitAndRollbackTestCase extends BaseTransactionTestCase { - public MultiOperationsCommitAndRollbackTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MultiOperationsCommitAndRollbackTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiTableCommitAndRollbackTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiTableCommitAndRollbackTestCase.java index df594e3e93480..bf5ce93a577dc 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiTableCommitAndRollbackTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiTableCommitAndRollbackTestCase.java @@ -18,11 +18,9 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.commitrollback; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -36,8 +34,8 @@ public final class MultiTableCommitAndRollbackTestCase extends BaseTransactionTe private static final String T_ORDER_ITEM = "t_order_item"; - public MultiTableCommitAndRollbackTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MultiTableCommitAndRollbackTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiTransactionInConnectionTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiTransactionInConnectionTestCase.java index f31030cb3d619..bdee5928cb8af 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiTransactionInConnectionTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiTransactionInConnectionTestCase.java @@ -18,11 +18,9 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.commitrollback; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -33,8 +31,8 @@ @TransactionTestCase public final class MultiTransactionInConnectionTestCase extends BaseTransactionTestCase { - public MultiTransactionInConnectionTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MultiTransactionInConnectionTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/SingleTableCommitAndRollbackTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/SingleTableCommitAndRollbackTestCase.java index 2d5cb408d2f74..5e1f71dd4e28c 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/SingleTableCommitAndRollbackTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/SingleTableCommitAndRollbackTestCase.java @@ -18,11 +18,9 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.commitrollback; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; @@ -33,8 +31,8 @@ @TransactionTestCase public final class SingleTableCommitAndRollbackTestCase extends BaseTransactionTestCase { - public SingleTableCommitAndRollbackTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public SingleTableCommitAndRollbackTestCase(TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/cursor/OpenGaussCursorTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/cursor/OpenGaussCursorTestCase.java index bd784c44ee321..fc3af405a555b 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/cursor/OpenGaussCursorTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/cursor/OpenGaussCursorTestCase.java @@ -19,13 +19,11 @@ import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.command.CursorSQLCommand; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import javax.xml.bind.JAXB; import java.sql.Connection; import java.sql.ResultSet; @@ -46,8 +44,8 @@ public final class OpenGaussCursorTestCase extends BaseTransactionTestCase { private final CursorSQLCommand cursorSQLCommand; - public OpenGaussCursorTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public OpenGaussCursorTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); this.cursorSQLCommand = loadCursorSQLCommand(); } diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/deadlock/TransactionDeadlockTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/deadlock/TransactionDeadlockTestCase.java index 00995b4d71b2a..f8a7bc9795d86 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/deadlock/TransactionDeadlockTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/deadlock/TransactionDeadlockTestCase.java @@ -19,12 +19,10 @@ import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import java.util.Collection; @@ -49,8 +47,8 @@ public final class TransactionDeadlockTestCase extends BaseTransactionTestCase { private final ExecutorService executor = Executors.newFixedThreadPool(2); - public TransactionDeadlockTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public TransactionDeadlockTestCase(TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/nested/NestedTransactionTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/nested/NestedTransactionTestCase.java index ca349201e104d..4227c042ca397 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/nested/NestedTransactionTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/nested/NestedTransactionTestCase.java @@ -19,13 +19,11 @@ import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.apache.shardingsphere.transaction.api.TransactionType; -import javax.sql.DataSource; import java.sql.SQLException; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -37,8 +35,8 @@ @TransactionTestCase(transactionTypes = TransactionType.LOCAL, adapters = TransactionTestConstants.JDBC) public final class NestedTransactionTestCase extends BaseTransactionTestCase { - public NestedTransactionTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public NestedTransactionTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/MySQLSetReadOnlyTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/MySQLSetReadOnlyTestCase.java index 8b09cdc68d328..fe91a7bd6e9cd 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/MySQLSetReadOnlyTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/MySQLSetReadOnlyTestCase.java @@ -18,12 +18,10 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.readonly; import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -38,8 +36,8 @@ @Slf4j public final class MySQLSetReadOnlyTestCase extends SetReadOnlyTestCase { - public MySQLSetReadOnlyTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MySQLSetReadOnlyTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java index 251868f24bb30..0bf070cb7851f 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java @@ -18,12 +18,10 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.readonly; import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -34,8 +32,8 @@ @Slf4j public final class PostgreSQLSetReadOnlyTestCase extends SetReadOnlyTestCase { - public PostgreSQLSetReadOnlyTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public PostgreSQLSetReadOnlyTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/SetReadOnlyTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/SetReadOnlyTestCase.java index 5164dae0df5fc..0511a33430e0d 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/SetReadOnlyTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/SetReadOnlyTestCase.java @@ -18,9 +18,7 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.readonly; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -34,8 +32,8 @@ */ public abstract class SetReadOnlyTestCase extends BaseTransactionTestCase { - protected SetReadOnlyTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + protected SetReadOnlyTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } void assertNotSetReadOnly() throws SQLException { diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readwritesplitting/ReadwriteSplittingInTransactionTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readwritesplitting/ReadwriteSplittingInTransactionTestCase.java index 9c3a6af03995e..2808703f85b92 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readwritesplitting/ReadwriteSplittingInTransactionTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readwritesplitting/ReadwriteSplittingInTransactionTestCase.java @@ -18,12 +18,10 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.readwritesplitting; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -37,8 +35,8 @@ @TransactionTestCase(dbTypes = TransactionTestConstants.MYSQL, scenario = "readwrite-splitting", adapters = TransactionTestConstants.PROXY) public final class ReadwriteSplittingInTransactionTestCase extends BaseTransactionTestCase { - public ReadwriteSplittingInTransactionTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public ReadwriteSplittingInTransactionTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/BaseSavePointTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/BaseSavePointTestCase.java index 4d88a180b46ec..1c95a15c308c3 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/BaseSavePointTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/BaseSavePointTestCase.java @@ -18,9 +18,7 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.savepoint; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import java.sql.Savepoint; @@ -30,8 +28,8 @@ */ public abstract class BaseSavePointTestCase extends BaseTransactionTestCase { - protected BaseSavePointTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + protected BaseSavePointTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } void assertRollbackToSavepoint() throws SQLException { diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/MySQLSavePointTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/MySQLSavePointTestCase.java index 6e79e555b1c5b..25d0f7e8d71c9 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/MySQLSavePointTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/MySQLSavePointTestCase.java @@ -17,12 +17,10 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.savepoint; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -35,8 +33,8 @@ @TransactionTestCase(dbTypes = TransactionTestConstants.MYSQL) public final class MySQLSavePointTestCase extends BaseSavePointTestCase { - public MySQLSavePointTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MySQLSavePointTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/OpenGaussSavePointTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/OpenGaussSavePointTestCase.java index e982904c28de0..2b58331c8d0cc 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/OpenGaussSavePointTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/OpenGaussSavePointTestCase.java @@ -17,13 +17,11 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.savepoint; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.opengauss.jdbc.PSQLSavepoint; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -38,8 +36,8 @@ @TransactionTestCase(dbTypes = TransactionTestConstants.OPENGAUSS) public final class OpenGaussSavePointTestCase extends BaseSavePointTestCase { - public OpenGaussSavePointTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public OpenGaussSavePointTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java index 692badc7dca5e..9ab6a3f1400aa 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java @@ -18,13 +18,11 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.savepoint; import lombok.SneakyThrows; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.postgresql.jdbc.PSQLSavepoint; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -39,8 +37,8 @@ @TransactionTestCase(dbTypes = TransactionTestConstants.POSTGRESQL) public final class PostgreSQLSavePointTestCase extends BaseSavePointTestCase { - public PostgreSQLSavePointTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public PostgreSQLSavePointTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/MySQLLocalTruncateTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/MySQLLocalTruncateTestCase.java index 32147926e6795..06daa73e9a03a 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/MySQLLocalTruncateTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/MySQLLocalTruncateTestCase.java @@ -18,13 +18,11 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.truncate; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.apache.shardingsphere.transaction.api.TransactionType; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -34,8 +32,8 @@ @TransactionTestCase(dbTypes = TransactionTestConstants.MYSQL, transactionTypes = TransactionType.LOCAL) public final class MySQLLocalTruncateTestCase extends BaseTransactionTestCase { - public MySQLLocalTruncateTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MySQLLocalTruncateTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/MySQLXATruncateTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/MySQLXATruncateTestCase.java index 53f1e3d1b8a17..104fc154f6ef8 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/MySQLXATruncateTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/MySQLXATruncateTestCase.java @@ -20,13 +20,11 @@ import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.infra.exception.dialect.exception.transaction.TableModifyInTransactionException; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.apache.shardingsphere.transaction.api.TransactionType; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -39,8 +37,8 @@ @Slf4j public final class MySQLXATruncateTestCase extends BaseTransactionTestCase { - public MySQLXATruncateTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public MySQLXATruncateTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/PostgreSQLAndOpenGaussTruncateTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/PostgreSQLAndOpenGaussTruncateTestCase.java index f855c0c2b4feb..8691a11b42a2c 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/PostgreSQLAndOpenGaussTruncateTestCase.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/truncate/PostgreSQLAndOpenGaussTruncateTestCase.java @@ -18,12 +18,10 @@ package org.apache.shardingsphere.test.e2e.transaction.cases.truncate; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; -import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionContainerComposer; import org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -33,8 +31,8 @@ @TransactionTestCase(dbTypes = {TransactionTestConstants.POSTGRESQL, TransactionTestConstants.OPENGAUSS}) public final class PostgreSQLAndOpenGaussTruncateTestCase extends BaseTransactionTestCase { - public PostgreSQLAndOpenGaussTruncateTestCase(final TransactionBaseE2EIT baseTransactionITCase, final DataSource dataSource) { - super(baseTransactionITCase, dataSource); + public PostgreSQLAndOpenGaussTruncateTestCase(final TransactionTestCaseParameter parameters) { + super(parameters); } @Override diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/engine/base/TransactionBaseE2EIT.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/engine/base/TransactionBaseE2EIT.java index a897f0f19ba4f..b38ddac849135 100644 --- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/engine/base/TransactionBaseE2EIT.java +++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/engine/base/TransactionBaseE2EIT.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.test.e2e.env.container.atomic.storage.DockerStorageContainer; import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment; import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase; +import org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase.TransactionTestCaseParameter; import org.apache.shardingsphere.test.e2e.transaction.engine.command.CommonSQLCommand; import org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants; import org.apache.shardingsphere.test.e2e.transaction.env.TransactionE2EEnvironment; @@ -43,7 +44,6 @@ import org.junit.jupiter.params.provider.ArgumentsSource; import org.testcontainers.shaded.org.awaitility.Awaitility; -import javax.sql.DataSource; import javax.xml.bind.JAXB; import java.io.File; import java.sql.Connection; @@ -136,7 +136,8 @@ private void doCallTestCases(final TransactionTestParameter testParam, final Tra for (Class each : testParam.getTransactionTestCaseClasses()) { log.info("Transaction IT {} -> {} test begin.", testParam, each.getSimpleName()); try { - each.getConstructor(TransactionBaseE2EIT.class, DataSource.class).newInstance(this, containerComposer.getDataSource()).execute(containerComposer); + each.getConstructor(TransactionTestCaseParameter.class).newInstance(new TransactionTestCaseParameter(this, containerComposer.getDataSource(), testParam.getTransactionTypes().get(0))) + .execute(containerComposer); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON @@ -158,7 +159,8 @@ private void doCallTestCases(final TransactionTestParameter testParam, final Tra } log.info("Call transaction IT {} -> {} -> {} -> {} test begin.", testParam, transactionType, provider, each.getSimpleName()); try { - each.getConstructor(TransactionBaseE2EIT.class, DataSource.class).newInstance(this, containerComposer.getDataSource()).execute(containerComposer); + each.getConstructor(TransactionTestCaseParameter.class).newInstance(new TransactionTestCaseParameter(this, containerComposer.getDataSource(), transactionType)) + .execute(containerComposer); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON