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 17223c82c54 Add set transaction type test case (#23648)
17223c82c54 is described below

commit 17223c82c54108afbaa7bb5ef8c4abfe15873b94
Author: ZhangCheng <[email protected]>
AuthorDate: Thu Jan 19 17:06:26 2023 +0800

    Add set transaction type test case (#23648)
    
    * Add set transaction type test case
    
    * Fix
    
    * Fix
    
    * Fix
---
 .../cases/settype/SetTransactionTypeTestCase.java  | 64 ++++++++++++++++++++++
 .../settype/TransactionTypeHolderTestCase.java     | 56 +++++++++++++++++++
 .../src/test/resources/env/it-env.properties       |  2 +-
 3 files changed, 121 insertions(+), 1 deletion(-)

diff --git 
a/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/settype/SetTransactionTypeTestCase.java
 
b/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/settype/SetTransactionTypeTestCase.java
new file mode 100644
index 00000000000..88d58078c17
--- /dev/null
+++ 
b/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/settype/SetTransactionTypeTestCase.java
@@ -0,0 +1,64 @@
+/*
+ * 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.test.e2e.transaction.cases.settype;
+
+import 
org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase;
+import 
org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT;
+import 
org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase;
+import 
org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants;
+import org.apache.shardingsphere.transaction.api.TransactionType;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+/**
+ * Set transaction type test case.
+ */
+@TransactionTestCase(adapters = TransactionTestConstants.PROXY, 
transactionTypes = TransactionType.XA)
+public class SetTransactionTypeTestCase extends BaseTransactionTestCase {
+    
+    public SetTransactionTypeTestCase(final TransactionBaseE2EIT 
baseTransactionITCase, final DataSource dataSource) {
+        super(baseTransactionITCase, dataSource);
+    }
+    
+    @Override
+    protected void executeTest() throws SQLException {
+        try (Connection connection = getDataSource().getConnection()) {
+            assertTransactionType(connection, TransactionType.XA.name());
+            executeWithLog(connection, "SET DIST VARIABLE TRANSACTION_TYPE = 
'LOCAL'");
+            connection.setAutoCommit(false);
+            assertTransactionType(connection, TransactionType.LOCAL.name());
+            connection.rollback();
+        }
+        try (Connection connection = getDataSource().getConnection()) {
+            assertTransactionType(connection, TransactionType.XA.name());
+        }
+    }
+    
+    private void assertTransactionType(final Connection connection, final 
String transactionType) throws SQLException {
+        ResultSet resultSet = executeQueryWithLog(connection, "SHOW DIST 
VARIABLE WHERE NAME = transaction_type;");
+        while (resultSet.next()) {
+            assertThat(resultSet.getString("variable_value"), 
is(transactionType));
+        }
+    }
+}
diff --git 
a/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/settype/TransactionTypeHolderTestCase.java
 
b/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/settype/TransactionTypeHolderTestCase.java
new file mode 100644
index 00000000000..186db3cb61a
--- /dev/null
+++ 
b/test/e2e/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/settype/TransactionTypeHolderTestCase.java
@@ -0,0 +1,56 @@
+/*
+ * 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.test.e2e.transaction.cases.settype;
+
+import 
org.apache.shardingsphere.test.e2e.transaction.cases.base.BaseTransactionTestCase;
+import 
org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionBaseE2EIT;
+import 
org.apache.shardingsphere.test.e2e.transaction.engine.base.TransactionTestCase;
+import 
org.apache.shardingsphere.test.e2e.transaction.engine.constants.TransactionTestConstants;
+import org.apache.shardingsphere.transaction.api.TransactionType;
+import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+/**
+ * Transaction type holder test case.
+ */
+@TransactionTestCase(adapters = TransactionTestConstants.JDBC, 
transactionTypes = TransactionType.XA)
+public final class TransactionTypeHolderTestCase extends 
BaseTransactionTestCase {
+    
+    public TransactionTypeHolderTestCase(final TransactionBaseE2EIT 
baseTransactionITCase, final DataSource dataSource) {
+        super(baseTransactionITCase, dataSource);
+    }
+    
+    @Override
+    protected void executeTest() throws SQLException {
+        try (Connection connection = getDataSource().getConnection()) {
+            TransactionTypeHolder.set(TransactionType.LOCAL);
+            assertThat(TransactionTypeHolder.get(), is(TransactionType.LOCAL));
+            connection.setAutoCommit(false);
+            connection.rollback();
+        } finally {
+            TransactionTypeHolder.set(TransactionType.XA);
+            assertThat(TransactionTypeHolder.get(), is(TransactionType.XA));
+        }
+    }
+}
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 05bf67cd5a7..5d30aad7cd2 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=MultiOperationsCommitAndRollbackTestCase, 
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, 
SetTransactionTypeTestCase, TransactionTypeHolderTestCase
 # transaction.it.env.transtypes=LOCAL, XA, BASE
 transaction.it.env.transtypes=LOCAL, XA
 # transaction.it.env.xa.providers=Atomikos, Bitronix, Narayana

Reply via email to