From a283800616cb5da5da43d878037e6398cccf9090 Mon Sep 17 00:00:00 2001 From: SeterKwok Date: Mon, 4 Mar 2019 14:51:13 -0800 Subject: [PATCH] Move some RocksObject into try-with-resources in Test (#5037) Summary: Fix #5008 Pull Request resolved: https://github.com/facebook/rocksdb/pull/5037 Differential Revision: D14302474 Pulled By: riversand963 fbshipit-source-id: dcd9dda5d4d6d459315692f355499a39e546d518 --- java/src/test/java/org/rocksdb/RocksDBTest.java | 3 +-- java/src/test/java/org/rocksdb/WriteBatchTest.java | 6 +++--- .../java/org/rocksdb/WriteBatchWithIndexTest.java | 11 ++++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/java/src/test/java/org/rocksdb/RocksDBTest.java b/java/src/test/java/org/rocksdb/RocksDBTest.java index d825b0b2d..a7d7fee14 100644 --- a/java/src/test/java/org/rocksdb/RocksDBTest.java +++ b/java/src/test/java/org/rocksdb/RocksDBTest.java @@ -525,8 +525,7 @@ public class RocksDBTest { @Test public void deleteRange() throws RocksDBException { - try (final RocksDB db = RocksDB.open(dbFolder.getRoot().getAbsolutePath()); - final WriteOptions wOpt = new WriteOptions()) { + try (final RocksDB db = RocksDB.open(dbFolder.getRoot().getAbsolutePath())) { db.put("key1".getBytes(), "value".getBytes()); db.put("key2".getBytes(), "12345678".getBytes()); db.put("key3".getBytes(), "abcdefg".getBytes()); diff --git a/java/src/test/java/org/rocksdb/WriteBatchTest.java b/java/src/test/java/org/rocksdb/WriteBatchTest.java index 1e3e50b7e..92bec3dcf 100644 --- a/java/src/test/java/org/rocksdb/WriteBatchTest.java +++ b/java/src/test/java/org/rocksdb/WriteBatchTest.java @@ -180,6 +180,7 @@ public class WriteBatchTest { @Test public void deleteRange() throws RocksDBException { try (final RocksDB db = RocksDB.open(dbFolder.getRoot().getAbsolutePath()); + final WriteBatch batch = new WriteBatch(); final WriteOptions wOpt = new WriteOptions()) { db.put("key1".getBytes(), "value".getBytes()); db.put("key2".getBytes(), "12345678".getBytes()); @@ -190,9 +191,8 @@ public class WriteBatchTest { assertThat(db.get("key3".getBytes())).isEqualTo("abcdefg".getBytes()); assertThat(db.get("key4".getBytes())).isEqualTo("xyz".getBytes()); - WriteBatch batch = new WriteBatch(); batch.deleteRange("key2".getBytes(), "key4".getBytes()); - db.write(new WriteOptions(), batch); + db.write(wOpt, batch); assertThat(db.get("key1".getBytes())).isEqualTo("value".getBytes()); assertThat(db.get("key2".getBytes())).isNull(); @@ -399,7 +399,7 @@ public class WriteBatchTest { } @Test - public void hasEndrepareRange() throws RocksDBException { + public void hasEndPrepareRange() throws RocksDBException { try (final WriteBatch batch = new WriteBatch()) { assertThat(batch.hasEndPrepare()).isFalse(); } diff --git a/java/src/test/java/org/rocksdb/WriteBatchWithIndexTest.java b/java/src/test/java/org/rocksdb/WriteBatchWithIndexTest.java index 3a872c412..fcef00a39 100644 --- a/java/src/test/java/org/rocksdb/WriteBatchWithIndexTest.java +++ b/java/src/test/java/org/rocksdb/WriteBatchWithIndexTest.java @@ -104,7 +104,7 @@ public class WriteBatchWithIndexTest { } @Test - public void write_writeBatchWithIndex() throws RocksDBException { + public void writeBatchWithIndex() throws RocksDBException { try (final Options options = new Options().setCreateIfMissing(true); final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) { @@ -114,11 +114,12 @@ public class WriteBatchWithIndexTest { final byte[] k2 = "key2".getBytes(); final byte[] v2 = "value2".getBytes(); - try (final WriteBatchWithIndex wbwi = new WriteBatchWithIndex()) { + try (final WriteBatchWithIndex wbwi = new WriteBatchWithIndex(); + final WriteOptions wOpt = new WriteOptions()) { wbwi.put(k1, v1); wbwi.put(k2, v2); - db.write(new WriteOptions(), wbwi); + db.write(wOpt, wbwi); } assertThat(db.get(k1)).isEqualTo(v1); @@ -512,6 +513,7 @@ public class WriteBatchWithIndexTest { @Test public void deleteRange() throws RocksDBException { try (final RocksDB db = RocksDB.open(dbFolder.getRoot().getAbsolutePath()); + final WriteBatch batch = new WriteBatch(); final WriteOptions wOpt = new WriteOptions()) { db.put("key1".getBytes(), "value".getBytes()); db.put("key2".getBytes(), "12345678".getBytes()); @@ -522,9 +524,8 @@ public class WriteBatchWithIndexTest { assertThat(db.get("key3".getBytes())).isEqualTo("abcdefg".getBytes()); assertThat(db.get("key4".getBytes())).isEqualTo("xyz".getBytes()); - WriteBatch batch = new WriteBatch(); batch.deleteRange("key2".getBytes(), "key4".getBytes()); - db.write(new WriteOptions(), batch); + db.write(wOpt, batch); assertThat(db.get("key1".getBytes())).isEqualTo("value".getBytes()); assertThat(db.get("key2".getBytes())).isNull();