diff --git a/java/src/test/java/org/rocksdb/ColumnFamilyTest.java b/java/src/test/java/org/rocksdb/ColumnFamilyTest.java index 1357b9ef707a63b5ac06b5322c2d4a376cbea93d..f6d5b9f9d672c4df5551f035f8d098c10a00cb42 100644 --- a/java/src/test/java/org/rocksdb/ColumnFamilyTest.java +++ b/java/src/test/java/org/rocksdb/ColumnFamilyTest.java @@ -56,6 +56,7 @@ public class ColumnFamilyTest { public void defaultColumnFamily() throws RocksDBException { RocksDB db = null; Options options = null; + ColumnFamilyHandle cfh = null; try { options = new Options(); options.setCreateIfMissing(true); @@ -64,7 +65,7 @@ public class ColumnFamilyTest { dbOptions.setCreateIfMissing(true); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); - ColumnFamilyHandle cfh = db.getDefaultColumnFamily(); + cfh = db.getDefaultColumnFamily(); assertThat(cfh).isNotNull(); final byte[] key = "key".getBytes(); @@ -77,6 +78,9 @@ public class ColumnFamilyTest { assertThat(cfh).isNotNull(); assertThat(actualValue).isEqualTo(value); } finally { + if (cfh != null) { + cfh.dispose(); + } if (db != null) { db.close(); } @@ -90,16 +94,14 @@ public class ColumnFamilyTest { public void createColumnFamily() throws RocksDBException { RocksDB db = null; Options options = null; + ColumnFamilyHandle columnFamilyHandle = null; try { options = new Options(); options.setCreateIfMissing(true); - DBOptions dbOptions = new DBOptions(); - dbOptions.setCreateIfMissing(true); - db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); - db.createColumnFamily(new ColumnFamilyDescriptor("new_cf".getBytes(), - new ColumnFamilyOptions())); + columnFamilyHandle = db.createColumnFamily( + new ColumnFamilyDescriptor("new_cf".getBytes(), new ColumnFamilyOptions())); db.close(); List columnFamilyNames; columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath()); @@ -109,6 +111,9 @@ public class ColumnFamilyTest { assertThat(new String(columnFamilyNames.get(0))).isEqualTo("default"); assertThat(new String(columnFamilyNames.get(1))).isEqualTo("new_cf"); } finally { + if (columnFamilyHandle != null) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -122,15 +127,15 @@ public class ColumnFamilyTest { public void openWithColumnFamilies() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); options.setCreateMissingColumnFamilies(true); // Test open database with column family names - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -156,6 +161,9 @@ public class ColumnFamilyTest { assertThat(db.get(columnFamilyHandleList.get(0), new ReadOptions(), "dfkey2".getBytes())).isNull(); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -169,15 +177,15 @@ public class ColumnFamilyTest { public void getWithOutValueAndCf() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfDescriptors = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); options.setCreateMissingColumnFamilies(true); // Test open database with column family names - List cfDescriptors = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(), cfDescriptors, columnFamilyHandleList); @@ -198,6 +206,9 @@ public class ColumnFamilyTest { assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND); assertThat(outValue).isEqualTo("12345".getBytes()); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -212,14 +223,14 @@ public class ColumnFamilyTest { RocksDB db = null; DBOptions opt = null; ColumnFamilyHandle tmpColumnFamilyHandle = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { opt = new DBOptions(); opt.setCreateIfMissing(true); opt.setCreateMissingColumnFamilies(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -231,6 +242,9 @@ public class ColumnFamilyTest { db.dropColumnFamily(tmpColumnFamilyHandle); tmpColumnFamilyHandle.dispose(); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (tmpColumnFamilyHandle != null) { tmpColumnFamilyHandle.dispose(); } @@ -247,14 +261,15 @@ public class ColumnFamilyTest { public void writeBatch() throws RocksDBException { RocksDB db = null; DBOptions opt = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { opt = new DBOptions(); opt.setCreateIfMissing(true); opt.setCreateMissingColumnFamilies(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions().setMergeOperator(new StringAppendOperator()))); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -288,6 +303,9 @@ public class ColumnFamilyTest { assertThat(new String(db.get(db.getDefaultColumnFamily(), "mergeKey".getBytes()))).isEqualTo("merge,merge"); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -302,14 +320,15 @@ public class ColumnFamilyTest { RocksDB db = null; DBOptions options = null; RocksIterator rocksIterator = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); options.setCreateMissingColumnFamilies(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -338,6 +357,9 @@ public class ColumnFamilyTest { if (rocksIterator != null) { rocksIterator.dispose(); } + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -351,14 +373,15 @@ public class ColumnFamilyTest { public void multiGet() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfDescriptors = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); options.setCreateMissingColumnFamilies(true); - List cfDescriptors = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfDescriptors.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -383,6 +406,9 @@ public class ColumnFamilyTest { assertThat(new String(retValues.get(keys.get(1)))) .isEqualTo("value"); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -396,14 +422,15 @@ public class ColumnFamilyTest { public void properties() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); options.setCreateMissingColumnFamilies(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -423,6 +450,9 @@ public class ColumnFamilyTest { assertThat(db.getProperty(columnFamilyHandleList.get(1), "rocksdb.sstables")).isNotNull(); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -437,15 +467,15 @@ public class ColumnFamilyTest { public void iterators() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); options.setCreateMissingColumnFamilies(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -476,6 +506,9 @@ public class ColumnFamilyTest { iter.next(); } } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -489,13 +522,14 @@ public class ColumnFamilyTest { public void failPutDisposedCF() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -504,6 +538,9 @@ public class ColumnFamilyTest { db.dropColumnFamily(columnFamilyHandleList.get(1)); db.put(columnFamilyHandleList.get(1), "key".getBytes(), "value".getBytes()); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -517,13 +554,14 @@ public class ColumnFamilyTest { public void failRemoveDisposedCF() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -532,6 +570,9 @@ public class ColumnFamilyTest { db.dropColumnFamily(columnFamilyHandleList.get(1)); db.remove(columnFamilyHandleList.get(1), "key".getBytes()); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -545,13 +586,14 @@ public class ColumnFamilyTest { public void failGetDisposedCF() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -560,6 +602,9 @@ public class ColumnFamilyTest { db.dropColumnFamily(columnFamilyHandleList.get(1)); db.get(columnFamilyHandleList.get(1), "key".getBytes()); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -573,13 +618,14 @@ public class ColumnFamilyTest { public void failMultiGetWithoutCorrectNumberOfCF() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfNames = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true); - List cfNames = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); @@ -592,6 +638,9 @@ public class ColumnFamilyTest { db.multiGet(cfCustomList, keys); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -605,6 +654,7 @@ public class ColumnFamilyTest { public void testByteCreateFolumnFamily() throws RocksDBException { RocksDB db = null; Options options = null; + ColumnFamilyHandle cf1 = null, cf2 = null, cf3 = null; try { options = new Options().setCreateIfMissing(true); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); @@ -612,12 +662,21 @@ public class ColumnFamilyTest { byte[] b0 = new byte[] { (byte)0x00 }; byte[] b1 = new byte[] { (byte)0x01 }; byte[] b2 = new byte[] { (byte)0x02 }; - db.createColumnFamily(new ColumnFamilyDescriptor(b0)); - db.createColumnFamily(new ColumnFamilyDescriptor(b1)); + cf1 = db.createColumnFamily(new ColumnFamilyDescriptor(b0)); + cf2 = db.createColumnFamily(new ColumnFamilyDescriptor(b1)); List families = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath()); assertThat(families).contains("default".getBytes(), b0, b1); - db.createColumnFamily(new ColumnFamilyDescriptor(b2)); + cf3 = db.createColumnFamily(new ColumnFamilyDescriptor(b2)); } finally { + if (cf1 != null) { + cf1.dispose(); + } + if (cf2 != null) { + cf2.dispose(); + } + if (cf3 != null) { + cf3.dispose(); + } if (db != null) { db.close(); } @@ -631,17 +690,24 @@ public class ColumnFamilyTest { public void testCFNamesWithZeroBytes() throws RocksDBException { RocksDB db = null; Options options = null; + ColumnFamilyHandle cf1 = null, cf2 = null; try { options = new Options().setCreateIfMissing(true); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); byte[] b0 = new byte[] { 0, 0 }; byte[] b1 = new byte[] { 0, 1 }; - db.createColumnFamily(new ColumnFamilyDescriptor(b0)); - db.createColumnFamily(new ColumnFamilyDescriptor(b1)); + cf1 = db.createColumnFamily(new ColumnFamilyDescriptor(b0)); + cf2 = db.createColumnFamily(new ColumnFamilyDescriptor(b1)); List families = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath()); assertThat(families).contains("default".getBytes(), b0, b1); } finally { + if (cf1 != null) { + cf1.dispose(); + } + if (cf2 != null) { + cf2.dispose(); + } if (db != null) { db.close(); } @@ -655,15 +721,20 @@ public class ColumnFamilyTest { public void testCFNameSimplifiedChinese() throws RocksDBException { RocksDB db = null; Options options = null; + ColumnFamilyHandle columnFamilyHandle = null; try { options = new Options().setCreateIfMissing(true); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); final String simplifiedChinese = "简体字"; - db.createColumnFamily(new ColumnFamilyDescriptor(simplifiedChinese.getBytes())); + columnFamilyHandle = db.createColumnFamily( + new ColumnFamilyDescriptor(simplifiedChinese.getBytes())); List families = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath()); assertThat(families).contains("default".getBytes(), simplifiedChinese.getBytes()); } finally { + if (columnFamilyHandle != null) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } diff --git a/java/src/test/java/org/rocksdb/KeyMayExistTest.java b/java/src/test/java/org/rocksdb/KeyMayExistTest.java index f29c2f8728a9557188b7ab949c4b48c5f1a66631..b670caddcfc350c0976be81054ca1be998b4a47b 100644 --- a/java/src/test/java/org/rocksdb/KeyMayExistTest.java +++ b/java/src/test/java/org/rocksdb/KeyMayExistTest.java @@ -27,15 +27,16 @@ public class KeyMayExistTest { public void keyMayExist() throws RocksDBException { RocksDB db = null; DBOptions options = null; + List cfDescriptors = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { options = new DBOptions(); options.setCreateIfMissing(true) .setCreateMissingColumnFamilies(true); // open database using cf names - List cfDescriptors = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); + cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); cfDescriptors.add(new ColumnFamilyDescriptor("new_cf".getBytes())); db = RocksDB.open(options, @@ -80,6 +81,9 @@ public class KeyMayExistTest { assertThat(db.keyMayExist(columnFamilyHandleList.get(1), "key".getBytes(), retValue)).isFalse(); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } diff --git a/java/src/test/java/org/rocksdb/MergeTest.java b/java/src/test/java/org/rocksdb/MergeTest.java index 55e8a20cd79172c40916a8805d2f543b96c0a98f..a5f8e1fe9d70eee1ab1efcb7e991fb45179c1d96 100644 --- a/java/src/test/java/org/rocksdb/MergeTest.java +++ b/java/src/test/java/org/rocksdb/MergeTest.java @@ -143,7 +143,11 @@ public class MergeTest { throws InterruptedException, RocksDBException { RocksDB db = null; DBOptions opt = null; - ColumnFamilyHandle columnFamilyHandle = null; + ColumnFamilyHandle cfHandle = null; + List cfDescriptors = + new ArrayList<>(); + List columnFamilyHandleList = + new ArrayList<>(); try { String db_path_string = dbFolder.getRoot().getAbsolutePath(); @@ -152,10 +156,6 @@ public class MergeTest { opt.setCreateMissingColumnFamilies(true); StringAppendOperator stringAppendOperator = new StringAppendOperator(); - List cfDescriptors = - new ArrayList<>(); - List columnFamilyHandleList = - new ArrayList<>(); cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions().setMergeOperator( stringAppendOperator))); @@ -175,23 +175,25 @@ public class MergeTest { String strValue = new String(value); // Test also with createColumnFamily - columnFamilyHandle = db.createColumnFamily( + cfHandle = db.createColumnFamily( new ColumnFamilyDescriptor("new_cf2".getBytes(), new ColumnFamilyOptions().setMergeOperator(stringAppendOperator))); // writing xx under cfkey2 - db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes()); + db.put(cfHandle, "cfkey2".getBytes(), "xx".getBytes()); // merge yy under cfkey2 - db.merge(columnFamilyHandle, new WriteOptions(), "cfkey2".getBytes(), "yy".getBytes()); - value = db.get(columnFamilyHandle, "cfkey2".getBytes()); + db.merge(cfHandle, new WriteOptions(), "cfkey2".getBytes(), "yy".getBytes()); + value = db.get(cfHandle, "cfkey2".getBytes()); String strValueTmpCf = new String(value); - columnFamilyHandle.dispose(); assertThat(strValue).isEqualTo("aa,bb"); assertThat(strValueTmpCf).isEqualTo("xx,yy"); } finally { - if (columnFamilyHandle != null) { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { columnFamilyHandle.dispose(); } + if (cfHandle != null) { + cfHandle.dispose(); + } if (db != null) { db.close(); } diff --git a/java/src/test/java/org/rocksdb/ReadOnlyTest.java b/java/src/test/java/org/rocksdb/ReadOnlyTest.java index a254481e5de5451ef1781e8405ca7fd65602a509..70ea75d1568b3be22cc23ddf142652d87de642c5 100644 --- a/java/src/test/java/org/rocksdb/ReadOnlyTest.java +++ b/java/src/test/java/org/rocksdb/ReadOnlyTest.java @@ -80,12 +80,21 @@ public class ReadOnlyTest { assertThat(new String(db3.get(readOnlyColumnFamilyHandleList2.get(1), "key2".getBytes()))).isEqualTo("value2"); } finally { + for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } + for (ColumnFamilyHandle columnFamilyHandle : readOnlyColumnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db2 != null) { db2.close(); } + for (ColumnFamilyHandle columnFamilyHandle : readOnlyColumnFamilyHandleList2) { + columnFamilyHandle.dispose(); + } if (db3 != null) { db3.close(); } @@ -100,13 +109,15 @@ public class ReadOnlyTest { RocksDB db = null; RocksDB rDb = null; Options options = null; + List cfDescriptors = new ArrayList<>(); + List readOnlyColumnFamilyHandleList = + new ArrayList<>(); try { - List cfDescriptors = new ArrayList<>(); + cfDescriptors.add( new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions())); - List readOnlyColumnFamilyHandleList = - new ArrayList<>(); + options = new Options(); options.setCreateIfMissing(true); @@ -120,6 +131,9 @@ public class ReadOnlyTest { // test that put fails in readonly mode rDb.put("key".getBytes(), "value".getBytes()); } finally { + for (ColumnFamilyHandle columnFamilyHandle : readOnlyColumnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -137,13 +151,14 @@ public class ReadOnlyTest { RocksDB db = null; RocksDB rDb = null; Options options = null; + List cfDescriptors = new ArrayList<>(); + List readOnlyColumnFamilyHandleList = + new ArrayList<>(); try { - List cfDescriptors = new ArrayList<>(); cfDescriptors.add( new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions())); - List readOnlyColumnFamilyHandleList = - new ArrayList<>(); + options = new Options(); options.setCreateIfMissing(true); @@ -157,6 +172,9 @@ public class ReadOnlyTest { rDb.put(readOnlyColumnFamilyHandleList.get(0), "key".getBytes(), "value".getBytes()); } finally { + for (ColumnFamilyHandle columnFamilyHandle : readOnlyColumnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -174,13 +192,13 @@ public class ReadOnlyTest { RocksDB db = null; RocksDB rDb = null; Options options = null; + List cfDescriptors = new ArrayList<>(); + List readOnlyColumnFamilyHandleList = + new ArrayList<>(); try { - List cfDescriptors = new ArrayList<>(); cfDescriptors.add( new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions())); - List readOnlyColumnFamilyHandleList = - new ArrayList<>(); options = new Options(); options.setCreateIfMissing(true); @@ -194,6 +212,9 @@ public class ReadOnlyTest { rDb.remove("key".getBytes()); } finally { + for (ColumnFamilyHandle columnFamilyHandle : readOnlyColumnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -211,13 +232,13 @@ public class ReadOnlyTest { RocksDB db = null; RocksDB rDb = null; Options options = null; + List cfDescriptors = new ArrayList<>(); + List readOnlyColumnFamilyHandleList = + new ArrayList<>(); try { - List cfDescriptors = new ArrayList<>(); cfDescriptors.add( new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions())); - List readOnlyColumnFamilyHandleList = - new ArrayList<>(); options = new Options(); options.setCreateIfMissing(true); @@ -233,6 +254,9 @@ public class ReadOnlyTest { rDb.remove(readOnlyColumnFamilyHandleList.get(0), "key".getBytes()); } finally { + for (ColumnFamilyHandle columnFamilyHandle : readOnlyColumnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -250,13 +274,14 @@ public class ReadOnlyTest { RocksDB db = null; RocksDB rDb = null; Options options = null; + List cfDescriptors = new ArrayList<>(); + List readOnlyColumnFamilyHandleList = + new ArrayList<>(); try { - List cfDescriptors = new ArrayList<>(); + cfDescriptors.add( new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions())); - List readOnlyColumnFamilyHandleList = - new ArrayList<>(); options = new Options(); options.setCreateIfMissing(true); @@ -273,6 +298,9 @@ public class ReadOnlyTest { wb.put("key".getBytes(), "value".getBytes()); rDb.write(new WriteOptions(), wb); } finally { + for (ColumnFamilyHandle columnFamilyHandle : readOnlyColumnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); } @@ -291,13 +319,15 @@ public class ReadOnlyTest { RocksDB rDb = null; Options options = null; WriteBatch wb = null; + List cfDescriptors = new ArrayList<>(); + List readOnlyColumnFamilyHandleList = + new ArrayList<>(); try { - List cfDescriptors = new ArrayList<>(); + cfDescriptors.add( new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions())); - List readOnlyColumnFamilyHandleList = - new ArrayList<>(); + options = new Options(); options.setCreateIfMissing(true); @@ -315,6 +345,9 @@ public class ReadOnlyTest { "key".getBytes(), "value".getBytes()); rDb.write(new WriteOptions(), wb); } finally { + for (ColumnFamilyHandle columnFamilyHandle : readOnlyColumnFamilyHandleList) { + columnFamilyHandle.dispose(); + } if (db != null) { db.close(); }