This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 d242d705ab1 Add mysql E2E case of transaction execution exception and
then commit (#31943)
d242d705ab1 is described below
commit d242d705ab1f12eeeed1309fc63f991d7743adfc
Author: ZhangCheng <[email protected]>
AuthorDate: Mon Jul 1 16:16:52 2024 +0800
Add mysql E2E case of transaction execution exception and then commit
(#31943)
---
.../cases/autocommit/MySQLAutoCommitTestCase.java | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
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 e0351ceb28f..48d905fb2e6 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,6 +17,7 @@
package org.apache.shardingsphere.test.e2e.transaction.cases.autocommit;
+import lombok.extern.slf4j.Slf4j;
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;
@@ -34,6 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* MySQL auto commit transaction integration test.
*/
@TransactionTestCase(dbTypes = TransactionTestConstants.MYSQL)
+@Slf4j
public final class MySQLAutoCommitTestCase extends AutoCommitTestCase {
public MySQLAutoCommitTestCase(final TransactionTestCaseParameter
testCaseParam) {
@@ -48,6 +50,26 @@ public final class MySQLAutoCommitTestCase extends
AutoCommitTestCase {
assertAutoCommitWithStatement();
assertAutoCommitWithPreparedStatement();
assertAutoCommitWithoutCommit();
+ assertExceptionForceCommit();
+ }
+
+ private void assertExceptionForceCommit() throws SQLException {
+ Connection connection = getDataSource().getConnection();
+ try {
+ executeWithLog(connection, "DELETE FROM account");
+ connection.setAutoCommit(false);
+ executeWithLog(connection, "INSERT INTO account VALUES (1, 1, 1),
(2, 2, 2)");
+ int causeExceptionResult = 1 / 0;
+ log.info("Caused exception result: {}", causeExceptionResult);
+ executeWithLog(connection, "INSERT INTO account VALUES (3, 3, 3),
(4, 4, 4)");
+ } catch (final ArithmeticException ignored) {
+ } finally {
+ connection.commit();
+ connection.close();
+ }
+ try (Connection queryConnection = getDataSource().getConnection()) {
+ assertAccountRowCount(queryConnection, 2);
+ }
}
private void assertAutoCommit() throws SQLException {