korlov42 commented on code in PR #4814:
URL: https://github.com/apache/ignite-3/pull/4814#discussion_r1870782232


##########
modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcStatementCancelSelfTest.java:
##########
@@ -17,140 +17,221 @@
 
 package org.apache.ignite.jdbc;
 
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static 
org.apache.ignite.jdbc.util.JdbcTestUtils.assertThrowsSqlException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
-import org.apache.ignite.jdbc.util.JdbcTestUtils;
-import org.junit.jupiter.api.Disabled;
+import java.util.concurrent.CompletableFuture;
+import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 
 /**
  * Statement cancel test.
  */
-@Disabled("https://issues.apache.org/jira/browse/IGNITE-16205";)
-public class ItJdbcStatementCancelSelfTest extends 
ItJdbcAbstractStatementSelfTest {
-    /**
-     * Trying to cancel stament without query. In given case cancel is noop, 
so no exception expected.
-     */
-    @Test
-    public void testCancelingStmtWithoutQuery() {
-        try {
-            stmt.cancel();
-        } catch (Exception e) {
-            log.error("Unexpected exception.", e);
-
-            fail("Unexpected exception");
+@SuppressWarnings({"ThrowableNotThrown", 
"JDBCResourceOpenedButNotSafelyClosed"})
+public class ItJdbcStatementCancelSelfTest extends AbstractJdbcSelfTest {
+    @AfterEach
+    void reset() throws SQLException {
+        if (!stmt.isClosed()) {
+            stmt.setFetchSize(1024);
         }
+
+        dropAllTables();
     }
 
-    /**
-     * Trying to retrieve result set of a canceled query.
-     * SQLException with message "The query was cancelled while executing." 
expected.
-     *
-     * @throws Exception If failed.
-     */
     @Test
-    public void testResultSetRetrievalInCanceledStatement() throws Exception {
-        stmt.execute("SELECT 1; SELECT 2; SELECT 3;");
+    void cancelIsNoopWhenThereIsNoRunningQuery() throws SQLException {
+        stmt.cancel();
+    }
 
-        assertNotNull(stmt.getResultSet());
+    @Test
+    void cancellationOfLongRunningQuery() throws Exception {
+        CompletableFuture<?> result = runAsync(() ->
+                stmt.executeQuery("SELECT count(*) FROM system_range(0, 
10000000000)")
+        );
+
+        assertTrue(
+                waitForCondition(() -> sql("SELECT * FROM 
system.sql_queries").size() == 2, 5_000),
+                "Query didn't appear in running queries view or disappeared 
too fast"
+        );
 
         stmt.cancel();
 
-        JdbcTestUtils.assertThrowsSqlException("The query was cancelled while 
executing.", stmt::getResultSet);
+        // second cancellation should not throw any error
+        stmt.cancel();
+
+        assertThrowsSqlException(
+                "The query was cancelled while executing.",

Review Comment:
   replaced all such literals with suggested constant, thanks 



-- 
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-unsubscr...@ignite.apache.org

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

Reply via email to