From 2a9cd87997e504d3dae634b34083abfd273647a8 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Mon, 26 Jun 2017 15:24:13 -0700 Subject: [PATCH] Fix jni WriteBatchThreadedTest Summary: WriteBatchThreadedTest is failing, at least on Mac. The problem seems to be `wb` is getting GC before we finish write. Explicitly close it seems to fix it. Closes https://github.com/facebook/rocksdb/pull/2482 Differential Revision: D5307379 Pulled By: yiwu-arbug fbshipit-source-id: 8ff7f8170451078c941951f5aafae83afffb7933 --- .../java/org/rocksdb/WriteBatchThreadedTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/java/src/test/java/org/rocksdb/WriteBatchThreadedTest.java b/java/src/test/java/org/rocksdb/WriteBatchThreadedTest.java index 66e1c8966..e31d83b28 100644 --- a/java/src/test/java/org/rocksdb/WriteBatchThreadedTest.java +++ b/java/src/test/java/org/rocksdb/WriteBatchThreadedTest.java @@ -59,13 +59,14 @@ public class WriteBatchThreadedTest { callables.add(new Callable() { @Override public Void call() throws RocksDBException { - final WriteBatch wb = new WriteBatch(); - for (int i = offset; i < offset + 100; i++) { - wb.put(ByteBuffer.allocate(4).putInt(i).array(), - "parallel rocks test".getBytes()); + try (final WriteBatch wb = new WriteBatch(); + final WriteOptions w_opt = new WriteOptions()) { + for (int i = offset; i < offset + 100; i++) { + wb.put(ByteBuffer.allocate(4).putInt(i).array(), + "parallel rocks test".getBytes()); + } + db.write(w_opt, wb); } - db.write(new WriteOptions(), wb); - return null; } });