tkalkirill commented on code in PR #1424:
URL: https://github.com/apache/ignite-3/pull/1424#discussion_r1046717549


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractSortedIndexStorageTest.java:
##########
@@ -1233,6 +1235,276 @@ void testScanContractRemoveNextAndAddFirstRow() {
         assertThrows(NoSuchElementException.class, scan::next);
     }
 
+
+    @Test
+    void testScanPeekForFinishedCursor() {
+        SortedIndexDefinition indexDefinition = 
SchemaBuilders.sortedIndex("TEST_IDX")
+                
.addIndexColumn(ColumnType.INT32.typeSpec().name()).asc().done()
+                .build();
+
+        SortedIndexStorage indexStorage = createIndexStorage(indexDefinition);
+
+        BinaryTupleRowSerializer serializer = new 
BinaryTupleRowSerializer(indexStorage.indexDescriptor());
+
+        PeekCursor<IndexRow> scan0 = indexStorage.scan(null, null, 0);
+        PeekCursor<IndexRow> scan1 = indexStorage.scan(null, null, 0);
+
+        // index   =
+        // cursor0 = ^ already finished
+        assertFalse(scan0.hasNext());
+        assertNull(scan0.peek());
+
+        // index   =
+        // cursor1 = ^ already finished
+        assertThrows(NoSuchElementException.class, scan1::next);
+        assertNull(scan1.peek());
+
+        // index   =  [0]
+        // cursor0 = ^ already finished
+        // cursor1 = ^ already finished
+        put(indexStorage, serializer.serializeRow(new Object[]{0}, new 
RowId(TEST_PARTITION)));
+
+        assertNull(scan0.peek());

Review Comment:
   I think that the basic iterator/cursor usage pattern is:
   `
   while(cursor.hasNext()){
       handle(cursor.next());
   }
   `
   If `hasNext()` returns `false`, then we exit the loop assuming that we have 
finished processing the range. 
   Therefore, it seems that further calls to `hasNext()`, `next()` and `peek()` 
should in my opinion be interpreted as nothing more to return.



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