oleg-vlsk commented on code in PR #12087:
URL: https://github.com/apache/ignite/pull/12087#discussion_r2153561959


##########
modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/LongRunningQueryTest.java:
##########
@@ -392,6 +415,102 @@ public void testBigResultDistributed() throws Exception {
         checkBigResultSet();
     }
 
+    /**
+     * Verifies that while a query is not fully fetched, its {@link 
H2QueryInfo} is kept in {@link HeavyQueriesTracker}
+     * on all cluster nodes and its {@link H2QueryInfo#isSuspended()} returns 
{@code true}. Then, once the query is fully
+     * fetched, its {@link H2QueryInfo} is removed from {@link 
HeavyQueriesTracker}.
+     */
+    @Test
+    @MultiNodeTest
+    public void testEmptyHeavyQueriesTrackerWithFullyFetchedIterator() {
+        Iterator<?> it = queryCursor(false).iterator();
+
+        checkQryInfoCount(gridCount());
+
+        H2QueryInfo qry = 
(H2QueryInfo)heavyQueriesTracker().getQueries().iterator().next();
+
+        assertTrue(qry.isSuspended());
+
+        it.forEachRemaining(x -> {});
+    }
+
+    /**
+     * Verifies that when the cursor of a not fully fetched query is closed, 
its {@link H2QueryInfo} is removed from
+     * {@link HeavyQueriesTracker} on all cluster nodes.
+     */
+    @Test
+    @MultiNodeTest
+    public void testEmptyHeavyQueriesTrackerWithClosedCursor() {
+        FieldsQueryCursor<List<?>> cursor = queryCursor(false);
+
+        cursor.iterator().next();
+
+        checkQryInfoCount(gridCount());
+
+        H2QueryInfo qryInfo = 
(H2QueryInfo)heavyQueriesTracker().getQueries().iterator().next();
+
+        assertTrue(qryInfo.isSuspended());
+
+        cursor.close();
+    }
+
+    /**
+     * Verifies that when a not fully fetched query is cancelled, its {@link 
H2QueryInfo} is removed from
+     * {@link HeavyQueriesTracker} on all cluster nodes.
+     */
+    @Test
+    @MultiNodeTest
+    public void testEmptyHeavyQueriesTrackerWithCancelledQuery() {
+        cancelQuery(runNotFullyFetchedQuery(false));
+    }
+
+    /**
+     * Verifies that when a local not fully fetched query is cancelled, its 
{@link H2QueryInfo} is removed from
+     * {@link HeavyQueriesTracker} on all cluster nodes.
+     */
+    @Test
+    @MultiNodeTest
+    public void testEmptyHeavyQueriesTrackerWithCancelledLocalQuery() {
+        long qryId = runNotFullyFetchedQuery(true);
+
+        ((IgniteEx)ignite).context().query().cancelLocalQueries(Set.of(qryId));
+    }
+
+    /**
+     * Verifies that when there are multiple not fully fetched queries, and 
they are cancelled separately, corresponding
+     * {@link H2QueryInfo} instances are removed from {@link 
HeavyQueriesTracker} on all cluster nodes.
+     * */
+    @Test
+    @MultiNodeTest
+    public void testEmptyHeavyQueriesTrackerWithMultipleCancelledQueries() {
+        int qryCnt = 4;
+        int cnldQryCnt = 2;
+
+        for (int i = 0; i < qryCnt; i++)
+            runNotFullyFetchedQuery(false);
+
+        for (int i = 0; i < gridCount(); ++i)
+            assertEquals(qryCnt, heavyQueriesTracker(i).getQueries().size());
+
+        for (int i = 0; i < cnldQryCnt; i++)
+            cancelQuery(i + 1);
+
+        for (int i = 0; i < gridCount(); ++i) {
+            Set<TrackableQuery> qrys = heavyQueriesTracker(i).getQueries();
+
+            assertEquals(cnldQryCnt, qrys.size());
+
+            assertFalse(qrys.stream().anyMatch(qryInfo -> {
+                long id = ((H2QueryInfo)qryInfo).queryId();
+
+                return IntStream.range(0, cnldQryCnt).anyMatch(x -> x == id);

Review Comment:
   Test refactored.



-- 
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