LuciferYang commented on code in PR #43502:
URL: https://github.com/apache/spark/pull/43502#discussion_r1371254821
##########
common/kvstore/src/test/java/org/apache/spark/util/kvstore/RocksDBSuite.java:
##########
@@ -381,6 +382,40 @@ public void testSkipAfterDBClose() throws Exception {
assertFalse(iter.skip(1));
}
+ @Test
+ public void testResourceCleaner() throws Exception {
+ File dbPathForCleanerTest = File.createTempFile(
+ "test_db_cleaner.", ".rdb");
+ dbPathForCleanerTest.delete();
+
+ RocksDB dbForCleanerTest = new RocksDB(dbPathForCleanerTest);
+ for (int i = 0; i < 8192; i++) {
+ dbForCleanerTest.write(createCustomType1(i));
+ }
+
+ RocksDBIterator<CustomType1> rocksDBIterator =
(RocksDBIterator<CustomType1>)
dbForCleanerTest.view(CustomType1.class).iterator();
+ Reference<RocksDBIterator<?>> reference =
dbForCleanerTest.getRocksDBIteratorRef(rocksDBIterator);
+ assertNotNull(reference);
+ RocksIterator it = rocksDBIterator.internalIterator();
+ // it has not been closed yet, isOwningHandle should be true.
+ assertTrue(it.isOwningHandle());
+ // Manually set rocksDBIterator to null, to be GC.
+ rocksDBIterator = null;
+ // 100 times gc, the rocksDBIterator should be GCed.
+ int count = 0;
+ while (count < 100 && !reference.refersTo(null)) {
+ System.gc();
+ count++;
+ Thread.sleep(100);
+ }
+ // check rocksDBIterator should be GCed
+ assertTrue(reference.refersTo(null));
+ // Verify that the Cleaner will be executed after a period of time, and
it.isOwningHandle() will become false.
+ assertTimeout(java.time.Duration.ofSeconds(5), () ->
assertFalse(it.isOwningHandle()));
+
+ dbForCleanerTest.close();
Review Comment:
OK, it's fine as long as we can ensure there are no residues after testing.
--
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]