[RocksJava] Fix cleanup in tests

main
fyrz 10 years ago
parent a01b592597
commit f862b38124
  1. 3
      java/src/test/java/org/rocksdb/AbstractComparatorTest.java
  2. 13
      java/src/test/java/org/rocksdb/ColumnFamilyTest.java
  3. 7
      java/src/test/java/org/rocksdb/RocksDBTest.java
  4. 32
      java/src/test/java/org/rocksdb/RocksIteratorTest.java

@ -78,6 +78,7 @@ public abstract class AbstractComparatorTest {
lastKey = thisKey; lastKey = thisKey;
count++; count++;
} }
it.dispose();
db.close(); db.close();
assertThat(count).isEqualTo(ITERATIONS); assertThat(count).isEqualTo(ITERATIONS);
@ -162,6 +163,8 @@ public abstract class AbstractComparatorTest {
lastKey = thisKey; lastKey = thisKey;
count++; count++;
} }
it.dispose();
for (ColumnFamilyHandle handle : cfHandles) { for (ColumnFamilyHandle handle : cfHandles) {
handle.dispose(); handle.dispose();
} }

@ -56,7 +56,7 @@ public class ColumnFamilyTest {
public void defaultColumnFamily() throws RocksDBException { public void defaultColumnFamily() throws RocksDBException {
RocksDB db = null; RocksDB db = null;
Options options = null; Options options = null;
ColumnFamilyHandle cfh = null; ColumnFamilyHandle cfh;
try { try {
options = new Options().setCreateIfMissing(true); options = new Options().setCreateIfMissing(true);
@ -95,7 +95,7 @@ public class ColumnFamilyTest {
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
columnFamilyHandle = db.createColumnFamily( columnFamilyHandle = db.createColumnFamily(
new ColumnFamilyDescriptor("new_cf".getBytes(), new ColumnFamilyOptions())); new ColumnFamilyDescriptor("new_cf".getBytes(), new ColumnFamilyOptions()));
db.close();
List<byte[]> columnFamilyNames; List<byte[]> columnFamilyNames;
columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath()); columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath());
assertThat(columnFamilyNames).isNotNull(); assertThat(columnFamilyNames).isNotNull();
@ -464,6 +464,7 @@ public class ColumnFamilyTest {
new ArrayList<>(); new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList = List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>(); new ArrayList<>();
List<RocksIterator> iterators = null;
try { try {
options = new DBOptions(); options = new DBOptions();
options.setCreateIfMissing(true); options.setCreateIfMissing(true);
@ -474,8 +475,7 @@ public class ColumnFamilyTest {
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(), db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList); cfNames, columnFamilyHandleList);
List<RocksIterator> iterators = iterators = db.newIterators(columnFamilyHandleList);
db.newIterators(columnFamilyHandleList);
assertThat(iterators.size()).isEqualTo(2); assertThat(iterators.size()).isEqualTo(2);
RocksIterator iter = iterators.get(0); RocksIterator iter = iterators.get(0);
iter.seekToFirst(); iter.seekToFirst();
@ -499,6 +499,11 @@ public class ColumnFamilyTest {
iter.next(); iter.next();
} }
} finally { } finally {
if (iterators != null) {
for (RocksIterator rocksIterator : iterators) {
rocksIterator.dispose();
}
}
for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) {
columnFamilyHandle.dispose(); columnFamilyHandle.dispose();
} }

@ -473,7 +473,7 @@ public class RocksDBTest {
db.put((String.valueOf(i)).getBytes(), b); db.put((String.valueOf(i)).getBytes(), b);
} }
db.compactRange("0".getBytes(), "201".getBytes(), db.compactRange("0".getBytes(), "201".getBytes(),
true, 0, 0); true, 0, -1);
} finally { } finally {
if (db != null) { if (db != null) {
db.close(); db.close();
@ -580,7 +580,7 @@ public class RocksDBTest {
String.valueOf(i).getBytes(), b); String.valueOf(i).getBytes(), b);
} }
db.compactRange(columnFamilyHandles.get(1), "0".getBytes(), db.compactRange(columnFamilyHandles.get(1), "0".getBytes(),
"201".getBytes(), true, 0, 0); "201".getBytes(), true, 0, -1);
} finally { } finally {
for (ColumnFamilyHandle handle : columnFamilyHandles) { for (ColumnFamilyHandle handle : columnFamilyHandles) {
handle.dispose(); handle.dispose();
@ -729,6 +729,9 @@ public class RocksDBTest {
} }
} }
} finally { } finally {
for (ColumnFamilyHandle handle : columnFamilyHandles) {
handle.dispose();
}
if (db != null) { if (db != null) {
db.close(); db.close();
} }

@ -58,41 +58,9 @@ public class RocksIteratorTest {
assertThat(iterator.value()).isEqualTo("value2".getBytes()); assertThat(iterator.value()).isEqualTo("value2".getBytes());
iterator.status(); iterator.status();
} finally { } finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
if (iterator != null) { if (iterator != null) {
iterator.dispose(); iterator.dispose();
} }
}
}
@Test
public void rocksIteratorGc()
throws RocksDBException {
RocksDB db = null;
Options options = null;
try {
options = new Options();
options.setCreateIfMissing(true)
.setCreateMissingColumnFamilies(true);
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.put("key".getBytes(), "value".getBytes());
db.newIterator();
db.newIterator();
RocksIterator iter3 = db.newIterator();
db.close();
db = null;
System.gc();
System.runFinalization();
iter3.dispose();
System.gc();
System.runFinalization();
} finally {
if (db != null) { if (db != null) {
db.close(); db.close();
} }

Loading…
Cancel
Save