You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ch...@apache.org on 2026/08/14 04:13:36 UTC

(shardingsphere) branch master updated: Fix multi-table transaction outcome assertions (#39451)

This is an automated email from the ASF dual-hosted git repository.

FlyingZC 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 9b423bee2b9 Fix multi-table transaction outcome assertions (#39451)
9b423bee2b9 is described below

commit 9b423bee2b930b3f0cd9b637682b5abaf4ebcd5c
Author: ZhangCheng <ch...@apache.org>
AuthorDate: Fri Aug 14 12:13:30 2026 +0800

    Fix multi-table transaction outcome assertions (#39451)
---
 .../MultiTableCommitAndRollbackTestCase.java       | 33 +++++++++++++++-------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/cases/commitrollback/MultiTableCommitAndRollbackTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/cases/commitrollback/MultiTableCommitAndRollbackTestCase.java
index 9e2fb4be752..3b427534910 100644
--- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/cases/commitrollback/MultiTableCommitAndRollbackTestCase.java
+++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/cases/commitrollback/MultiTableCommitAndRollbackTestCase.java
@@ -23,6 +23,10 @@ import org.apache.shardingsphere.test.e2e.operation.transaction.engine.base.Tran
 
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 
 /**
  * Multi-table transaction commit and rollback integration test.
@@ -49,17 +53,17 @@ public final class MultiTableCommitAndRollbackTestCase extends BaseTransactionTe
             connection.setAutoCommit(false);
             assertTableRowCount(connection, T_ORDER, 0);
             assertTableRowCount(connection, T_ORDER_ITEM, 0);
-            executeSqlListWithLog(connection,
-                    "INSERT INTO t_order (order_id, user_id, status) VALUES (1, 1, '1');",
-                    "INSERT INTO t_order (order_id, user_id, status) VALUES (2, 2, '2');",
-                    "INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES (1, 1, 1, '1');",
-                    "INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES (2, 2, 2, '2');");
+            assertInsertRows(connection);
             assertTableRowCount(connection, T_ORDER, 2);
             assertTableRowCount(connection, T_ORDER_ITEM, 2);
             connection.rollback();
             assertTableRowCount(connection, T_ORDER, 0);
             assertTableRowCount(connection, T_ORDER_ITEM, 0);
         }
+        try (Connection connection = getDataSource().getConnection()) {
+            assertTableRowCount(connection, T_ORDER, 0);
+            assertTableRowCount(connection, T_ORDER_ITEM, 0);
+        }
     }
     
     private void assertCommit() throws SQLException {
@@ -67,16 +71,25 @@ public final class MultiTableCommitAndRollbackTestCase extends BaseTransactionTe
             connection.setAutoCommit(false);
             assertTableRowCount(connection, T_ORDER, 0);
             assertTableRowCount(connection, T_ORDER_ITEM, 0);
-            executeSqlListWithLog(connection,
-                    "INSERT INTO t_order (order_id, user_id, status) VALUES (1, 1, '1');",
-                    "INSERT INTO t_order (order_id, user_id, status) VALUES (2, 2, '2');",
-                    "INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES (1, 1, 1, '1');",
-                    "INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES (2, 2, 2, '2');");
+            assertInsertRows(connection);
             assertTableRowCount(connection, T_ORDER, 2);
             assertTableRowCount(connection, T_ORDER_ITEM, 2);
             connection.commit();
             assertTableRowCount(connection, T_ORDER, 2);
             assertTableRowCount(connection, T_ORDER_ITEM, 2);
         }
+        try (Connection connection = getDataSource().getConnection()) {
+            assertTableRowCount(connection, T_ORDER, 2);
+            assertTableRowCount(connection, T_ORDER_ITEM, 2);
+        }
+    }
+    
+    private void assertInsertRows(final Connection connection) throws SQLException {
+        try (Statement statement = connection.createStatement()) {
+            assertThat(statement.executeUpdate("INSERT INTO t_order (order_id, user_id, status) VALUES (1, 1, '1');"), is(1));
+            assertThat(statement.executeUpdate("INSERT INTO t_order (order_id, user_id, status) VALUES (2, 2, '2');"), is(1));
+            assertThat(statement.executeUpdate("INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES (1, 1, 1, '1');"), is(1));
+            assertThat(statement.executeUpdate("INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES (2, 2, 2, '2');"), is(1));
+        }
     }
 }