jingshanglu commented on code in PR #19590:
URL: https://github.com/apache/shardingsphere/pull/19590#discussion_r930670518


##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/commitrollback/MultiOperationsCommitAndRollbackTestCase.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.commitrollback;
+
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+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.integration.transaction.engine.constants.TransactionTestConstants;
+import org.junit.Assert;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * Integration test of multiple operations in one transaction.
+ */
+@Slf4j
+@TransactionTestCase
+public final class MultiOperationsCommitAndRollbackTestCase extends 
BaseTransactionTestCase {
+    
+    public MultiOperationsCommitAndRollbackTestCase(final 
BaseTransactionITCase baseTransactionITCase, final DataSource dataSource) {
+        super(baseTransactionITCase, dataSource);
+    }
+    
+    @Override
+    @SneakyThrows
+    public void executeTest() {
+        assertRollback();
+        assertCommit();
+    }
+    
+    private void assertRollback() throws SQLException {
+        Connection conn = getDataSource().getConnection();
+        conn.setAutoCommit(false);
+        assertTableRowCount(conn, TransactionTestConstants.ACCOUNT, 0);
+        executeWithLog(conn, "insert into account(id, balance, transaction_id) 
values(1, 1, 1);");
+        executeWithLog(conn, "insert into account(id, balance, transaction_id) 
values(2, 2, 2);");
+        executeUpdateWithLog(conn, "update account set balance=3 and 
transaction_id=3 where id=2;");
+        conn.rollback();
+        assertTableRowCount(conn, TransactionTestConstants.ACCOUNT, 0);

Review Comment:
   It may be better to call `assertQueryAccount` before calling `rollback`.



##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/alterresource/AddResourceTestCase.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.alterresource;
+
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+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.integration.transaction.engine.constants.TransactionTestConstants;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Integration test of add resource.
+ */
+@Slf4j
+@TransactionTestCase(adapters = TransactionTestConstants.PROXY)
+public final class AddResourceTestCase extends BaseTransactionTestCase {
+    
+    public AddResourceTestCase(final BaseTransactionITCase 
baseTransactionITCase, final DataSource dataSource) {
+        super(baseTransactionITCase, dataSource);
+    }
+    
+    @Override
+    @SneakyThrows
+    public void executeTest() {
+        assertAddResource();
+    }
+    
+    private void assertAddResource() throws SQLException {
+        Connection conn = getDataSource().getConnection();
+        getBaseTransactionITCase().addNewResource(conn);
+        getBaseTransactionITCase().createThreeDataSourceAccountTableRule(conn);
+        reCreateAccountTable(conn);
+        assertRollback();
+        assertCommit();
+        conn.close();
+    }
+    
+    private void reCreateAccountTable(final Connection conn) throws 
SQLException {
+        getBaseTransactionITCase().dropAccountTable(conn);
+        getBaseTransactionITCase().createAccountTable(conn);
+    }
+    
+    private void assertRollback() throws SQLException {
+        Connection conn = getDataSource().getConnection();
+        conn.setAutoCommit(false);
+        assertTableRowCount(conn, TransactionTestConstants.ACCOUNT, 0);
+        executeWithLog(conn, "insert into account(id, BALANCE, TRANSACTION_ID) 
values(1, 1, 1),(2, 2, 2),(3, 3, 3),(4, 4, 4),(5, 5, 5),(6, 6, 6);");
+        conn.rollback();
+        assertTableRowCount(conn, TransactionTestConstants.ACCOUNT, 0);

Review Comment:
   
   It may be better to call `TransactionTestConstants.ACCOUNT, 6)` before 
calling rollback.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to