LuciferYang commented on code in PR #37471:
URL: https://github.com/apache/spark/pull/37471#discussion_r943066491
##########
common/kvstore/src/test/java/org/apache/spark/util/kvstore/RocksDBSuite.java:
##########
@@ -303,6 +303,84 @@ public void testCloseRocksDBIterator() throws Exception {
assertTrue(!dbPathForCloseTest.exists());
}
+ @Test
+ public void testHasNextAfterIteratorClose() throws Exception {
+ db.write(createCustomType1(0));
+ KVStoreIterator<CustomType1> iter =
+ db.view(CustomType1.class).closeableIterator();
+ // iter should be true
+ assertTrue(iter.hasNext());
+ // close iter
+ iter.close();
+ // iter.hasNext should be false after iter close
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ public void testHasNextAfterDBClose() throws Exception {
+ db.write(createCustomType1(0));
+ KVStoreIterator<CustomType1> iter =
+ db.view(CustomType1.class).closeableIterator();
+ // iter should be true
+ assertTrue(iter.hasNext());
+ // close db
+ db.close();
+ // iter.hasNext should be false after db close
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ public void testNextAfterIteratorClose() throws Exception {
+ db.write(createCustomType1(0));
+ KVStoreIterator<CustomType1> iter =
+ db.view(CustomType1.class).closeableIterator();
+ // iter should be true
+ assertTrue(iter.hasNext());
+ // close iter
+ iter.close();
+ // iter.next should throw NoSuchElementException after iter close
+ assertThrows(NoSuchElementException.class, iter::next);
+ }
+
+ @Test
+ public void testNextAfterDBClose() throws Exception {
+ db.write(createCustomType1(0));
+ KVStoreIterator<CustomType1> iter =
+ db.view(CustomType1.class).closeableIterator();
+ // iter should be true
+ assertTrue(iter.hasNext());
+ // close db
+ iter.close();
+ // iter.next should throw NoSuchElementException after db close
+ assertThrows(NoSuchElementException.class, iter::next);
+ }
+
+ @Test
+ public void testSkipAfterIteratorClose() throws Exception {
+ db.write(createCustomType1(0));
+ KVStoreIterator<CustomType1> iter =
+ db.view(CustomType1.class).closeableIterator();
+ // close iter
+ iter.close();
+ // skip should always return false after iter close
+ assertFalse(iter.skip(0));
+ assertFalse(iter.skip(1));
Review Comment:
`AbstractRocksIterator.isValid` assert failed before this pr
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]