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

(shardingsphere) branch master updated: Fix MySQL read-only transaction failure assertions (#39460)

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

iamhucong 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 e952770a215 Fix MySQL read-only transaction failure assertions (#39460)
e952770a215 is described below

commit e952770a215630a3659c75d64369168cd3e26b82
Author: ZhangCheng <ch...@apache.org>
AuthorDate: Fri Aug 14 18:42:44 2026 +0800

    Fix MySQL read-only transaction failure assertions (#39460)
---
 .../cases/readonly/MySQLSetReadOnlyTestCase.java           | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/cases/readonly/MySQLSetReadOnlyTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/cases/readonly/MySQLSetReadOnlyTestCase.java
index 76bdd916f5d..39e0ef2aafc 100644
--- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/cases/readonly/MySQLSetReadOnlyTestCase.java
+++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/operation/transaction/cases/readonly/MySQLSetReadOnlyTestCase.java
@@ -26,7 +26,7 @@ import java.sql.SQLException;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /**
  * MySQL set read only transaction integration test.
@@ -51,18 +51,14 @@ public final class MySQLSetReadOnlyTestCase extends SetReadOnlyTestCase {
         try (Connection connection = getDataSource().getConnection()) {
             connection.setReadOnly(true);
             assertQueryBalance(connection);
-            executeWithLog(connection, "UPDATE account SET balance = 100 WHERE id = 2;");
-            fail("Update ran successfully, should failed.");
-        } catch (final SQLException ex) {
-            assertThat(ex.getMessage(), is("Connection is read-only. Queries leading to data modification are not allowed."));
+            SQLException actualException = assertThrows(SQLException.class, () -> executeWithLog(connection, "UPDATE account SET balance = 100 WHERE id = 2;"));
+            assertThat(actualException.getMessage(), is("Connection is read-only. Queries leading to data modification are not allowed."));
         }
         try (Connection connection = getDataSource().getConnection()) {
             connection.setAutoCommit(false);
             connection.setReadOnly(true);
-            executeWithLog(connection, "UPDATE account SET balance = 100 WHERE id = 2;");
-            fail("Update ran successfully, should failed.");
-        } catch (final SQLException ex) {
-            assertThat(ex.getMessage(), is("Connection is read-only. Queries leading to data modification are not allowed."));
+            SQLException actualException = assertThrows(SQLException.class, () -> executeWithLog(connection, "UPDATE account SET balance = 100 WHERE id = 2;"));
+            assertThat(actualException.getMessage(), is("Connection is read-only. Queries leading to data modification are not allowed."));
         }
     }
 }