You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2022/11/07 10:12:23 UTC
[shardingsphere] branch master updated: Add nested transaction test case (#21990)
This is an automated email from the ASF dual-hosted git repository.
tuichenchuxin 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 b1ef6cf80c5 Add nested transaction test case (#21990)
b1ef6cf80c5 is described below
commit b1ef6cf80c5dbdd12ae754da4b7029d4398878a9
Author: ZhangCheng <fl...@outlook.com>
AuthorDate: Mon Nov 7 18:12:07 2022 +0800
Add nested transaction test case (#21990)
---
.../cases/nested/NestedTransactionTestCase.java | 59 ++++++++++++++++++++++
.../src/test/resources/env/it-env.properties | 2 +-
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/nested/NestedTransactionTestCase.java b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/nested/NestedTransactionTestCase.java
new file mode 100644
index 00000000000..e584836e647
--- /dev/null
+++ b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/nested/NestedTransactionTestCase.java
@@ -0,0 +1,59 @@
+/*
+ * 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.integration.transaction.cases.nested;
+
+import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
+import org.apache.shardingsphere.integration.transaction.cases.base.BaseTransactionTestCase;
+import org.apache.shardingsphere.integration.transaction.engine.base.BaseTransactionITCase;
+import org.apache.shardingsphere.integration.transaction.engine.base.TransactionTestCase;
+import org.apache.shardingsphere.test.integration.env.container.atomic.constants.AdapterContainerConstants;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.junit.Assert;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+
+/**
+ * Nested transaction test case.
+ */
+@TransactionTestCase(transactionTypes = TransactionType.LOCAL, adapters = AdapterContainerConstants.JDBC)
+public class NestedTransactionTestCase extends BaseTransactionTestCase {
+
+ public NestedTransactionTestCase(final BaseTransactionITCase baseTransactionITCase, final DataSource dataSource) {
+ super(baseTransactionITCase, dataSource);
+ }
+
+ @Override
+ protected void executeTest() throws SQLException {
+ ShardingSphereConnection conn1 = (ShardingSphereConnection) getDataSource().getConnection();
+ Assert.assertFalse(conn1.isHoldTransaction());
+ conn1.setAutoCommit(false);
+ Assert.assertTrue(conn1.isHoldTransaction());
+ requiresNewTransaction();
+ Assert.assertTrue(conn1.isHoldTransaction());
+ conn1.commit();
+ }
+
+ private void requiresNewTransaction() throws SQLException {
+ ShardingSphereConnection conn2 = (ShardingSphereConnection) getDataSource().getConnection();
+ Assert.assertFalse(conn2.isHoldTransaction());
+ conn2.setAutoCommit(false);
+ Assert.assertTrue(conn2.isHoldTransaction());
+ conn2.commit();
+ }
+}
diff --git a/test/integration-test/transaction/src/test/resources/env/it-env.properties b/test/integration-test/transaction/src/test/resources/env/it-env.properties
index fac4d6e9534..535b342c6f8 100644
--- a/test/integration-test/transaction/src/test/resources/env/it-env.properties
+++ b/test/integration-test/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= MySQLAutoCommitTestCase, PostgresSQLAutoCommitTestCase, ClassicTransferTestCase, MultiTableCommitAndRollbackTestCase, SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase, MySQLSavePointTestCase, PostgreSQLSavePointTestCase
-transaction.it.env.cases=BroadcastTableTransactionTestCase, ExceptionInTransactionTestCase, MultiTableCommitAndRollbackTestCase, SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase, MySQLSavePointTestCase, MySQLLocalTruncateTestCase, MySQLXATruncateTestCase, OpenGaussCursorTestCase
+transaction.it.env.cases=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