This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new d08e4ac2a0a Fix multi operations in transaction test case (#23512)
d08e4ac2a0a is described below
commit d08e4ac2a0ac0e16ed5544cf71b9b59dec66b608
Author: ZhangCheng <[email protected]>
AuthorDate: Mon Jan 16 08:29:45 2023 +0800
Fix multi operations in transaction test case (#23512)
---
.../MultiOperationsCommitAndRollbackTestCase.java | 46 ++++++++++++----------
.../src/test/resources/env/it-env.properties | 2 +-
2 files changed, 27 insertions(+), 21 deletions(-)
diff --git
a/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java
b/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java
index 8fde86ce5ce..0ad4731756a 100644
---
a/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java
+++
b/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java
@@ -49,29 +49,35 @@ public final class MultiOperationsCommitAndRollbackTestCase
extends BaseTransact
}
private void assertRollback() throws SQLException {
- Connection connection = getDataSource().getConnection();
- connection.setAutoCommit(false);
- assertTableRowCount(connection, TransactionTestConstants.ACCOUNT, 0);
- executeWithLog(connection, "insert into account(id, balance,
transaction_id) values(1, 1, 1);");
- executeWithLog(connection, "insert into account(id, balance,
transaction_id) values(2, 2, 2);");
- executeUpdateWithLog(connection, "update account set balance = 3,
transaction_id = 3 where id = 2;");
- assertQueryAccount(connection, 1, 3);
- connection.rollback();
- assertTableRowCount(connection, TransactionTestConstants.ACCOUNT, 0);
- assertQueryAccount(connection, 1, 2);
+ try (Connection connection = getDataSource().getConnection()) {
+ connection.setAutoCommit(false);
+ assertTableRowCount(connection, TransactionTestConstants.ACCOUNT,
0);
+ executeWithLog(connection, "insert into account(id, balance,
transaction_id) values(1, 1, 1);");
+ executeWithLog(connection, "insert into account(id, balance,
transaction_id) values(2, 2, 2);");
+ executeUpdateWithLog(connection, "update account set balance = 3,
transaction_id = 3 where id = 2;");
+ assertQueryAccount(connection, 1, 3);
+ connection.rollback();
+ }
+ try (Connection connection = getDataSource().getConnection()) {
+ assertTableRowCount(connection, TransactionTestConstants.ACCOUNT,
0);
+ assertQueryAccount(connection, 1, 2);
+ }
}
private void assertCommit() throws SQLException {
- Connection connection = getDataSource().getConnection();
- connection.setAutoCommit(false);
- assertTableRowCount(connection, TransactionTestConstants.ACCOUNT, 0);
- executeWithLog(connection, "insert into account(id, balance,
transaction_id) values(1, 1, 1);");
- executeWithLog(connection, "insert into account(id, balance,
transaction_id) values(2, 2, 2);");
- executeUpdateWithLog(connection, "update account set balance = 3,
transaction_id = 3 where id = 2;");
- assertQueryAccount(connection, 1, 3);
- connection.commit();
- assertTableRowCount(connection, TransactionTestConstants.ACCOUNT, 2);
- assertQueryAccount(connection, 1, 3);
+ try (Connection connection = getDataSource().getConnection()) {
+ connection.setAutoCommit(false);
+ assertTableRowCount(connection, TransactionTestConstants.ACCOUNT,
0);
+ executeWithLog(connection, "insert into account(id, balance,
transaction_id) values(1, 1, 1);");
+ executeWithLog(connection, "insert into account(id, balance,
transaction_id) values(2, 2, 2);");
+ executeUpdateWithLog(connection, "update account set balance = 3,
transaction_id = 3 where id = 2;");
+ assertQueryAccount(connection, 1, 3);
+ connection.commit();
+ }
+ try (Connection connection = getDataSource().getConnection()) {
+ assertTableRowCount(connection, TransactionTestConstants.ACCOUNT,
2);
+ assertQueryAccount(connection, 1, 3);
+ }
}
private void assertQueryAccount(final Connection connection, final int...
expectedBalances) throws SQLException {
diff --git a/test/e2e/transaction/src/test/resources/env/it-env.properties
b/test/e2e/transaction/src/test/resources/env/it-env.properties
index ab14e3a79a2..05bf67cd5a7 100644
--- a/test/e2e/transaction/src/test/resources/env/it-env.properties
+++ b/test/e2e/transaction/src/test/resources/env/it-env.properties
@@ -17,7 +17,7 @@
# transaction.it.type=NONE,DOCKER,NATIVE
transaction.it.env.type=NONE
# transaction.it.env.cases=ClassicTransferTestCase,
PostgreSQLSavePointTestCase
-transaction.it.env.cases=MySQLAutoCommitTestCase,
PostgresSQLAutoCommitTestCase, BroadcastTableTransactionTestCase,
ExceptionInTransactionTestCase, MultiTableCommitAndRollbackTestCase,
SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase,
MySQLSavePointTestCase, MySQLLocalTruncateTestCase, MySQLXATruncateTestCase,
OpenGaussCursorTestCase, NestedTransactionTestCase
+transaction.it.env.cases=MultiOperationsCommitAndRollbackTestCase,
MySQLAutoCommitTestCase, PostgresSQLAutoCommitTestCase,
BroadcastTableTransactionTestCase, ExceptionInTransactionTestCase,
MultiTableCommitAndRollbackTestCase, SingleTableCommitAndRollbackTestCase,
MySQLSetReadOnlyTestCase, MySQLSavePointTestCase, MySQLLocalTruncateTestCase,
MySQLXATruncateTestCase, OpenGaussCursorTestCase, NestedTransactionTestCase
# transaction.it.env.transtypes=LOCAL, XA, BASE
transaction.it.env.transtypes=LOCAL, XA
# transaction.it.env.xa.providers=Atomikos, Bitronix, Narayana