You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/03 06:43:36 UTC

[GitHub] [shardingsphere] FlyingZC opened a new pull request, #21924: Add cursor transaction test case

FlyingZC opened a new pull request, #21924:
URL: https://github.com/apache/shardingsphere/pull/21924

   Changes proposed in this pull request:
     - Add cursor transaction test case
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [x] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `mvn clean install -B -T2C -DskipTests -Dmaven.javadoc.skip=true -e`.
   - [x] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] FlyingZC commented on a diff in pull request #21924: Add cursor transaction test case

Posted by GitBox <gi...@apache.org>.
FlyingZC commented on code in PR #21924:
URL: https://github.com/apache/shardingsphere/pull/21924#discussion_r1012591540


##########
test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/cursor/OpenGaussCursorTestCase.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.cursor;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.integration.transaction.cases.base.BaseTransactionTestCase;
+import org.apache.shardingsphere.integration.transaction.engine.base.BaseITCase;
+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.command.CursorSQLCommand;
+import org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
+import org.apache.shardingsphere.test.integration.env.container.atomic.constants.AdapterContainerConstants;
+import org.junit.Assert;
+
+import javax.sql.DataSource;
+import javax.xml.bind.JAXB;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Objects;
+
+import static org.junit.Assert.fail;
+
+/**
+ * OpenGauss cursor transaction integration test.
+ */
+@TransactionTestCase(dbTypes = {TransactionTestConstants.OPENGAUSS}, adapters = {AdapterContainerConstants.PROXY}, scenario = "cursor")
+@Slf4j
+public final class OpenGaussCursorTestCase extends BaseTransactionTestCase {
+    
+    private final CursorSQLCommand cursorSQLCommand;
+    
+    public OpenGaussCursorTestCase(final BaseTransactionITCase baseTransactionITCase, final DataSource dataSource) {
+        super(baseTransactionITCase, dataSource);
+        this.cursorSQLCommand = loadCursorSQLCommand();
+    }
+    
+    private CursorSQLCommand loadCursorSQLCommand() {
+        return JAXB.unmarshal(Objects.requireNonNull(BaseITCase.class.getClassLoader().getResource("env/common/cursor-command.xml")), CursorSQLCommand.class);
+    }
+    
+    @Override
+    protected void beforeTest() throws SQLException {
+        super.beforeTest();
+        Connection conn = getDataSource().getConnection();
+        executeWithLog(conn, "CREATE OR REPLACE VIEW t_order_view AS SELECT * FROM t_order;");
+    }
+    
+    @Override
+    public void executeTest() throws SQLException {
+        Connection conn = getDataSource().getConnection();
+        broadcastTableCursorTest(conn);
+        broadcastTableCursorTest2(conn);
+        broadcastAndSingleTablesCursorTest(conn);
+        broadcastAndSingleTablesCursorTest2(conn);
+        viewCursorTest(conn);
+    }
+    
+    private void broadcastTableCursorTest(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor());
+        fetch(conn, 10101);
+        fetch(conn, 10102);
+        fetch(conn, 10201);
+        fetch(conn, 10202);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void broadcastTableCursorTest2(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor2());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor2());
+        fetch(conn, 10101);
+        fetch(conn, 10102);
+        fetch(conn, 10201);
+        fetch(conn, 10202);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void broadcastAndSingleTablesCursorTest(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastAndSingleTablesCursor());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastAndSingleTablesCursor());
+        fetch(conn, 1);
+        fetch(conn, 2);
+        fetch(conn, 3);
+        fetch(conn, 4);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void broadcastAndSingleTablesCursorTest2(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor2());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor2());
+        fetch(conn, 10101);
+        fetch(conn, 10102);
+        fetch(conn, 10201);
+        fetch(conn, 10202);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void viewCursorTest(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getViewCursor());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getViewCursor());
+        fetch(conn, 1);
+        fetch(conn, 2);
+        fetch(conn, 3);
+        fetch(conn, 4);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void fetch(final Connection conn, final int expectedId) throws SQLException {
+        ResultSet rs = executeQueryWithLog(conn, "fetch test;");
+        while (rs.next()) {
+            int id = rs.getInt("id");
+            Assert.assertEquals(String.format("Expected fetch id is %s, actual is %s.", expectedId, id), expectedId, id);

Review Comment:
   OK,I will correct it.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #21924: Add cursor transaction test case

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on code in PR #21924:
URL: https://github.com/apache/shardingsphere/pull/21924#discussion_r1012590538


##########
test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/cursor/OpenGaussCursorTestCase.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.cursor;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.integration.transaction.cases.base.BaseTransactionTestCase;
+import org.apache.shardingsphere.integration.transaction.engine.base.BaseITCase;
+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.command.CursorSQLCommand;
+import org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
+import org.apache.shardingsphere.test.integration.env.container.atomic.constants.AdapterContainerConstants;
+import org.junit.Assert;
+
+import javax.sql.DataSource;
+import javax.xml.bind.JAXB;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Objects;
+
+import static org.junit.Assert.fail;
+
+/**
+ * OpenGauss cursor transaction integration test.
+ */
+@TransactionTestCase(dbTypes = {TransactionTestConstants.OPENGAUSS}, adapters = {AdapterContainerConstants.PROXY}, scenario = "cursor")
+@Slf4j
+public final class OpenGaussCursorTestCase extends BaseTransactionTestCase {
+    
+    private final CursorSQLCommand cursorSQLCommand;
+    
+    public OpenGaussCursorTestCase(final BaseTransactionITCase baseTransactionITCase, final DataSource dataSource) {
+        super(baseTransactionITCase, dataSource);
+        this.cursorSQLCommand = loadCursorSQLCommand();
+    }
+    
+    private CursorSQLCommand loadCursorSQLCommand() {
+        return JAXB.unmarshal(Objects.requireNonNull(BaseITCase.class.getClassLoader().getResource("env/common/cursor-command.xml")), CursorSQLCommand.class);
+    }
+    
+    @Override
+    protected void beforeTest() throws SQLException {
+        super.beforeTest();
+        Connection conn = getDataSource().getConnection();
+        executeWithLog(conn, "CREATE OR REPLACE VIEW t_order_view AS SELECT * FROM t_order;");
+    }
+    
+    @Override
+    public void executeTest() throws SQLException {
+        Connection conn = getDataSource().getConnection();
+        broadcastTableCursorTest(conn);
+        broadcastTableCursorTest2(conn);
+        broadcastAndSingleTablesCursorTest(conn);
+        broadcastAndSingleTablesCursorTest2(conn);
+        viewCursorTest(conn);
+    }
+    
+    private void broadcastTableCursorTest(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor());
+        fetch(conn, 10101);
+        fetch(conn, 10102);
+        fetch(conn, 10201);
+        fetch(conn, 10202);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void broadcastTableCursorTest2(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor2());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor2());
+        fetch(conn, 10101);
+        fetch(conn, 10102);
+        fetch(conn, 10201);
+        fetch(conn, 10202);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void broadcastAndSingleTablesCursorTest(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastAndSingleTablesCursor());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastAndSingleTablesCursor());
+        fetch(conn, 1);
+        fetch(conn, 2);
+        fetch(conn, 3);
+        fetch(conn, 4);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void broadcastAndSingleTablesCursorTest2(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor2());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getBroadcastTablesCursor2());
+        fetch(conn, 10101);
+        fetch(conn, 10102);
+        fetch(conn, 10201);
+        fetch(conn, 10202);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void viewCursorTest(final Connection conn) throws SQLException {
+        executeWithLog(conn, "start transaction;");
+        executeWithLog(conn, cursorSQLCommand.getViewCursor());
+        executeWithLog(conn, "close test;");
+        executeWithLog(conn, cursorSQLCommand.getViewCursor());
+        fetch(conn, 1);
+        fetch(conn, 2);
+        fetch(conn, 3);
+        fetch(conn, 4);
+        fetchOver(conn);
+        fetchOver(conn);
+        executeWithLog(conn, "rollback;");
+    }
+    
+    private void fetch(final Connection conn, final int expectedId) throws SQLException {
+        ResultSet rs = executeQueryWithLog(conn, "fetch test;");
+        while (rs.next()) {
+            int id = rs.getInt("id");
+            Assert.assertEquals(String.format("Expected fetch id is %s, actual is %s.", expectedId, id), expectedId, id);

Review Comment:
   Please use assertThat instead of assertEquals.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] strongduanmu merged pull request #21924: Add cursor transaction test case

Posted by GitBox <gi...@apache.org>.
strongduanmu merged PR #21924:
URL: https://github.com/apache/shardingsphere/pull/21924


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org