lowka commented on code in PR #2437:
URL: https://github.com/apache/ignite-3/pull/2437#discussion_r1291380724


##########
modules/client-handler/src/test/java/org/apache/ignite/client/handler/requests/jdbc/JdbcQueryCursorSelfTest.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.ignite.client.handler.requests.jdbc;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.sql.engine.AsyncCursor.BatchedResult;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursorImpl;
+import org.apache.ignite.internal.sql.engine.SqlQueryType;
+import org.apache.ignite.internal.sql.engine.exec.AsyncWrapper;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Tests for for {@link JdbcQueryCursor}.
+ */
+public class JdbcQueryCursorSelfTest {
+    private static final int TOTAL_ROWS_COUNT = 3;
+
+    /** Basic test to check corner cases of setting the {@code maxRows} 
parameter. */
+    @ParameterizedTest(name = "maxRows={0}, fetchSize={1}")
+    @MethodSource("maxRowsTestParameters")
+    public void testMaxRows(int maxRows, int fetchSize) {
+        List<Integer> rows = IntStream.range(0, 
TOTAL_ROWS_COUNT).boxed().collect(Collectors.toList());
+
+        JdbcQueryCursor<Integer> cursor = new JdbcQueryCursor<>(maxRows,
+                new AsyncSqlCursorImpl<>(SqlQueryType.QUERY, null, null,
+                        new 
AsyncWrapper<>(CompletableFuture.completedFuture(rows.iterator()), 
Runnable::run)));
+
+
+        List<Integer> results = new ArrayList<>(maxRows);
+        BatchedResult<Integer> requestResult;
+
+        do {
+            requestResult = cursor.requestNextAsync(fetchSize).join();
+
+            results.addAll(requestResult.items());
+        } while (requestResult.hasMore());
+
+        if (maxRows == 0 || maxRows >= TOTAL_ROWS_COUNT) {
+            assertEquals(rows, results);
+        } else {
+            assertEquals(rows.subList(0, maxRows), results);

Review Comment:
   I think It would be better to split if this test case were split into two - 
one for maxRows = 0 and another for maxRows != 0 by extracting a driver method 
that accepts (rows for iteration + max rows and returns a `BatchedResult` ) and 
does all the necessary setup + loops over  `requestResult`. Because right know 
this test case is almost identical to implementation.
   
   



##########
modules/client-handler/src/test/java/org/apache/ignite/client/handler/requests/jdbc/JdbcQueryCursorSelfTest.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.ignite.client.handler.requests.jdbc;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.sql.engine.AsyncCursor.BatchedResult;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursorImpl;
+import org.apache.ignite.internal.sql.engine.SqlQueryType;
+import org.apache.ignite.internal.sql.engine.exec.AsyncWrapper;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Tests for for {@link JdbcQueryCursor}.
+ */
+public class JdbcQueryCursorSelfTest {
+    private static final int TOTAL_ROWS_COUNT = 3;
+
+    /** Basic test to check corner cases of setting the {@code maxRows} 
parameter. */
+    @ParameterizedTest(name = "maxRows={0}, fetchSize={1}")
+    @MethodSource("maxRowsTestParameters")
+    public void testMaxRows(int maxRows, int fetchSize) {
+        List<Integer> rows = IntStream.range(0, 
TOTAL_ROWS_COUNT).boxed().collect(Collectors.toList());
+
+        JdbcQueryCursor<Integer> cursor = new JdbcQueryCursor<>(maxRows,
+                new AsyncSqlCursorImpl<>(SqlQueryType.QUERY, null, null,
+                        new 
AsyncWrapper<>(CompletableFuture.completedFuture(rows.iterator()), 
Runnable::run)));
+
+
+        List<Integer> results = new ArrayList<>(maxRows);
+        BatchedResult<Integer> requestResult;
+
+        do {
+            requestResult = cursor.requestNextAsync(fetchSize).join();
+
+            results.addAll(requestResult.items());
+        } while (requestResult.hasMore());
+
+        if (maxRows == 0 || maxRows >= TOTAL_ROWS_COUNT) {
+            assertEquals(rows, results);
+        } else {
+            assertEquals(rows.subList(0, maxRows), results);
+        }
+    }
+
+    private static List<Arguments> maxRowsTestParameters() {
+        int[] fetchSizes = {1024, 1, 0, -1};

Review Comment:
   Negative number of `rows` parameter looks like something that should not be 
allowed. As we have a counter that limits the number of returned records, it 
seem that we should to allow negative values for `rows` otherwise maxRows makes 
a little sense: 
   initially: maxRows = 10, fetched = 0
   
   0: fetch(8): fetched= 8
   1: fetch(-5): fetched=3 
   
   Or I am missing something here?



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