From 1fe7a4c62f09d871a9e7fb359e8ff80fa0e09bda Mon Sep 17 00:00:00 2001
From: fyrz
Date: Sun, 2 Nov 2014 01:08:41 +0100
Subject: [PATCH 01/12] [RocksJava] Test-framework integration
---
java/Makefile | 79 ++++---
java/org/rocksdb/ColumnFamilyHandle.java | 8 +-
java/org/rocksdb/RocksDB.java | 8 +-
java/org/rocksdb/RocksIterator.java | 8 +-
java/org/rocksdb/WriteBatch.java | 10 -
java/org/rocksdb/WriteBatchTest.java | 124 -----------
java/org/rocksdb/test/BackupableDBTest.java | 38 +++-
.../test/BlockBasedTableConfigTest.java | 10 +-
java/org/rocksdb/test/ColumnFamilyTest.java | 21 +-
.../rocksdb/test/ComparatorOptionsTest.java | 21 +-
java/org/rocksdb/test/ComparatorTest.java | 20 +-
.../rocksdb/test/DirectComparatorTest.java | 19 +-
java/org/rocksdb/test/FilterTest.java | 15 +-
java/org/rocksdb/test/MemTableTest.java | 45 ++--
java/org/rocksdb/test/MergeTest.java | 71 ++++---
.../rocksdb/test/PlainTableConfigTest.java | 11 +-
.../rocksdb/test/PlatformRandomHelper.java | 4 +-
java/org/rocksdb/test/ReadOnlyTest.java | 41 ++--
java/org/rocksdb/test/ReadOptionsTest.java | 17 +-
java/org/rocksdb/test/RocksIteratorTest.java | 59 +++---
.../org/rocksdb/test/RocksMemoryResource.java | 21 ++
java/org/rocksdb/test/SnapshotTest.java | 133 ++++++------
.../rocksdb/test/StatisticsCollectorTest.java | 28 ++-
java/org/rocksdb/test/WriteBatchTest.java | 130 ++++++++++++
java/rocksjni.pom | 194 +++++++++++++++---
java/rocksjni/write_batch.cc | 20 +-
26 files changed, 709 insertions(+), 446 deletions(-)
delete mode 100644 java/org/rocksdb/WriteBatchTest.java
create mode 100644 java/org/rocksdb/test/RocksMemoryResource.java
create mode 100644 java/org/rocksdb/test/WriteBatchTest.java
diff --git a/java/Makefile b/java/Makefile
index 21066b991..d3bd8d8d4 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -32,8 +32,8 @@ NATIVE_JAVA_CLASSES = org.rocksdb.AbstractComparator\
org.rocksdb.StringAppendOperator\
org.rocksdb.WriteBatch\
org.rocksdb.WriteBatch.Handler\
- org.rocksdb.WriteBatchInternal\
- org.rocksdb.WriteBatchTest\
+ org.rocksdb.test.WriteBatchInternal\
+ org.rocksdb.test.WriteBatchTest\
org.rocksdb.WriteOptions\
ROCKSDB_MAJOR = $(shell egrep "ROCKSDB_MAJOR.[0-9]" ../include/rocksdb/version.h | cut -d ' ' -f 3)
@@ -43,18 +43,51 @@ ROCKSDB_PATCH = $(shell egrep "ROCKSDB_PATCH.[0-9]" ../include/rocksdb/version.h
NATIVE_INCLUDE = ./include
ARCH := $(shell getconf LONG_BIT)
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-linux$(ARCH).jar
-
ifeq ($(PLATFORM), OS_MACOSX)
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar
endif
+JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
+ org.rocksdb.test.BackupableDBTest\
+ org.rocksdb.test.BlockBasedTableConfigTest\
+ org.rocksdb.test.ColumnFamilyOptionsTest\
+ org.rocksdb.test.ColumnFamilyTest\
+ org.rocksdb.test.ComparatorOptionsTest\
+ org.rocksdb.test.ComparatorTest\
+ org.rocksdb.test.DBOptionsTest\
+ org.rocksdb.test.DirectComparatorTest\
+ org.rocksdb.test.FilterTest\
+ org.rocksdb.test.FlushTest\
+ org.rocksdb.test.KeyMayExistTest\
+ org.rocksdb.test.MemTableTest\
+ org.rocksdb.test.MergeTest\
+ org.rocksdb.test.MixedOptionsTest\
+ org.rocksdb.test.OptionsTest\
+ org.rocksdb.test.PlainTableConfigTest\
+ org.rocksdb.test.ReadOnlyTest\
+ org.rocksdb.test.ReadOptionsTest\
+ org.rocksdb.test.RocksIteratorTest\
+ org.rocksdb.test.SnapshotTest\
+ org.rocksdb.test.StatisticsCollectorTest\
+ org.rocksdb.test.WirteBatchHandlerTest\
+ org.rocksdb.test.WriteBatchTest\
+
+JAVA_TEST_LIBDIR = ./test-libs/
+JAVA_JUNIT_JAR = $(JAVA_TEST_LIBDIR)junit-4.12-beta-2.jar
+JAVA_HAMCR_JAR = $(JAVA_TEST_LIBDIR)hamcrest-core-1.3.jar
+JAVA_MOCKITO_JAR = $(JAVA_TEST_LIBDIR)mockito-all-1.9.5.jar
+JAVA_CGLIB_JAR = $(JAVA_TEST_LIBDIR)cglib-2.2.2.jar
+JAVA_ASSERTJ_JAR = $(JAVA_TEST_LIBDIR)assertj-core-1.7.0.jar
+JAVA_TESTCLASSPATH = $(ROCKSDB_JAR):$(JAVA_JUNIT_JAR):$(JAVA_HAMCR_JAR):$(JAVA_MOCKITO_JAR):$(JAVA_CGLIB_JAR):$(JAVA_ASSERTJ_JAR):.:./*
+
clean:
-find . -name "*.class" -exec rm {} \;
-find . -name "hs*.log" -exec rm {} \;
rm -rf javadoc/*
+ rm -rf test-libs/
javadocs:
- mkdir -p javadoc; javadoc -d javadoc -sourcepath . -subpackages org
+ mkdir -p javadoc; javadoc -d javadoc -sourcepath . -subpackages org -exclude org.rocksdb.test
java: javadocs
javac org/rocksdb/util/*.java org/rocksdb/*.java
@@ -76,33 +109,17 @@ column_family_sample: java
java -ea -Djava.library.path=.:../ -cp ".:./*" -Xcheck:jni RocksDBColumnFamilySample /tmp/rocksdbjni
@rm -rf /tmp/rocksdbjni
-test: java
- @rm -rf /tmp/rocksdbjni_*
- javac org/rocksdb/test/*.java
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.WriteBatchTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.BackupableDBTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.BlockBasedTableConfigTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.DBOptionsTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.ColumnFamilyTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.ColumnFamilyOptionsTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.FilterTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.FlushTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.KeyMayExistTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.MemTableTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.MergeTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.MixedOptionsTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.OptionsTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.PlainTableConfigTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.ReadOnlyTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.ReadOptionsTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.RocksIteratorTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.SnapshotTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.StatisticsCollectorTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.ComparatorOptionsTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.ComparatorTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.DirectComparatorTest
- java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.WriteBatchHandlerTest
- @rm -rf /tmp/rocksdbjni_*
+resolve_test_deps:
+ mkdir -p "$(JAVA_TEST_LIBDIR)"
+ test -s "$(JAVA_JUNIT_JAR)" || curl -L -o $(JAVA_JUNIT_JAR) http://search.maven.org/remotecontent?filepath=junit/junit/4.12-beta-2/junit-4.12-beta-2.jar
+ test -s "$(JAVA_HAMCR_JAR)" || curl -L -o $(JAVA_HAMCR_JAR) http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
+ test -s "$(JAVA_MOCKITO_JAR)" || curl -L -o "$(JAVA_MOCKITO_JAR)" http://search.maven.org/remotecontent?filepath=org/mockito/mockito-all/1.9.5/mockito-all-1.9.5.jar
+ test -s "$(JAVA_CGLIB_JAR)" || curl -L -o "$(JAVA_CGLIB_JAR)" http://search.maven.org/remotecontent?filepath=cglib/cglib/2.2.2/cglib-2.2.2.jar
+ test -s "$(JAVA_ASSERTJ_JAR)" || curl -L -o "$(JAVA_ASSERTJ_JAR)" http://central.maven.org/maven2/org/assertj/assertj-core/1.7.0/assertj-core-1.7.0.jar
+
+test: java resolve_test_deps
+ javac -cp $(JAVA_TESTCLASSPATH) org/rocksdb/test/*.java
+ java -ea -Djava.library.path=.:../ -cp "$(JAVA_TESTCLASSPATH)" org.junit.runner.JUnitCore $(JAVA_TESTS)
db_bench: java
javac org/rocksdb/benchmark/*.java
diff --git a/java/org/rocksdb/ColumnFamilyHandle.java b/java/org/rocksdb/ColumnFamilyHandle.java
index 92a4d7cef..ed8417728 100644
--- a/java/org/rocksdb/ColumnFamilyHandle.java
+++ b/java/org/rocksdb/ColumnFamilyHandle.java
@@ -30,9 +30,11 @@ public class ColumnFamilyHandle extends RocksObject {
* before freeing the native handle.
*/
@Override protected void disposeInternal() {
- assert(isInitialized());
- if (rocksDB_.isInitialized()) {
- disposeInternal(nativeHandle_);
+ synchronized (rocksDB_) {
+ assert (isInitialized());
+ if (rocksDB_.isInitialized()) {
+ disposeInternal(nativeHandle_);
+ }
}
}
diff --git a/java/org/rocksdb/RocksDB.java b/java/org/rocksdb/RocksDB.java
index 5ebbc609e..730c1940d 100644
--- a/java/org/rocksdb/RocksDB.java
+++ b/java/org/rocksdb/RocksDB.java
@@ -363,8 +363,10 @@ public class RocksDB extends RocksObject {
}
@Override protected void disposeInternal() {
- assert(isInitialized());
- disposeInternal(nativeHandle_);
+ synchronized (this) {
+ assert (isInitialized());
+ disposeInternal(nativeHandle_);
+ }
}
/**
@@ -1150,6 +1152,8 @@ public class RocksDB extends RocksObject {
throws RocksDBException, IllegalArgumentException {
// throws RocksDBException if something goes wrong
dropColumnFamily(nativeHandle_, columnFamilyHandle.nativeHandle_);
+ // After the drop the native handle is not valid anymore
+ columnFamilyHandle.nativeHandle_ = 0;
}
/**
diff --git a/java/org/rocksdb/RocksIterator.java b/java/org/rocksdb/RocksIterator.java
index fee3f459d..b947b2c83 100644
--- a/java/org/rocksdb/RocksIterator.java
+++ b/java/org/rocksdb/RocksIterator.java
@@ -143,9 +143,11 @@ public class RocksIterator extends RocksObject {
* before freeing the native handle.
*/
@Override protected void disposeInternal() {
- assert(isInitialized());
- if (rocksDB_.isInitialized()) {
- disposeInternal(nativeHandle_);
+ synchronized (rocksDB_) {
+ assert (isInitialized());
+ if (rocksDB_.isInitialized()) {
+ disposeInternal(nativeHandle_);
+ }
}
}
diff --git a/java/org/rocksdb/WriteBatch.java b/java/org/rocksdb/WriteBatch.java
index 5bd1119da..3407033ab 100644
--- a/java/org/rocksdb/WriteBatch.java
+++ b/java/org/rocksdb/WriteBatch.java
@@ -221,13 +221,3 @@ public class WriteBatch extends RocksObject {
private native void disposeInternal(long handle);
}
}
-
-/**
- * Package-private class which provides java api to access
- * c++ WriteBatchInternal.
- */
-class WriteBatchInternal {
- static native void setSequence(WriteBatch batch, long sn);
- static native long sequence(WriteBatch batch);
- static native void append(WriteBatch b1, WriteBatch b2);
-}
diff --git a/java/org/rocksdb/WriteBatchTest.java b/java/org/rocksdb/WriteBatchTest.java
deleted file mode 100644
index 770cd85b8..000000000
--- a/java/org/rocksdb/WriteBatchTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright (c) 2014, Facebook, Inc. All rights reserved.
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
-//
-// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file. See the AUTHORS file for names of contributors.
-package org.rocksdb;
-
-import java.util.*;
-import java.io.UnsupportedEncodingException;
-
-/**
- * This class mimics the db/write_batch_test.cc in the c++ rocksdb library.
- */
-public class WriteBatchTest {
- static {
- RocksDB.loadLibrary();
- }
-
- public static void main(String args[]) {
- System.out.println("Testing WriteBatchTest.Empty ===");
- Empty();
-
- System.out.println("Testing WriteBatchTest.Multiple ===");
- Multiple();
-
- System.out.println("Testing WriteBatchTest.Append ===");
- Append();
-
- System.out.println("Testing WriteBatchTest.Blob ===");
- Blob();
-
- // The following tests have not yet ported.
- // Continue();
- // PutGatherSlices();
-
- System.out.println("Passed all WriteBatchTest!");
- }
-
- static void Empty() {
- WriteBatch batch = new WriteBatch();
- assert(batch.count() == 0);
- }
-
- static void Multiple() {
- try {
- WriteBatch batch = new WriteBatch();
- batch.put("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
- batch.remove("box".getBytes("US-ASCII"));
- batch.put("baz".getBytes("US-ASCII"), "boo".getBytes("US-ASCII"));
- WriteBatchInternal.setSequence(batch, 100);
- assert(100 == WriteBatchInternal.sequence(batch));
- assert(3 == batch.count());
- assert(("Put(baz, boo)@102" +
- "Delete(box)@101" +
- "Put(foo, bar)@100")
- .equals(new String(getContents(batch), "US-ASCII")));
- } catch (UnsupportedEncodingException e) {
- System.err.println(e);
- assert(false);
- }
- }
-
- static void Append() {
- WriteBatch b1 = new WriteBatch();
- WriteBatch b2 = new WriteBatch();
- WriteBatchInternal.setSequence(b1, 200);
- WriteBatchInternal.setSequence(b2, 300);
- WriteBatchInternal.append(b1, b2);
- assert(getContents(b1).length == 0);
- assert(b1.count() == 0);
- try {
- b2.put("a".getBytes("US-ASCII"), "va".getBytes("US-ASCII"));
- WriteBatchInternal.append(b1, b2);
- assert("Put(a, va)@200".equals(new String(getContents(b1), "US-ASCII")));
- assert(1 == b1.count());
- b2.clear();
- b2.put("b".getBytes("US-ASCII"), "vb".getBytes("US-ASCII"));
- WriteBatchInternal.append(b1, b2);
- assert(("Put(a, va)@200" +
- "Put(b, vb)@201")
- .equals(new String(getContents(b1), "US-ASCII")));
- assert(2 == b1.count());
- b2.remove("foo".getBytes("US-ASCII"));
- WriteBatchInternal.append(b1, b2);
- assert(("Put(a, va)@200" +
- "Put(b, vb)@202" +
- "Put(b, vb)@201" +
- "Delete(foo)@203")
- .equals(new String(getContents(b1), "US-ASCII")));
- assert(4 == b1.count());
- } catch (UnsupportedEncodingException e) {
- System.err.println(e);
- assert(false);
- }
- }
-
- static void Blob() {
- WriteBatch batch = new WriteBatch();
- try {
- batch.put("k1".getBytes("US-ASCII"), "v1".getBytes("US-ASCII"));
- batch.put("k2".getBytes("US-ASCII"), "v2".getBytes("US-ASCII"));
- batch.put("k3".getBytes("US-ASCII"), "v3".getBytes("US-ASCII"));
- batch.putLogData("blob1".getBytes("US-ASCII"));
- batch.remove("k2".getBytes("US-ASCII"));
- batch.putLogData("blob2".getBytes("US-ASCII"));
- batch.merge("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
- assert(5 == batch.count());
- assert(("Merge(foo, bar)@4" +
- "Put(k1, v1)@0" +
- "Delete(k2)@3" +
- "Put(k2, v2)@1" +
- "Put(k3, v3)@2")
- .equals(new String(getContents(batch), "US-ASCII")));
- } catch (UnsupportedEncodingException e) {
- System.err.println(e);
- assert(false);
- }
- }
-
- static native byte[] getContents(WriteBatch batch);
-}
diff --git a/java/org/rocksdb/test/BackupableDBTest.java b/java/org/rocksdb/test/BackupableDBTest.java
index 2115e9ca9..f0a6708c1 100644
--- a/java/org/rocksdb/test/BackupableDBTest.java
+++ b/java/org/rocksdb/test/BackupableDBTest.java
@@ -5,28 +5,41 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
import java.util.List;
public class BackupableDBTest {
- static final String db_path = "/tmp/rocksdbjni_backupable_db_test";
- static final String backup_path = "/tmp/rocksdbjni_backupable_db_backup_test";
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args) {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @Rule
+ public TemporaryFolder backupFolder = new TemporaryFolder();
+
+ @Test
+ public void shouldTestBackupableDb() {
Options opt = new Options();
opt.setCreateIfMissing(true);
- BackupableDBOptions bopt = new BackupableDBOptions(backup_path, false,
+ BackupableDBOptions bopt = new BackupableDBOptions(
+ backupFolder.getRoot().getAbsolutePath(), false,
true, false, true, 0, 0);
BackupableDB bdb = null;
List backupInfos;
List restoreInfos;
try {
- bdb = BackupableDB.open(opt, bopt, db_path);
+ bdb = BackupableDB.open(opt, bopt,
+ dbFolder.getRoot().getAbsolutePath());
bdb.put("abc".getBytes(), "def".getBytes());
bdb.put("ghi".getBytes(), "jkl".getBytes());
@@ -74,7 +87,9 @@ public class BackupableDBTest {
assert(restoreInfos.get(0).numberFiles() ==
backupInfos.get(0).numberFiles());
- rdb.restoreDBFromLatestBackup(db_path, db_path,
+ rdb.restoreDBFromLatestBackup(
+ dbFolder.getRoot().getAbsolutePath(),
+ dbFolder.getRoot().getAbsolutePath(),
ropt);
// do nothing because there is only one backup
rdb.purgeOldBackups(1);
@@ -84,7 +99,8 @@ public class BackupableDBTest {
ropt.dispose();
// verify that backed up data contains deleted record
- bdb = BackupableDB.open(opt, bopt, db_path);
+ bdb = BackupableDB.open(opt, bopt,
+ dbFolder.getRoot().getAbsolutePath());
value = bdb.get("abc".getBytes());
assert(new String(value).equals("def"));
@@ -110,7 +126,6 @@ public class BackupableDBTest {
assert(backupInfos.size() == 2);
assert(backupInfos.get(0).backupId() == 4);
assert(backupInfos.get(1).backupId() == 5);
- System.out.println("Backup and restore test passed");
} catch (RocksDBException e) {
System.err.format("[ERROR]: %s%n", e);
e.printStackTrace();
@@ -121,5 +136,6 @@ public class BackupableDBTest {
bdb.close();
}
}
+ System.out.println("Passed BackupableDBTest.");
}
}
diff --git a/java/org/rocksdb/test/BlockBasedTableConfigTest.java b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
index 3f54d5a78..8c73915ee 100644
--- a/java/org/rocksdb/test/BlockBasedTableConfigTest.java
+++ b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
@@ -5,13 +5,19 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.rocksdb.BlockBasedTableConfig;
import org.rocksdb.ChecksumType;
import org.rocksdb.IndexType;
public class BlockBasedTableConfigTest {
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
- public static void main(String[] args) {
+ @Test
+ public void shouldTestBlockBasedTableConfig() {
BlockBasedTableConfig blockBasedTableConfig =
new BlockBasedTableConfig();
blockBasedTableConfig.setNoBlockCache(true);
@@ -42,6 +48,6 @@ public class BlockBasedTableConfigTest {
== 4);
blockBasedTableConfig.setCacheNumShardBits(5);
assert(blockBasedTableConfig.cacheNumShardBits() == 5);
- System.out.println("BlockBasedTableConfig test passed");
+ System.out.println("Passed BlockBasedTableConfigTest.");
}
}
diff --git a/java/org/rocksdb/test/ColumnFamilyTest.java b/java/org/rocksdb/test/ColumnFamilyTest.java
index 350c4446c..e52eac589 100644
--- a/java/org/rocksdb/test/ColumnFamilyTest.java
+++ b/java/org/rocksdb/test/ColumnFamilyTest.java
@@ -9,16 +9,25 @@ import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
+
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
public class ColumnFamilyTest {
- static final String db_path = "/tmp/rocksdbjni_columnfamily_test";
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args) {
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+ @Test
+ public void shouldTestColumnFamilies() {
+ String db_path = dbFolder.getRoot().getAbsolutePath();
RocksDB db = null;
Options options = new Options();
options.setCreateIfMissing(true);
@@ -274,7 +283,6 @@ public class ColumnFamilyTest {
assert(false);
}
- System.out.println("Passed ColumnFamilyTest");
// free cf handles before database close
for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) {
columnFamilyHandle.dispose();
@@ -283,5 +291,6 @@ public class ColumnFamilyTest {
db.close();
// be sure to dispose c++ pointers
options.dispose();
+ System.out.println("Passed ColumnFamilyTest.");
}
}
diff --git a/java/org/rocksdb/test/ComparatorOptionsTest.java b/java/org/rocksdb/test/ComparatorOptionsTest.java
index e25209392..21f4fc2a1 100644
--- a/java/org/rocksdb/test/ComparatorOptionsTest.java
+++ b/java/org/rocksdb/test/ComparatorOptionsTest.java
@@ -5,27 +5,30 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.rocksdb.ComparatorOptions;
-import org.rocksdb.RocksDB;
-import java.util.Random;
+import static org.assertj.core.api.Assertions.assertThat;
public class ComparatorOptionsTest {
- static {
- RocksDB.loadLibrary();
- }
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
- public static void main(String[] args) {
+ @Test
+ public void shouldTestComparatorOptions() {
final ComparatorOptions copt = new ComparatorOptions();
- Random rand = new Random();
+
+ assertThat(copt).isNotNull();
{ // UseAdaptiveMutex test
copt.setUseAdaptiveMutex(true);
- assert(copt.useAdaptiveMutex() == true);
+ assertThat(copt.useAdaptiveMutex()).isTrue();
copt.setUseAdaptiveMutex(false);
- assert(copt.useAdaptiveMutex() == false);
+ assertThat(copt.useAdaptiveMutex()).isFalse();
}
copt.dispose();
diff --git a/java/org/rocksdb/test/ComparatorTest.java b/java/org/rocksdb/test/ComparatorTest.java
index 34d7c78df..d65a0653a 100644
--- a/java/org/rocksdb/test/ComparatorTest.java
+++ b/java/org/rocksdb/test/ComparatorTest.java
@@ -5,19 +5,26 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
import java.io.IOException;
import java.nio.file.FileSystems;
public class ComparatorTest {
- private static final String db_path = "/tmp/comparator_db";
- static {
- RocksDB.loadLibrary();
- }
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
- public static void main(String[] args) throws IOException {
+ @Test
+ public void shouldTestComparator() throws IOException {
final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() {
@Override
@@ -38,7 +45,8 @@ public class ComparatorTest {
};
// test the round-tripability of keys written and read with the Comparator
- comparatorTest.testRoundtrip(FileSystems.getDefault().getPath(db_path));
+ comparatorTest.testRoundtrip(FileSystems.getDefault().getPath(
+ dbFolder.getRoot().getAbsolutePath()));
System.out.println("Passed ComparatorTest");
}
diff --git a/java/org/rocksdb/test/DirectComparatorTest.java b/java/org/rocksdb/test/DirectComparatorTest.java
index 9df06eb73..562038897 100644
--- a/java/org/rocksdb/test/DirectComparatorTest.java
+++ b/java/org/rocksdb/test/DirectComparatorTest.java
@@ -5,19 +5,25 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
import java.io.IOException;
import java.nio.file.FileSystems;
public class DirectComparatorTest {
- private static final String db_path = "/tmp/direct_comparator_db";
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
- static {
- RocksDB.loadLibrary();
- }
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
- public static void main(String[] args) throws IOException {
+ @Test
+ public void shouldTestDirectComparator() throws IOException {
final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() {
@Override
@@ -41,7 +47,8 @@ public class DirectComparatorTest {
};
// test the round-tripability of keys written and read with the DirectComparator
- comparatorTest.testRoundtrip(FileSystems.getDefault().getPath(db_path));
+ comparatorTest.testRoundtrip(FileSystems.getDefault().getPath(
+ dbFolder.getRoot().getAbsolutePath()));
System.out.println("Passed DirectComparatorTest");
}
diff --git a/java/org/rocksdb/test/FilterTest.java b/java/org/rocksdb/test/FilterTest.java
index fc4fabf56..3894167b0 100644
--- a/java/org/rocksdb/test/FilterTest.java
+++ b/java/org/rocksdb/test/FilterTest.java
@@ -5,13 +5,18 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.rocksdb.*;
public class FilterTest {
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args) {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Test
+ public void shouldTestFilter() {
Options options = new Options();
// test table config
BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
@@ -37,6 +42,6 @@ public class FilterTest {
blockConfig = null;
System.gc();
System.runFinalization();
- System.out.println("Filter test passed");
+ System.out.println("Passed FilterTest.");
}
}
diff --git a/java/org/rocksdb/test/MemTableTest.java b/java/org/rocksdb/test/MemTableTest.java
index 0d1e4d54a..0b1244fc2 100644
--- a/java/org/rocksdb/test/MemTableTest.java
+++ b/java/org/rocksdb/test/MemTableTest.java
@@ -5,13 +5,18 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.rocksdb.*;
public class MemTableTest {
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args) {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Test
+ public void shouldTestMemTable() throws RocksDBException {
Options options = new Options();
// Test HashSkipListMemTableConfig
HashSkipListMemTableConfig memTableConfig =
@@ -25,11 +30,7 @@ public class MemTableTest {
assert(memTableConfig.branchingFactor() == 4);
memTableConfig.setBranchingFactor(6);
assert(memTableConfig.branchingFactor() == 6);
- try {
- options.setMemTableConfig(memTableConfig);
- } catch (RocksDBException e) {
- assert(false);
- }
+ options.setMemTableConfig(memTableConfig);
memTableConfig = null;
options.dispose();
System.gc();
@@ -41,11 +42,7 @@ public class MemTableTest {
assert(skipMemTableConfig.lookahead() == 0);
skipMemTableConfig.setLookahead(20);
assert(skipMemTableConfig.lookahead() == 20);
- try {
- options.setMemTableConfig(skipMemTableConfig);
- } catch (RocksDBException e) {
- assert(false);
- }
+ options.setMemTableConfig(skipMemTableConfig);
skipMemTableConfig = null;
options.dispose();
System.gc();
@@ -67,21 +64,17 @@ public class MemTableTest {
assert(hashLinkedListMemTableConfig.
bucketEntriesLoggingThreshold() == 200);
assert(hashLinkedListMemTableConfig.
- ifLogBucketDistWhenFlush() == true);
+ ifLogBucketDistWhenFlush());
hashLinkedListMemTableConfig.
setIfLogBucketDistWhenFlush(false);
- assert(hashLinkedListMemTableConfig.
- ifLogBucketDistWhenFlush() == false);
+ assert(!hashLinkedListMemTableConfig.
+ ifLogBucketDistWhenFlush());
assert(hashLinkedListMemTableConfig.
thresholdUseSkiplist() == 256);
hashLinkedListMemTableConfig.setThresholdUseSkiplist(29);
assert(hashLinkedListMemTableConfig.
thresholdUseSkiplist() == 29);
- try {
- options.setMemTableConfig(hashLinkedListMemTableConfig);
- } catch (RocksDBException e) {
- assert(false);
- }
+ options.setMemTableConfig(hashLinkedListMemTableConfig);
hashLinkedListMemTableConfig = null;
options.dispose();
System.gc();
@@ -93,15 +86,11 @@ public class MemTableTest {
assert(vectorMemTableConfig.reservedSize() == 0);
vectorMemTableConfig.setReservedSize(123);
assert(vectorMemTableConfig.reservedSize() == 123);
- try {
- options.setMemTableConfig(vectorMemTableConfig);
- } catch (RocksDBException e) {
- assert(false);
- }
+ options.setMemTableConfig(vectorMemTableConfig);
vectorMemTableConfig = null;
options.dispose();
System.gc();
System.runFinalization();
- System.out.println("Mem-table test passed");
+ System.out.println("Passed MemTableTest.");
}
}
diff --git a/java/org/rocksdb/test/MergeTest.java b/java/org/rocksdb/test/MergeTest.java
index d802559e1..31a3fe5cb 100644
--- a/java/org/rocksdb/test/MergeTest.java
+++ b/java/org/rocksdb/test/MergeTest.java
@@ -7,19 +7,33 @@ package org.rocksdb.test;
import java.util.List;
import java.util.ArrayList;
+
+import org.junit.AfterClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
public class MergeTest {
- static final String db_path_string = "/tmp/rocksdbjni_mergestring_db";
- static final String db_cf_path_string = "/tmp/rocksdbjni_mergecfstring_db";
- static final String db_path_operator = "/tmp/rocksdbjni_mergeoperator_db";
- static {
- RocksDB.loadLibrary();
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @AfterClass
+ public static void printMergePass(){
+ System.out.println("Passed MergeTest.");
}
- public static void testStringOption()
+ @Test
+ public void shouldTestStringOption()
throws InterruptedException, RocksDBException {
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
Options opt = new Options();
opt.setCreateIfMissing(true);
opt.setMergeOperatorName("stringappend");
@@ -38,23 +52,26 @@ public class MergeTest {
assert(strValue.equals("aa,bb"));
}
- public static void testCFStringOption()
+ @Test
+ public void shouldTestCFStringOption()
throws InterruptedException, RocksDBException {
DBOptions opt = new DBOptions();
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
opt.setCreateIfMissing(true);
opt.setCreateMissingColumnFamilies(true);
List cfDescr =
- new ArrayList();
+ new ArrayList<>();
List columnFamilyHandleList =
- new ArrayList();
+ new ArrayList<>();
cfDescr.add(new ColumnFamilyDescriptor("default",
new ColumnFamilyOptions().setMergeOperatorName(
"stringappend")));
cfDescr.add(new ColumnFamilyDescriptor("default",
new ColumnFamilyOptions().setMergeOperatorName(
"stringappend")));
- RocksDB db = RocksDB.open(opt, db_cf_path_string,
+ RocksDB db = RocksDB.open(opt, db_path_string,
cfDescr, columnFamilyHandleList);
// writing aa under key
@@ -75,8 +92,11 @@ public class MergeTest {
assert(strValue.equals("aa,bb"));
}
- public static void testOperatorOption()
+ @Test
+ public void shouldTestOperatorOption()
throws InterruptedException, RocksDBException {
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
Options opt = new Options();
opt.setCreateIfMissing(true);
@@ -98,26 +118,29 @@ public class MergeTest {
assert(strValue.equals("aa,bb"));
}
- public static void testCFOperatorOption()
+ @Test
+ public void shouldTestCFOperatorOption()
throws InterruptedException, RocksDBException {
DBOptions opt = new DBOptions();
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
+
opt.setCreateIfMissing(true);
opt.setCreateMissingColumnFamilies(true);
StringAppendOperator stringAppendOperator = new StringAppendOperator();
List cfDescr =
- new ArrayList();
+ new ArrayList<>();
List columnFamilyHandleList =
- new ArrayList();
+ new ArrayList<>();
cfDescr.add(new ColumnFamilyDescriptor("default",
new ColumnFamilyOptions().setMergeOperator(
stringAppendOperator)));
cfDescr.add(new ColumnFamilyDescriptor("new_cf",
new ColumnFamilyOptions().setMergeOperator(
stringAppendOperator)));
- RocksDB db = RocksDB.open(opt, db_path_operator,
+ RocksDB db = RocksDB.open(opt, db_path_string,
cfDescr, columnFamilyHandleList);
-
// writing aa under key
db.put(columnFamilyHandleList.get(1),
"cfkey".getBytes(), "aa".getBytes());
@@ -139,14 +162,18 @@ public class MergeTest {
value = db.get(columnFamilyHandle, "cfkey2".getBytes());
String strValueTmpCf = new String(value);
+ columnFamilyHandle.dispose();
db.close();
opt.dispose();
assert(strValue.equals("aa,bb"));
assert(strValueTmpCf.equals("xx,yy"));
}
- public static void testOperatorGcBehaviour()
+ @Test
+ public void shouldTestOperatorGcBehaviour()
throws RocksDBException {
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
Options opt = new Options();
opt.setCreateIfMissing(true);
StringAppendOperator stringAppendOperator = new StringAppendOperator();
@@ -185,14 +212,4 @@ public class MergeTest {
System.gc();
System.runFinalization();
}
-
- public static void main(String[] args)
- throws InterruptedException, RocksDBException {
- testStringOption();
- testCFStringOption();
- testOperatorOption();
- testCFOperatorOption();
- testOperatorGcBehaviour();
- System.out.println("Passed MergeTest.");
- }
}
diff --git a/java/org/rocksdb/test/PlainTableConfigTest.java b/java/org/rocksdb/test/PlainTableConfigTest.java
index 888f35d81..f4cebb155 100644
--- a/java/org/rocksdb/test/PlainTableConfigTest.java
+++ b/java/org/rocksdb/test/PlainTableConfigTest.java
@@ -5,12 +5,19 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.rocksdb.EncodingType;
import org.rocksdb.PlainTableConfig;
public class PlainTableConfigTest {
- public static void main(String[] args) {
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Test
+ public void shouldTestPlainTableConfig() {
PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setKeySize(5);
assert(plainTableConfig.keySize() == 5);
@@ -29,6 +36,6 @@ public class PlainTableConfigTest {
assert(plainTableConfig.fullScanMode());
plainTableConfig.setStoreIndexInFile(true);
assert(plainTableConfig.storeIndexInFile());
- System.out.println("PlainTableConfig test passed");
+ System.out.println("Passed PlainTableConfigTest.");
}
}
diff --git a/java/org/rocksdb/test/PlatformRandomHelper.java b/java/org/rocksdb/test/PlatformRandomHelper.java
index 7112fc4f1..d43f4a4f0 100644
--- a/java/org/rocksdb/test/PlatformRandomHelper.java
+++ b/java/org/rocksdb/test/PlatformRandomHelper.java
@@ -18,11 +18,11 @@ public class PlatformRandomHelper {
* @return boolean value indicating if operating system is 64 Bit.
*/
public static boolean isOs64Bit(){
- boolean is64Bit = false;
+ boolean is64Bit;
if (System.getProperty("os.name").contains("Windows")) {
is64Bit = (System.getenv("ProgramFiles(x86)") != null);
} else {
- is64Bit = (System.getProperty("os.arch").indexOf("64") != -1);
+ is64Bit = (System.getProperty("os.arch").contains("64"));
}
return is64Bit;
}
diff --git a/java/org/rocksdb/test/ReadOnlyTest.java b/java/org/rocksdb/test/ReadOnlyTest.java
index 21b5eb9ae..057d2d4b8 100644
--- a/java/org/rocksdb/test/ReadOnlyTest.java
+++ b/java/org/rocksdb/test/ReadOnlyTest.java
@@ -4,31 +4,41 @@
// of patent rights can be found in the PATENTS file in the same directory.
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
import java.util.ArrayList;
import java.util.List;
public class ReadOnlyTest {
- static final String DB_PATH = "/tmp/rocksdbjni_readonly_test";
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args){
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @Test
+ public void shouldTestReadOnlyOpen() {
RocksDB db = null, db2 = null, db3 = null;
List columnFamilyHandleList =
- new ArrayList();
+ new ArrayList<>();
List db2ColumnFamilyHandleList =
- new ArrayList();
+ new ArrayList<>();
List db3ColumnFamilyHandleList =
- new ArrayList();
+ new ArrayList<>();
Options options = new Options();
options.setCreateIfMissing(true);
try {
- db = RocksDB.open(options, DB_PATH);
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
db.put("key".getBytes(), "value".getBytes());
- db2 = RocksDB.openReadOnly(DB_PATH);
+ db2 = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath());
assert("value".equals(new String(db2.get("key".getBytes()))));
db.close();
db2.close();
@@ -38,7 +48,7 @@ public class ReadOnlyTest {
new ArrayList();
cfNames.add(new ColumnFamilyDescriptor("default"));
- db = RocksDB.open(DB_PATH, cfNames, columnFamilyHandleList);
+ db = RocksDB.open(dbFolder.getRoot().getAbsolutePath(), cfNames, columnFamilyHandleList);
columnFamilyHandleList.add(db.createColumnFamily(
new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
columnFamilyHandleList.add(db.createColumnFamily(
@@ -46,15 +56,16 @@ public class ReadOnlyTest {
db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
"value2".getBytes());
- db2 = RocksDB.openReadOnly(DB_PATH, cfNames, db2ColumnFamilyHandleList);
+ db2 = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfNames, db2ColumnFamilyHandleList);
assert(db2.get("key2".getBytes())==null);
assert(db2.get(columnFamilyHandleList.get(0), "key2".getBytes())==null);
List cfNewName =
- new ArrayList();
+ new ArrayList<>();
cfNewName.add(new ColumnFamilyDescriptor("default"));
cfNewName.add(new ColumnFamilyDescriptor("new_cf2"));
- db3 = RocksDB.openReadOnly(DB_PATH, cfNewName, db3ColumnFamilyHandleList);
+ db3 = RocksDB.openReadOnly(dbFolder.getRoot().getAbsolutePath(), cfNewName, db3ColumnFamilyHandleList);
assert(new String(db3.get(db3ColumnFamilyHandleList.get(1),
"key2".getBytes())).equals("value2"));
}catch (RocksDBException e){
@@ -125,6 +136,6 @@ public class ReadOnlyTest {
columnFamilyHandle.dispose();
}
db3.close();
- System.out.println("Passed ReadOnlyTest");
+ System.out.println("Passed ReadOnlyTest.");
}
}
diff --git a/java/org/rocksdb/test/ReadOptionsTest.java b/java/org/rocksdb/test/ReadOptionsTest.java
index b3b5b2690..27d757a10 100644
--- a/java/org/rocksdb/test/ReadOptionsTest.java
+++ b/java/org/rocksdb/test/ReadOptionsTest.java
@@ -6,14 +6,20 @@
package org.rocksdb.test;
import java.util.Random;
+
+import org.junit.ClassRule;
+import org.junit.Test;
import org.rocksdb.RocksDB;
import org.rocksdb.ReadOptions;
public class ReadOptionsTest {
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args) {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Test
+ public void shouldTestReadOptions() {
ReadOptions opt = new ReadOptions();
Random rand = new Random();
{ // VerifyChecksums test
@@ -33,8 +39,7 @@ public class ReadOptionsTest {
opt.setTailing(boolValue);
assert(opt.tailing() == boolValue);
}
-
opt.dispose();
- System.out.println("Passed ReadOptionsTest");
+ System.out.println("Passed ReadOptionsTest.");
}
}
diff --git a/java/org/rocksdb/test/RocksIteratorTest.java b/java/org/rocksdb/test/RocksIteratorTest.java
index 1e2fa8c6d..7de27cad9 100644
--- a/java/org/rocksdb/test/RocksIteratorTest.java
+++ b/java/org/rocksdb/test/RocksIteratorTest.java
@@ -4,45 +4,46 @@
// of patent rights can be found in the PATENTS file in the same directory.
package org.rocksdb.test;
-import org.rocksdb.ColumnFamilyHandle;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.Options;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;
-import java.util.ArrayList;
-import java.util.List;
-
public class RocksIteratorTest {
- static final String DB_PATH = "/tmp/rocksdbjni_iterator_test";
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args){
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @Test
+ public void shouldTestRocksIteratorGc()
+ throws RocksDBException {
RocksDB db;
Options options = new Options();
options.setCreateIfMissing(true)
.setCreateMissingColumnFamilies(true);
- try {
- db = RocksDB.open(options, DB_PATH);
- db.put("key".getBytes(), "value".getBytes());
- RocksIterator iter = db.newIterator();
- RocksIterator iter2 = db.newIterator();
- RocksIterator iter3 = db.newIterator();
- iter = null;
- db.close();
- db = null;
- iter2 = null;
- System.gc();
- System.runFinalization();
- System.out.println("Passed RocksIterator Test");
- iter3.dispose();
- System.gc();
- System.runFinalization();
- }catch (RocksDBException e){
- e.printStackTrace();
- assert(false);
- }
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.put("key".getBytes(), "value".getBytes());
+ RocksIterator iter = db.newIterator();
+ RocksIterator iter2 = db.newIterator();
+ RocksIterator iter3 = db.newIterator();
+ iter = null;
+ db.close();
+ db = null;
+ iter2 = null;
+ System.gc();
+ System.runFinalization();
+ iter3.dispose();
+ System.gc();
+ System.runFinalization();
+ System.out.println("Passed RocksIteratorTest.");
}
}
diff --git a/java/org/rocksdb/test/RocksMemoryResource.java b/java/org/rocksdb/test/RocksMemoryResource.java
new file mode 100644
index 000000000..eabbc822e
--- /dev/null
+++ b/java/org/rocksdb/test/RocksMemoryResource.java
@@ -0,0 +1,21 @@
+package org.rocksdb.test;
+
+import org.junit.rules.ExternalResource;
+import org.rocksdb.RocksDB;
+
+/**
+ * Resource to trigger garbage collection after each test
+ * run.
+ */
+public class RocksMemoryResource extends ExternalResource {
+
+ static {
+ RocksDB.loadLibrary();
+ }
+
+ @Override
+ protected void after() {
+ System.gc();
+ System.runFinalization();
+ }
+}
\ No newline at end of file
diff --git a/java/org/rocksdb/test/SnapshotTest.java b/java/org/rocksdb/test/SnapshotTest.java
index 67d0a83ef..ad3546de3 100644
--- a/java/org/rocksdb/test/SnapshotTest.java
+++ b/java/org/rocksdb/test/SnapshotTest.java
@@ -4,84 +4,79 @@
// of patent rights can be found in the PATENTS file in the same directory.
package org.rocksdb.test;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.rocksdb.ColumnFamilyHandle;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.Options;
import org.rocksdb.ReadOptions;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.Snapshot;
-import org.rocksdb.WriteBatch;
-import org.rocksdb.WriteOptions;
+public class SnapshotTest {
-public class SnapshotTest
-{
- static final String DB_PATH = "/tmp/rocksdbjni_snapshot_test";
- static {
- RocksDB.loadLibrary();
- }
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
- public static void main(String[] args){
- RocksDB db = null;
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @Test
+ public void shouldTestSnapshots() throws RocksDBException {
+ RocksDB db;
Options options = new Options();
options.setCreateIfMissing(true);
- try {
- db = RocksDB.open(options, DB_PATH);
- db.put("key".getBytes(), "value".getBytes());
- // Get new Snapshot of database
- Snapshot snapshot = db.getSnapshot();
- ReadOptions readOptions = new ReadOptions();
- // set snapshot in ReadOptions
- readOptions.setSnapshot(snapshot);
- // retrieve key value pair
- assert(new String(db.get("key".getBytes()))
- .equals("value"));
- // retrieve key value pair created before
- // the snapshot was made
- assert(new String(db.get(readOptions,
- "key".getBytes())).equals("value"));
- // add new key/value pair
- db.put("newkey".getBytes(), "newvalue".getBytes());
- // using no snapshot the latest db entries
- // will be taken into account
- assert(new String(db.get("newkey".getBytes()))
- .equals("newvalue"));
- // snapshopot was created before newkey
- assert(db.get(readOptions, "newkey".getBytes())
- == null);
- // Retrieve snapshot from read options
- Snapshot sameSnapshot = readOptions.snapshot();
- readOptions.setSnapshot(sameSnapshot);
- // results must be the same with new Snapshot
- // instance using the same native pointer
- assert(new String(db.get(readOptions,
- "key".getBytes())).equals("value"));
- // update key value pair to newvalue
- db.put("key".getBytes(), "newvalue".getBytes());
- // read with previously created snapshot will
- // read previous version of key value pair
- assert(new String(db.get(readOptions,
- "key".getBytes())).equals("value"));
- // read for newkey using the snapshot must be
- // null
- assert(db.get(readOptions, "newkey".getBytes())
- == null);
- // setting null to snapshot in ReadOptions leads
- // to no Snapshot being used.
- readOptions.setSnapshot(null);
- assert(new String(db.get(readOptions,
- "newkey".getBytes())).equals("newvalue"));
- // release Snapshot
- db.releaseSnapshot(snapshot);
- // Close database
- db.close();
- }catch (RocksDBException e){
- e.printStackTrace();
- assert(false);
- }
- System.out.println("Passed SnapshotTest");
+
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
+ db.put("key".getBytes(), "value".getBytes());
+ // Get new Snapshot of database
+ Snapshot snapshot = db.getSnapshot();
+ ReadOptions readOptions = new ReadOptions();
+ // set snapshot in ReadOptions
+ readOptions.setSnapshot(snapshot);
+ // retrieve key value pair
+ assert(new String(db.get("key".getBytes()))
+ .equals("value"));
+ // retrieve key value pair created before
+ // the snapshot was made
+ assert(new String(db.get(readOptions,
+ "key".getBytes())).equals("value"));
+ // add new key/value pair
+ db.put("newkey".getBytes(), "newvalue".getBytes());
+ // using no snapshot the latest db entries
+ // will be taken into account
+ assert(new String(db.get("newkey".getBytes()))
+ .equals("newvalue"));
+ // snapshopot was created before newkey
+ assert(db.get(readOptions, "newkey".getBytes())
+ == null);
+ // Retrieve snapshot from read options
+ Snapshot sameSnapshot = readOptions.snapshot();
+ readOptions.setSnapshot(sameSnapshot);
+ // results must be the same with new Snapshot
+ // instance using the same native pointer
+ assert(new String(db.get(readOptions,
+ "key".getBytes())).equals("value"));
+ // update key value pair to newvalue
+ db.put("key".getBytes(), "newvalue".getBytes());
+ // read with previously created snapshot will
+ // read previous version of key value pair
+ assert(new String(db.get(readOptions,
+ "key".getBytes())).equals("value"));
+ // read for newkey using the snapshot must be
+ // null
+ assert(db.get(readOptions, "newkey".getBytes())
+ == null);
+ // setting null to snapshot in ReadOptions leads
+ // to no Snapshot being used.
+ readOptions.setSnapshot(null);
+ assert(new String(db.get(readOptions,
+ "newkey".getBytes())).equals("newvalue"));
+ // release Snapshot
+ db.releaseSnapshot(snapshot);
+ // Close database
+ db.close();
}
}
diff --git a/java/org/rocksdb/test/StatisticsCollectorTest.java b/java/org/rocksdb/test/StatisticsCollectorTest.java
index 5298aa46a..b748c21ce 100644
--- a/java/org/rocksdb/test/StatisticsCollectorTest.java
+++ b/java/org/rocksdb/test/StatisticsCollectorTest.java
@@ -6,20 +6,32 @@
package org.rocksdb.test;
import java.util.Collections;
+
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class StatisticsCollectorTest {
- static final String db_path = "/tmp/rocksdbjni_statistics_collector_test";
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args)
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @Test
+ public void shouldTestStatisticsCollector()
throws InterruptedException, RocksDBException {
Options opt = new Options().createStatistics().setCreateIfMissing(true);
Statistics stats = opt.statisticsPtr();
- RocksDB db = RocksDB.open(opt, db_path);
+ RocksDB db = RocksDB.open(opt,
+ dbFolder.getRoot().getAbsolutePath());
StatsCallbackMock callback = new StatsCallbackMock();
StatsCollectorInput statsInput = new StatsCollectorInput(stats, callback);
@@ -30,8 +42,8 @@ public class StatisticsCollectorTest {
Thread.sleep(1000);
- assert(callback.tickerCallbackCount > 0);
- assert(callback.histCallbackCount > 0);
+ assertThat(callback.tickerCallbackCount).isGreaterThan(0);
+ assertThat(callback.histCallbackCount).isGreaterThan(0);
statsCollector.shutDown(1000);
diff --git a/java/org/rocksdb/test/WriteBatchTest.java b/java/org/rocksdb/test/WriteBatchTest.java
new file mode 100644
index 000000000..72e0e464e
--- /dev/null
+++ b/java/org/rocksdb/test/WriteBatchTest.java
@@ -0,0 +1,130 @@
+// Copyright (c) 2014, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file. See the AUTHORS file for names of contributors.
+package org.rocksdb.test;
+
+import org.junit.AfterClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.rocksdb.WriteBatch;
+
+import java.io.UnsupportedEncodingException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * This class mimics the db/write_batch_test.cc
+ * in the c++ rocksdb library.
+ *
+ * Not ported yet:
+ *
+ * Continue();
+ * PutGatherSlices();
+ */
+public class WriteBatchTest {
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @AfterClass
+ public static void printMergePass(){
+ System.out.println("Passed WriteBatchTest.");
+ }
+
+ @Test
+ public void shouldTestEmptyWriteBatch() {
+ WriteBatch batch = new WriteBatch();
+ assertThat(batch.count()).isEqualTo(0);
+ }
+
+ @Test
+ public void shouldTestMultipleBatchOperations()
+ throws UnsupportedEncodingException {
+ WriteBatch batch = new WriteBatch();
+ batch.put("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
+ batch.remove("box".getBytes("US-ASCII"));
+ batch.put("baz".getBytes("US-ASCII"), "boo".getBytes("US-ASCII"));
+ WriteBatchInternal.setSequence(batch, 100);
+ assertThat(WriteBatchInternal.sequence(batch)).
+ isNotNull().
+ isEqualTo(100);
+ assertThat(batch.count()).isEqualTo(3);
+ assertThat(new String(getContents(batch), "US-ASCII")).
+ isEqualTo("Put(baz, boo)@102" +
+ "Delete(box)@101" +
+ "Put(foo, bar)@100");
+ }
+
+ @Test
+ public void shouldTestAppendOperation()
+ throws UnsupportedEncodingException {
+ WriteBatch b1 = new WriteBatch();
+ WriteBatch b2 = new WriteBatch();
+ WriteBatchInternal.setSequence(b1, 200);
+ WriteBatchInternal.setSequence(b2, 300);
+ WriteBatchInternal.append(b1, b2);
+ assertThat(getContents(b1).length).isEqualTo(0);
+ assertThat(b1.count()).isEqualTo(0);
+ b2.put("a".getBytes("US-ASCII"), "va".getBytes("US-ASCII"));
+ WriteBatchInternal.append(b1, b2);
+ assertThat("Put(a, va)@200".equals(new String(getContents(b1), "US-ASCII")));
+ assertThat(b1.count()).isEqualTo(1);
+ b2.clear();
+ b2.put("b".getBytes("US-ASCII"), "vb".getBytes("US-ASCII"));
+ WriteBatchInternal.append(b1, b2);
+ assertThat(("Put(a, va)@200" +
+ "Put(b, vb)@201")
+ .equals(new String(getContents(b1), "US-ASCII")));
+ assertThat(b1.count()).isEqualTo(2);
+ b2.remove("foo".getBytes("US-ASCII"));
+ WriteBatchInternal.append(b1, b2);
+ assertThat(("Put(a, va)@200" +
+ "Put(b, vb)@202" +
+ "Put(b, vb)@201" +
+ "Delete(foo)@203")
+ .equals(new String(getContents(b1), "US-ASCII")));
+ assertThat(b1.count()).isEqualTo(4);
+ }
+
+ @Test
+ public void shouldTestBlobOperation()
+ throws UnsupportedEncodingException {
+ WriteBatch batch = new WriteBatch();
+ batch.put("k1".getBytes("US-ASCII"), "v1".getBytes("US-ASCII"));
+ batch.put("k2".getBytes("US-ASCII"), "v2".getBytes("US-ASCII"));
+ batch.put("k3".getBytes("US-ASCII"), "v3".getBytes("US-ASCII"));
+ batch.putLogData("blob1".getBytes("US-ASCII"));
+ batch.remove("k2".getBytes("US-ASCII"));
+ batch.putLogData("blob2".getBytes("US-ASCII"));
+ batch.merge("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
+ assertThat(batch.count()).isEqualTo(5);
+ assertThat(("Merge(foo, bar)@4" +
+ "Put(k1, v1)@0" +
+ "Delete(k2)@3" +
+ "Put(k2, v2)@1" +
+ "Put(k3, v3)@2")
+ .equals(new String(getContents(batch), "US-ASCII")));
+ }
+
+ static native byte[] getContents(WriteBatch batch);
+}
+
+/**
+ * Package-private class which provides java api to access
+ * c++ WriteBatchInternal.
+ */
+class WriteBatchInternal {
+ static native void setSequence(WriteBatch batch, long sn);
+ static native long sequence(WriteBatch batch);
+ static native void append(WriteBatch b1, WriteBatch b2);
+}
diff --git a/java/rocksjni.pom b/java/rocksjni.pom
index 554357031..d8fe09fe9 100644
--- a/java/rocksjni.pom
+++ b/java/rocksjni.pom
@@ -1,34 +1,164 @@
-
- 4.0.0
- RocksDB JNI
- http://rocksdb.org/
- org.rocksdb
- rocksdbjni
- 3.6.0
- RocksDB fat jar that contains .so files for linux32 and linux64, and jnilib files for Mac OSX.
-
-
- Apache License 2.0
- http://www.apache.org/licenses/LICENSE-2.0.html
- repo
-
-
-
- scm:git:git://github.com/dropwizard/metrics.git
- scm:git:git@github.com:dropwizard/metrics.git
- http://github.com/dropwizard/metrics/
- HEAD
-
-
-
- Facebook
- help@facebook.com
- America/New_York
-
- architect
-
-
-
+
+ 4.0.0
+ RocksDB JNI
+ http://rocksdb.org/
+ org.rocksdb
+ rocksdbjni
+ 3.6.0
+ RocksDB fat jar that contains .so files for linux32 and linux64, and jnilib files
+ for Mac OSX.
+
+
+
+ Apache License 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.html
+ repo
+
+
+
+ scm:git:git://github.com/dropwizard/metrics.git
+ scm:git:git@github.com:dropwizard/metrics.git
+ http://github.com/dropwizard/metrics/
+ HEAD
+
+
+
+ Facebook
+ help@facebook.com
+ America/New_York
+
+ architect
+
+
+
+
+
+ UTF-8
+
+
+
+
+
+ ${project.basedir}
+
+
+
+ ${project.basedir}
+
+ **/*
+
+
+
+
+ ${project.basedir}
+
+
+
+ ${project.basedir}
+
+ *.so
+ *.jar
+ *.jnilib
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+
+ 1.7
+
+
+
+ *.java
+
+ org/rocksdb/benchmark/*.java
+
+ org/rocksdb/test/*.java
+ org/rocksdb/WriteBatchTest.java
+
+
+
+
+ default-testCompile
+ test-compile
+
+
+
+
+ %regex[org/rocksdb/[^WriteBatchTest].*java]
+
+ *.java
+
+ org/rocksdb/benchmark/*.java
+
+ org/rocksdb/util/*.java
+
+
+
+ org/rocksdb/test/*.java
+
+
+
+ testCompile
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.17
+
+ ${argLine}
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.7.1.201405082137
+
+
+
+ prepare-agent
+
+
+
+ report
+ prepare-package
+
+ report
+
+
+
+
+
+
+
+
+
+ junit
+ junit
+ 4.12-beta-2
+ test
+
+
+ org.assertj
+ assertj-core
+ 1.7.0
+ test
+
+
+ org.mockito
+ mockito-all
+ 1.9.5
+
+
diff --git a/java/rocksjni/write_batch.cc b/java/rocksjni/write_batch.cc
index f1d0a89d6..d243c87a0 100644
--- a/java/rocksjni/write_batch.cc
+++ b/java/rocksjni/write_batch.cc
@@ -9,8 +9,8 @@
#include "include/org_rocksdb_WriteBatch.h"
#include "include/org_rocksdb_WriteBatch_Handler.h"
-#include "include/org_rocksdb_WriteBatchInternal.h"
-#include "include/org_rocksdb_WriteBatchTest.h"
+#include "include/org_rocksdb_test_WriteBatchInternal.h"
+#include "include/org_rocksdb_test_WriteBatchTest.h"
#include "rocksjni/portal.h"
#include "rocksjni/writebatchhandlerjnicallback.h"
#include "rocksdb/db.h"
@@ -257,11 +257,11 @@ void Java_org_rocksdb_WriteBatch_disposeInternal(
}
/*
- * Class: org_rocksdb_WriteBatchInternal
+ * Class: org_rocksdb_test_WriteBatchInternal
* Method: setSequence
* Signature: (Lorg/rocksdb/WriteBatch;J)V
*/
-void Java_org_rocksdb_WriteBatchInternal_setSequence(
+void Java_org_rocksdb_test_WriteBatchInternal_setSequence(
JNIEnv* env, jclass jclazz, jobject jobj, jlong jsn) {
rocksdb::WriteBatch* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
assert(wb != nullptr);
@@ -271,11 +271,11 @@ void Java_org_rocksdb_WriteBatchInternal_setSequence(
}
/*
- * Class: org_rocksdb_WriteBatchInternal
+ * Class: org_rocksdb_test_WriteBatchInternal
* Method: sequence
* Signature: (Lorg/rocksdb/WriteBatch;)J
*/
-jlong Java_org_rocksdb_WriteBatchInternal_sequence(
+jlong Java_org_rocksdb_test_WriteBatchInternal_sequence(
JNIEnv* env, jclass jclazz, jobject jobj) {
rocksdb::WriteBatch* wb = rocksdb::WriteBatchJni::getHandle(env, jobj);
assert(wb != nullptr);
@@ -284,11 +284,11 @@ jlong Java_org_rocksdb_WriteBatchInternal_sequence(
}
/*
- * Class: org_rocksdb_WriteBatchInternal
+ * Class: org_rocksdb_test_WriteBatchInternal
* Method: append
* Signature: (Lorg/rocksdb/WriteBatch;Lorg/rocksdb/WriteBatch;)V
*/
-void Java_org_rocksdb_WriteBatchInternal_append(
+void Java_org_rocksdb_test_WriteBatchInternal_append(
JNIEnv* env, jclass jclazz, jobject jwb1, jobject jwb2) {
rocksdb::WriteBatch* wb1 = rocksdb::WriteBatchJni::getHandle(env, jwb1);
assert(wb1 != nullptr);
@@ -321,11 +321,11 @@ void Java_org_rocksdb_WriteBatch_00024Handler_disposeInternal(
}
/*
- * Class: org_rocksdb_WriteBatchTest
+ * Class: org_rocksdb_test_WriteBatchTest
* Method: getContents
* Signature: (Lorg/rocksdb/WriteBatch;)[B
*/
-jbyteArray Java_org_rocksdb_WriteBatchTest_getContents(
+jbyteArray Java_org_rocksdb_test_WriteBatchTest_getContents(
JNIEnv* env, jclass jclazz, jobject jobj) {
rocksdb::WriteBatch* b = rocksdb::WriteBatchJni::getHandle(env, jobj);
assert(b != nullptr);
From f617135d5fd148206da8399c64c236ccafb08017 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Sun, 2 Nov 2014 23:39:01 +0100
Subject: [PATCH 02/12] [RocksJava] Testcase improvements
---
java/org/rocksdb/ReadOptions.java | 1 -
.../test/BlockBasedTableConfigTest.java | 70 ++++++++++++----
.../rocksdb/test/PlainTableConfigTest.java | 7 +-
java/org/rocksdb/test/ReadOptionsTest.java | 83 +++++++++++++++++--
4 files changed, 137 insertions(+), 24 deletions(-)
diff --git a/java/org/rocksdb/ReadOptions.java b/java/org/rocksdb/ReadOptions.java
index aa6977e98..4a64f288b 100644
--- a/java/org/rocksdb/ReadOptions.java
+++ b/java/org/rocksdb/ReadOptions.java
@@ -155,7 +155,6 @@ public class ReadOptions extends RocksObject {
@Override protected void disposeInternal() {
- assert(isInitialized());
disposeInternal(nativeHandle_);
}
private native void disposeInternal(long handle);
diff --git a/java/org/rocksdb/test/BlockBasedTableConfigTest.java b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
index 8c73915ee..6e90f340a 100644
--- a/java/org/rocksdb/test/BlockBasedTableConfigTest.java
+++ b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
@@ -5,49 +5,85 @@
package org.rocksdb.test;
+import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
-import org.rocksdb.BlockBasedTableConfig;
-import org.rocksdb.ChecksumType;
-import org.rocksdb.IndexType;
+import org.rocksdb.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
public class BlockBasedTableConfigTest {
+
@ClassRule
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
+ @AfterClass
+ public static void printMessage(){
+ System.out.println("Passed BlockBasedTableConfigTst.");
+ }
+
@Test
public void shouldTestBlockBasedTableConfig() {
BlockBasedTableConfig blockBasedTableConfig =
new BlockBasedTableConfig();
blockBasedTableConfig.setNoBlockCache(true);
- assert(blockBasedTableConfig.noBlockCache());
- blockBasedTableConfig.setBlockCacheSize(8*1024);
- assert(blockBasedTableConfig.blockCacheSize() == (8*1024));
+ assertThat(blockBasedTableConfig.noBlockCache()).isTrue();
+ blockBasedTableConfig.setBlockCacheSize(8 * 1024);
+ assertThat(blockBasedTableConfig.blockCacheSize()).
+ isEqualTo(8 * 1024);
blockBasedTableConfig.setBlockSizeDeviation(12);
- assert(blockBasedTableConfig.blockSizeDeviation() == 12);
+ assertThat(blockBasedTableConfig.blockSizeDeviation()).
+ isEqualTo(12);
blockBasedTableConfig.setBlockRestartInterval(15);
- assert(blockBasedTableConfig.blockRestartInterval() == 15);
+ assertThat(blockBasedTableConfig.blockRestartInterval()).
+ isEqualTo(15);
blockBasedTableConfig.setWholeKeyFiltering(false);
- assert(!blockBasedTableConfig.wholeKeyFiltering());
+ assertThat(blockBasedTableConfig.wholeKeyFiltering()).
+ isFalse();
blockBasedTableConfig.setCacheIndexAndFilterBlocks(true);
- assert(blockBasedTableConfig.cacheIndexAndFilterBlocks());
+ assertThat(blockBasedTableConfig.cacheIndexAndFilterBlocks()).
+ isTrue();
blockBasedTableConfig.setHashIndexAllowCollision(false);
- assert(!blockBasedTableConfig.hashIndexAllowCollision());
+ assertThat(blockBasedTableConfig.hashIndexAllowCollision()).
+ isFalse();
blockBasedTableConfig.setBlockCacheCompressedSize(40);
- assert(blockBasedTableConfig.blockCacheCompressedSize() == 40);
+ assertThat(blockBasedTableConfig.blockCacheCompressedSize()).
+ isEqualTo(40);
blockBasedTableConfig.setChecksumType(ChecksumType.kNoChecksum);
blockBasedTableConfig.setChecksumType(ChecksumType.kxxHash);
- assert(blockBasedTableConfig.checksumType().equals(
+ assertThat(blockBasedTableConfig.checksumType().equals(
ChecksumType.kxxHash));
blockBasedTableConfig.setIndexType(IndexType.kHashSearch);
- assert(blockBasedTableConfig.indexType().equals(
+ assertThat(blockBasedTableConfig.indexType().equals(
IndexType.kHashSearch));
blockBasedTableConfig.setBlockCacheCompressedNumShardBits(4);
- assert(blockBasedTableConfig.blockCacheCompressedNumShardBits()
- == 4);
+ assertThat(blockBasedTableConfig.blockCacheCompressedNumShardBits()).
+ isEqualTo(4);
blockBasedTableConfig.setCacheNumShardBits(5);
- assert(blockBasedTableConfig.cacheNumShardBits() == 5);
+ assertThat(blockBasedTableConfig.cacheNumShardBits()).
+ isEqualTo(5);
+ blockBasedTableConfig.setBlockSize(10);
+ assertThat(blockBasedTableConfig.blockSize()).isEqualTo(10);
System.out.println("Passed BlockBasedTableConfigTest.");
}
+
+ @Test
+ public void shouldTestBlockBasedTableWithFilter() {
+ Options options = new Options();
+ options.setTableFormatConfig(
+ new BlockBasedTableConfig().setFilter(
+ new BloomFilter(10)));
+ assertThat(options.tableFactoryName()).
+ isEqualTo("BlockBasedTable");
+ }
+
+ @Test
+ public void shouldTestBlockBasedTableWithoutFilter() {
+ Options options = new Options();
+ options.setTableFormatConfig(
+ new BlockBasedTableConfig().setFilter(null));
+ assertThat(options.tableFactoryName()).
+ isEqualTo("BlockBasedTable");
+ }
}
diff --git a/java/org/rocksdb/test/PlainTableConfigTest.java b/java/org/rocksdb/test/PlainTableConfigTest.java
index f4cebb155..1891cd19a 100644
--- a/java/org/rocksdb/test/PlainTableConfigTest.java
+++ b/java/org/rocksdb/test/PlainTableConfigTest.java
@@ -5,6 +5,7 @@
package org.rocksdb.test;
+import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.EncodingType;
@@ -16,6 +17,11 @@ public class PlainTableConfigTest {
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
+ @AfterClass
+ public static void printMessage(){
+ System.out.println("Passed PlainTableConfigTest.");
+ }
+
@Test
public void shouldTestPlainTableConfig() {
PlainTableConfig plainTableConfig = new PlainTableConfig();
@@ -36,6 +42,5 @@ public class PlainTableConfigTest {
assert(plainTableConfig.fullScanMode());
plainTableConfig.setStoreIndexInFile(true);
assert(plainTableConfig.storeIndexInFile());
- System.out.println("Passed PlainTableConfigTest.");
}
}
diff --git a/java/org/rocksdb/test/ReadOptionsTest.java b/java/org/rocksdb/test/ReadOptionsTest.java
index 27d757a10..e00e143cf 100644
--- a/java/org/rocksdb/test/ReadOptionsTest.java
+++ b/java/org/rocksdb/test/ReadOptionsTest.java
@@ -7,17 +7,29 @@ package org.rocksdb.test;
import java.util.Random;
+import org.junit.AfterClass;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
-import org.rocksdb.RocksDB;
+import org.junit.rules.ExpectedException;
import org.rocksdb.ReadOptions;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class ReadOptionsTest {
@ClassRule
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @AfterClass
+ public static void printMessage(){
+ System.out.println("Passed ReadOptionsTest.");
+ }
+
@Test
public void shouldTestReadOptions() {
ReadOptions opt = new ReadOptions();
@@ -25,21 +37,82 @@ public class ReadOptionsTest {
{ // VerifyChecksums test
boolean boolValue = rand.nextBoolean();
opt.setVerifyChecksums(boolValue);
- assert(opt.verifyChecksums() == boolValue);
+ assertThat(opt.verifyChecksums()).isEqualTo(boolValue);
}
{ // FillCache test
boolean boolValue = rand.nextBoolean();
opt.setFillCache(boolValue);
- assert(opt.fillCache() == boolValue);
+ assertThat(opt.fillCache()).isEqualTo(boolValue);
}
{ // Tailing test
boolean boolValue = rand.nextBoolean();
opt.setTailing(boolValue);
- assert(opt.tailing() == boolValue);
+ assertThat(opt.tailing()).isEqualTo(boolValue);
+ }
+
+ { // Snapshot null test
+ opt.setSnapshot(null);
+ assertThat(opt.snapshot()).isNull();
}
opt.dispose();
- System.out.println("Passed ReadOptionsTest.");
+ }
+
+ @Test
+ public void shouldFailVerifyChecksumUninitialized(){
+ ReadOptions readOptions = setupUninitializedReadOptions(
+ exception);
+ readOptions.setVerifyChecksums(true);
+ }
+
+ @Test
+ public void shouldFailSetFillCacheUninitialized(){
+ ReadOptions readOptions = setupUninitializedReadOptions(
+ exception);
+ readOptions.setFillCache(true);
+ }
+
+ @Test
+ public void shouldFailFillCacheUninitialized(){
+ ReadOptions readOptions = setupUninitializedReadOptions(
+ exception);
+ readOptions.fillCache();
+ }
+
+ @Test
+ public void shouldFailSetTailingUninitialized(){
+ ReadOptions readOptions = setupUninitializedReadOptions(
+ exception);
+ readOptions.setTailing(true);
+ }
+
+ @Test
+ public void shouldFailTailingUninitialized(){
+ ReadOptions readOptions = setupUninitializedReadOptions(
+ exception);
+ readOptions.tailing();
+ }
+
+ @Test
+ public void shouldFailSetSnapshotUninitialized(){
+ ReadOptions readOptions = setupUninitializedReadOptions(
+ exception);
+ readOptions.setSnapshot(null);
+ }
+
+ @Test
+ public void shouldFailSnapshotUninitialized(){
+ ReadOptions readOptions = setupUninitializedReadOptions(
+ exception);
+ readOptions.snapshot();
+ }
+
+ private ReadOptions setupUninitializedReadOptions(
+ ExpectedException exception) {
+ ReadOptions readOptions = new ReadOptions();
+ readOptions.dispose();
+ exception.expect(AssertionError.class);
+ return readOptions;
}
}
From 9bec23c413ab3b2ab59aafc7d8664155b76fb018 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Mon, 3 Nov 2014 00:11:01 +0100
Subject: [PATCH 03/12] [RocksJava] Test-framework integration
Summary:
As we had the discussion some weeks ago. Java needs a test framework and should support code coverage analysis. This pull request includes:
Move Tests from main method functionality to Junit4
Move WriteBatchTest to test package
Adjust the Makefile to run Junit4
Download dependencies from Make (once if not-present)
Adjustment of the rocksjni.pom to run coverage analysis using jacoco
Javadoc excludes now tests
Two bugfixes regarding GC cleanup which came up within the test runs
Make can be used as beforehand to build and run RocksJava. make test runs tests using the command-line version of Junit4.
Maven can be used to retrieve code coverage reports using mvn -f rocksjni.pom package. Code coverage reports can then be found as usual in the site folder.
Testing libraries available within Java
Junit4 (incl. hamcrest-core dependency)
AssertJ (providing fluent syntax for assertions, cglib dependency)
Mockito to provide mocktests
Libraries as said before are not statically within this commit or filesystem instead they are downloaded using curl. Make checks if files are present, if so it will perform tests without downloading the libraries again.
Note: Libraries are only necessary to compile & run tests.
Next steps after merge:
Get the maven build into travis-ci and coveralls.io
Filling up the missing test spots (based on coverage data)
Test Plan:
make rocksdbjava
make jtest
Reviewers: yhchiang, ankgup87, adamretter
Subscribers: dhruba
Differential Revision: https://reviews.facebook.net/D28209
---
java/org/rocksdb/test/RocksMemoryResource.java | 2 +-
java/rocksjni.pom | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/java/org/rocksdb/test/RocksMemoryResource.java b/java/org/rocksdb/test/RocksMemoryResource.java
index eabbc822e..51164ad65 100644
--- a/java/org/rocksdb/test/RocksMemoryResource.java
+++ b/java/org/rocksdb/test/RocksMemoryResource.java
@@ -18,4 +18,4 @@ public class RocksMemoryResource extends ExternalResource {
System.gc();
System.runFinalization();
}
-}
\ No newline at end of file
+}
diff --git a/java/rocksjni.pom b/java/rocksjni.pom
index d8fe09fe9..2966a8a6b 100644
--- a/java/rocksjni.pom
+++ b/java/rocksjni.pom
@@ -123,7 +123,7 @@
org.jacoco
jacoco-maven-plugin
- 0.7.1.201405082137
+ 0.7.2.201409121644
From b092686959dffec61f5afff5c29b15215239dfb5 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Mon, 3 Nov 2014 09:59:52 +0100
Subject: [PATCH 04/12] [RocksJava] Extended testcases
+ 7% coverage + 3% branch coverage
---
java/Makefile | 1 +
.../test/BlockBasedTableConfigTest.java | 3 +-
java/org/rocksdb/test/ComparatorTest.java | 129 +++++++++++++++++-
java/org/rocksdb/test/WriteOptionsTest.java | 38 ++++++
4 files changed, 168 insertions(+), 3 deletions(-)
create mode 100644 java/org/rocksdb/test/WriteOptionsTest.java
diff --git a/java/Makefile b/java/Makefile
index d3bd8d8d4..d99821f05 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -71,6 +71,7 @@ JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
org.rocksdb.test.StatisticsCollectorTest\
org.rocksdb.test.WirteBatchHandlerTest\
org.rocksdb.test.WriteBatchTest\
+ org.rocksdb.test.WriteOptionsTest\
JAVA_TEST_LIBDIR = ./test-libs/
JAVA_JUNIT_JAR = $(JAVA_TEST_LIBDIR)junit-4.12-beta-2.jar
diff --git a/java/org/rocksdb/test/BlockBasedTableConfigTest.java b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
index 6e90f340a..0b1961569 100644
--- a/java/org/rocksdb/test/BlockBasedTableConfigTest.java
+++ b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
@@ -20,7 +20,7 @@ public class BlockBasedTableConfigTest {
@AfterClass
public static void printMessage(){
- System.out.println("Passed BlockBasedTableConfigTst.");
+ System.out.println("Passed BlockBasedTableConfigTest.");
}
@Test
@@ -65,7 +65,6 @@ public class BlockBasedTableConfigTest {
isEqualTo(5);
blockBasedTableConfig.setBlockSize(10);
assertThat(blockBasedTableConfig.blockSize()).isEqualTo(10);
- System.out.println("Passed BlockBasedTableConfigTest.");
}
@Test
diff --git a/java/org/rocksdb/test/ComparatorTest.java b/java/org/rocksdb/test/ComparatorTest.java
index d65a0653a..26523c719 100644
--- a/java/org/rocksdb/test/ComparatorTest.java
+++ b/java/org/rocksdb/test/ComparatorTest.java
@@ -5,6 +5,7 @@
package org.rocksdb.test;
+import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -14,6 +15,8 @@ import org.rocksdb.*;
import java.io.IOException;
import java.nio.file.FileSystems;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class ComparatorTest {
@ClassRule
@@ -23,6 +26,11 @@ public class ComparatorTest {
@Rule
public TemporaryFolder dbFolder = new TemporaryFolder();
+ @AfterClass
+ public static void printMessage(){
+ System.out.println("Passed ComparatorTest.");
+ }
+
@Test
public void shouldTestComparator() throws IOException {
@@ -47,7 +55,126 @@ public class ComparatorTest {
// test the round-tripability of keys written and read with the Comparator
comparatorTest.testRoundtrip(FileSystems.getDefault().getPath(
dbFolder.getRoot().getAbsolutePath()));
+ }
- System.out.println("Passed ComparatorTest");
+ @Test
+ public void shouldTestBuiltinForwardComparator()
+ throws RocksDBException {
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+ options.setComparator(BuiltinComparator.BYTEWISE_COMPARATOR);
+ RocksDB rocksDB = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+
+ rocksDB.put("abc1".getBytes(), "abc1".getBytes());
+ rocksDB.put("abc2".getBytes(), "abc2".getBytes());
+ rocksDB.put("abc3".getBytes(), "abc3".getBytes());
+
+ RocksIterator rocksIterator = rocksDB.newIterator();
+ // Iterate over keys using a iterator
+ rocksIterator.seekToFirst();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc1".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc1".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc2".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc2".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc3".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc3".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isFalse();
+ // Get last one
+ rocksIterator.seekToLast();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc3".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc3".getBytes());
+ // Seek for abc
+ rocksIterator.seek("abc".getBytes());
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc1".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc1".getBytes());
+ rocksIterator.dispose();
+ rocksDB.close();
+ options.dispose();
+ }
+
+ @Test
+ public void shouldTestBuiltinReverseComparator()
+ throws RocksDBException {
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+ options.setComparator(
+ BuiltinComparator.REVERSE_BYTEWISE_COMPARATOR);
+ RocksDB rocksDB = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+
+ rocksDB.put("abc1".getBytes(), "abc1".getBytes());
+ rocksDB.put("abc2".getBytes(), "abc2".getBytes());
+ rocksDB.put("abc3".getBytes(), "abc3".getBytes());
+
+ RocksIterator rocksIterator = rocksDB.newIterator();
+ // Iterate over keys using a iterator
+ rocksIterator.seekToFirst();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc3".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc3".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc2".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc2".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc1".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc1".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isFalse();
+ // Get last one
+ rocksIterator.seekToLast();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc1".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc1".getBytes());
+ // Will be invalid because abc is after abc1
+ rocksIterator.seek("abc".getBytes());
+ assertThat(rocksIterator.isValid()).isFalse();
+ // Will be abc3 because the next one after abc999
+ // is abc3
+ rocksIterator.seek("abc999".getBytes());
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc3".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc3".getBytes());
+ rocksIterator.dispose();
+ rocksDB.close();
+ options.dispose();
+ }
+
+ @Test
+ public void shouldTestBuiltinComparatorEnum(){
+ assertThat(BuiltinComparator.BYTEWISE_COMPARATOR.ordinal())
+ .isEqualTo(0);
+ assertThat(
+ BuiltinComparator.REVERSE_BYTEWISE_COMPARATOR.ordinal())
+ .isEqualTo(1);
}
}
diff --git a/java/org/rocksdb/test/WriteOptionsTest.java b/java/org/rocksdb/test/WriteOptionsTest.java
new file mode 100644
index 000000000..7a92bf9fa
--- /dev/null
+++ b/java/org/rocksdb/test/WriteOptionsTest.java
@@ -0,0 +1,38 @@
+// Copyright (c) 2014, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+
+package org.rocksdb.test;
+
+import org.junit.AfterClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.rocksdb.WriteOptions;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class WriteOptionsTest {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @AfterClass
+ public static void printMessage(){
+ System.out.println("Passed WriteOptionsTest.");
+ }
+
+ @Test
+ public void shouldTestWriteOptions(){
+ WriteOptions writeOptions = new WriteOptions();
+ writeOptions.setDisableWAL(true);
+ assertThat(writeOptions.disableWAL()).isTrue();
+ writeOptions.setDisableWAL(false);
+ assertThat(writeOptions.disableWAL()).isFalse();
+ writeOptions.setSync(true);
+ assertThat(writeOptions.sync()).isTrue();
+ writeOptions.setSync(false);
+ assertThat(writeOptions.sync()).isFalse();
+ }
+}
From 36f3a0bb8e19ddef1d5ae7e9c88bf9cc5b67cb47 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Wed, 5 Nov 2014 18:46:36 +0100
Subject: [PATCH 05/12] [RocksJava] Integrated review comments from adamretter
in D28209
---
java/Makefile | 2 +-
java/org/rocksdb/test/BackupableDBTest.java | 208 ++++++------
.../test/BlockBasedTableConfigTest.java | 12 +-
java/org/rocksdb/test/ColumnFamilyTest.java | 3 +-
.../rocksdb/test/ComparatorOptionsTest.java | 3 +-
java/org/rocksdb/test/ComparatorTest.java | 14 +-
java/org/rocksdb/test/DBOptionsTest.java | 162 ++++++----
.../rocksdb/test/DirectComparatorTest.java | 4 +-
java/org/rocksdb/test/FilterTest.java | 10 +-
java/org/rocksdb/test/KeyMayExistTest.java | 118 +++----
java/org/rocksdb/test/MemTableTest.java | 79 +++--
java/org/rocksdb/test/MergeTest.java | 32 +-
java/org/rocksdb/test/OptionsTest.java | 289 ++++++++++++++++-
.../rocksdb/test/PlainTableConfigTest.java | 34 +-
java/org/rocksdb/test/ReadOnlyTest.java | 295 ++++++++++++------
java/org/rocksdb/test/ReadOptionsTest.java | 22 +-
java/org/rocksdb/test/RocksIteratorTest.java | 3 +-
java/org/rocksdb/test/RocksJunitRunner.java | 65 ++++
java/org/rocksdb/test/SnapshotTest.java | 36 ++-
.../rocksdb/test/StatisticsCollectorTest.java | 4 +-
java/org/rocksdb/test/WriteBatchTest.java | 14 +-
java/org/rocksdb/test/WriteOptionsTest.java | 8 +-
java/rocksjni.pom | 1 +
23 files changed, 925 insertions(+), 493 deletions(-)
create mode 100644 java/org/rocksdb/test/RocksJunitRunner.java
diff --git a/java/Makefile b/java/Makefile
index d99821f05..83bf34afc 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -120,7 +120,7 @@ resolve_test_deps:
test: java resolve_test_deps
javac -cp $(JAVA_TESTCLASSPATH) org/rocksdb/test/*.java
- java -ea -Djava.library.path=.:../ -cp "$(JAVA_TESTCLASSPATH)" org.junit.runner.JUnitCore $(JAVA_TESTS)
+ java -ea -Djava.library.path=.:../ -cp "$(JAVA_TESTCLASSPATH)" org.rocksdb.test.RocksJunitRunner $(JAVA_TESTS)
db_bench: java
javac org/rocksdb/benchmark/*.java
diff --git a/java/org/rocksdb/test/BackupableDBTest.java b/java/org/rocksdb/test/BackupableDBTest.java
index f0a6708c1..aa6c07c14 100644
--- a/java/org/rocksdb/test/BackupableDBTest.java
+++ b/java/org/rocksdb/test/BackupableDBTest.java
@@ -13,6 +13,8 @@ import org.rocksdb.*;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class BackupableDBTest {
@ClassRule
@@ -26,7 +28,7 @@ public class BackupableDBTest {
public TemporaryFolder backupFolder = new TemporaryFolder();
@Test
- public void shouldTestBackupableDb() {
+ public void backupableDb() throws RocksDBException {
Options opt = new Options();
opt.setCreateIfMissing(true);
@@ -34,108 +36,110 @@ public class BackupableDBTest {
BackupableDBOptions bopt = new BackupableDBOptions(
backupFolder.getRoot().getAbsolutePath(), false,
true, false, true, 0, 0);
- BackupableDB bdb = null;
+ BackupableDB bdb;
List backupInfos;
List restoreInfos;
- try {
- bdb = BackupableDB.open(opt, bopt,
- dbFolder.getRoot().getAbsolutePath());
-
- bdb.put("abc".getBytes(), "def".getBytes());
- bdb.put("ghi".getBytes(), "jkl".getBytes());
-
- backupInfos = bdb.getBackupInfos();
- assert(backupInfos.size() == 0);
-
- bdb.createNewBackup(true);
-
- backupInfos = bdb.getBackupInfos();
- assert(backupInfos.size() == 1);
-
- // Retrieving backup infos twice shall not
- // lead to different results
- List tmpBackupInfo = bdb.getBackupInfos();
- assert(tmpBackupInfo.get(0).backupId() ==
- backupInfos.get(0).backupId());
- assert(tmpBackupInfo.get(0).timestamp() ==
- backupInfos.get(0).timestamp());
- assert(tmpBackupInfo.get(0).size() ==
- backupInfos.get(0).size());
- assert(tmpBackupInfo.get(0).numberFiles() ==
- backupInfos.get(0).numberFiles());
-
- // delete record after backup
- bdb.remove("abc".getBytes());
- byte[] value = bdb.get("abc".getBytes());
- assert(value == null);
- bdb.close();
-
- // restore from backup
- RestoreOptions ropt = new RestoreOptions(false);
- RestoreBackupableDB rdb = new RestoreBackupableDB(bopt);
-
- // getting backup infos from restorable db should
- // lead to the same infos as from backupable db
- restoreInfos = rdb.getBackupInfos();
- assert(restoreInfos.size() == backupInfos.size());
- assert(restoreInfos.get(0).backupId() ==
- backupInfos.get(0).backupId());
- assert(restoreInfos.get(0).timestamp() ==
- backupInfos.get(0).timestamp());
- assert(restoreInfos.get(0).size() ==
- backupInfos.get(0).size());
- assert(restoreInfos.get(0).numberFiles() ==
- backupInfos.get(0).numberFiles());
-
- rdb.restoreDBFromLatestBackup(
- dbFolder.getRoot().getAbsolutePath(),
- dbFolder.getRoot().getAbsolutePath(),
- ropt);
- // do nothing because there is only one backup
- rdb.purgeOldBackups(1);
- restoreInfos = rdb.getBackupInfos();
- assert(restoreInfos.size() == 1);
- rdb.dispose();
- ropt.dispose();
-
- // verify that backed up data contains deleted record
- bdb = BackupableDB.open(opt, bopt,
- dbFolder.getRoot().getAbsolutePath());
- value = bdb.get("abc".getBytes());
- assert(new String(value).equals("def"));
-
- bdb.createNewBackup(false);
- // after new backup there must be two backup infos
- backupInfos = bdb.getBackupInfos();
- assert(backupInfos.size() == 2);
- // deleting the backup must be possible using the
- // id provided by backup infos
- bdb.deleteBackup(backupInfos.get(1).backupId());
- // after deletion there should only be one info
- backupInfos = bdb.getBackupInfos();
- assert(backupInfos.size() == 1);
- bdb.createNewBackup(false);
- bdb.createNewBackup(false);
- bdb.createNewBackup(false);
- backupInfos = bdb.getBackupInfos();
- assert(backupInfos.size() == 4);
- // purge everything and keep two
- bdb.purgeOldBackups(2);
- // backup infos need to be two
- backupInfos = bdb.getBackupInfos();
- assert(backupInfos.size() == 2);
- assert(backupInfos.get(0).backupId() == 4);
- assert(backupInfos.get(1).backupId() == 5);
- } catch (RocksDBException e) {
- System.err.format("[ERROR]: %s%n", e);
- e.printStackTrace();
- } finally {
- opt.dispose();
- bopt.dispose();
- if (bdb != null) {
- bdb.close();
- }
- }
- System.out.println("Passed BackupableDBTest.");
+
+ bdb = BackupableDB.open(opt, bopt,
+ dbFolder.getRoot().getAbsolutePath());
+ bdb.put("abc".getBytes(), "def".getBytes());
+ bdb.put("ghi".getBytes(), "jkl".getBytes());
+
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(0);
+
+ bdb.createNewBackup(true);
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(1);
+
+ // Retrieving backup infos twice shall not
+ // lead to different results
+ List tmpBackupInfo = bdb.getBackupInfos();
+ assertThat(tmpBackupInfo.get(0).backupId()).
+ isEqualTo(backupInfos.get(0).backupId());
+ assertThat(tmpBackupInfo.get(0).timestamp()).
+ isEqualTo(backupInfos.get(0).timestamp());
+ assertThat(tmpBackupInfo.get(0).size()).
+ isEqualTo(backupInfos.get(0).size());
+ assertThat(tmpBackupInfo.get(0).numberFiles()).
+ isEqualTo(backupInfos.get(0).numberFiles());
+
+ // delete record after backup
+ bdb.remove("abc".getBytes());
+ byte[] value = bdb.get("abc".getBytes());
+ assertThat(value).isNull();
+ bdb.close();
+
+ // restore from backup
+ RestoreOptions ropt = new RestoreOptions(false);
+ RestoreBackupableDB rdb = new RestoreBackupableDB(bopt);
+
+ // getting backup infos from restorable db should
+ // lead to the same infos as from backupable db
+ restoreInfos = rdb.getBackupInfos();
+ assertThat(restoreInfos.size()).
+ isEqualTo(backupInfos.size());
+ assertThat(restoreInfos.get(0).backupId()).
+ isEqualTo(backupInfos.get(0).backupId());
+ assertThat(restoreInfos.get(0).timestamp()).
+ isEqualTo(backupInfos.get(0).timestamp());
+ assertThat(restoreInfos.get(0).size()).
+ isEqualTo(backupInfos.get(0).size());
+ assertThat(restoreInfos.get(0).numberFiles()).
+ isEqualTo(backupInfos.get(0).numberFiles());
+
+ rdb.restoreDBFromLatestBackup(
+ dbFolder.getRoot().getAbsolutePath(),
+ dbFolder.getRoot().getAbsolutePath(),
+ ropt);
+ // do nothing because there is only one backup
+ rdb.purgeOldBackups(1);
+ restoreInfos = rdb.getBackupInfos();
+ assertThat(restoreInfos.size()).
+ isEqualTo(1);
+ rdb.dispose();
+ ropt.dispose();
+
+ // verify that backed up data contains deleted record
+ bdb = BackupableDB.open(opt, bopt,
+ dbFolder.getRoot().getAbsolutePath());
+ value = bdb.get("abc".getBytes());
+ assertThat(new String(value)).
+ isEqualTo("def");
+
+ bdb.createNewBackup(false);
+ // after new backup there must be two backup infos
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(2);
+ // deleting the backup must be possible using the
+ // id provided by backup infos
+ bdb.deleteBackup(backupInfos.get(1).backupId());
+ // after deletion there should only be one info
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(1);
+ bdb.createNewBackup(false);
+ bdb.createNewBackup(false);
+ bdb.createNewBackup(false);
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(4);
+ // purge everything and keep two
+ bdb.purgeOldBackups(2);
+ // backup infos need to be two
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(2);
+ assertThat(backupInfos.get(0).backupId()).
+ isEqualTo(4);
+ assertThat(backupInfos.get(1).backupId()).
+ isEqualTo(5);
+
+ opt.dispose();
+ bopt.dispose();
+ bdb.close();
}
}
diff --git a/java/org/rocksdb/test/BlockBasedTableConfigTest.java b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
index 0b1961569..143a3fa14 100644
--- a/java/org/rocksdb/test/BlockBasedTableConfigTest.java
+++ b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
@@ -5,7 +5,6 @@
package org.rocksdb.test;
-import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.*;
@@ -18,13 +17,8 @@ public class BlockBasedTableConfigTest {
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
- @AfterClass
- public static void printMessage(){
- System.out.println("Passed BlockBasedTableConfigTest.");
- }
-
@Test
- public void shouldTestBlockBasedTableConfig() {
+ public void blockBasedTableConfig() {
BlockBasedTableConfig blockBasedTableConfig =
new BlockBasedTableConfig();
blockBasedTableConfig.setNoBlockCache(true);
@@ -68,7 +62,7 @@ public class BlockBasedTableConfigTest {
}
@Test
- public void shouldTestBlockBasedTableWithFilter() {
+ public void blockBasedTableWithFilter() {
Options options = new Options();
options.setTableFormatConfig(
new BlockBasedTableConfig().setFilter(
@@ -78,7 +72,7 @@ public class BlockBasedTableConfigTest {
}
@Test
- public void shouldTestBlockBasedTableWithoutFilter() {
+ public void blockBasedTableWithoutFilter() {
Options options = new Options();
options.setTableFormatConfig(
new BlockBasedTableConfig().setFilter(null));
diff --git a/java/org/rocksdb/test/ColumnFamilyTest.java b/java/org/rocksdb/test/ColumnFamilyTest.java
index e52eac589..fc5b4ba6e 100644
--- a/java/org/rocksdb/test/ColumnFamilyTest.java
+++ b/java/org/rocksdb/test/ColumnFamilyTest.java
@@ -26,7 +26,7 @@ public class ColumnFamilyTest {
public TemporaryFolder dbFolder = new TemporaryFolder();
@Test
- public void shouldTestColumnFamilies() {
+ public void columnFamilies() {
String db_path = dbFolder.getRoot().getAbsolutePath();
RocksDB db = null;
Options options = new Options();
@@ -291,6 +291,5 @@ public class ColumnFamilyTest {
db.close();
// be sure to dispose c++ pointers
options.dispose();
- System.out.println("Passed ColumnFamilyTest.");
}
}
diff --git a/java/org/rocksdb/test/ComparatorOptionsTest.java b/java/org/rocksdb/test/ComparatorOptionsTest.java
index 21f4fc2a1..1064910df 100644
--- a/java/org/rocksdb/test/ComparatorOptionsTest.java
+++ b/java/org/rocksdb/test/ComparatorOptionsTest.java
@@ -18,7 +18,7 @@ public class ComparatorOptionsTest {
new RocksMemoryResource();
@Test
- public void shouldTestComparatorOptions() {
+ public void comparatorOptions() {
final ComparatorOptions copt = new ComparatorOptions();
assertThat(copt).isNotNull();
@@ -32,6 +32,5 @@ public class ComparatorOptionsTest {
}
copt.dispose();
- System.out.println("Passed ComparatorOptionsTest");
}
}
diff --git a/java/org/rocksdb/test/ComparatorTest.java b/java/org/rocksdb/test/ComparatorTest.java
index 26523c719..c9037954e 100644
--- a/java/org/rocksdb/test/ComparatorTest.java
+++ b/java/org/rocksdb/test/ComparatorTest.java
@@ -5,7 +5,6 @@
package org.rocksdb.test;
-import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -26,13 +25,8 @@ public class ComparatorTest {
@Rule
public TemporaryFolder dbFolder = new TemporaryFolder();
- @AfterClass
- public static void printMessage(){
- System.out.println("Passed ComparatorTest.");
- }
-
@Test
- public void shouldTestComparator() throws IOException {
+ public void javaComparator() throws IOException {
final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() {
@Override
@@ -58,7 +52,7 @@ public class ComparatorTest {
}
@Test
- public void shouldTestBuiltinForwardComparator()
+ public void builtinForwardComparator()
throws RocksDBException {
Options options = new Options();
options.setCreateIfMissing(true);
@@ -112,7 +106,7 @@ public class ComparatorTest {
}
@Test
- public void shouldTestBuiltinReverseComparator()
+ public void builtinReverseComparator()
throws RocksDBException {
Options options = new Options();
options.setCreateIfMissing(true);
@@ -170,7 +164,7 @@ public class ComparatorTest {
}
@Test
- public void shouldTestBuiltinComparatorEnum(){
+ public void builtinComparatorEnum(){
assertThat(BuiltinComparator.BYTEWISE_COMPARATOR.ordinal())
.isEqualTo(0);
assertThat(
diff --git a/java/org/rocksdb/test/DBOptionsTest.java b/java/org/rocksdb/test/DBOptionsTest.java
index 0cd2468ea..529a9b09b 100644
--- a/java/org/rocksdb/test/DBOptionsTest.java
+++ b/java/org/rocksdb/test/DBOptionsTest.java
@@ -5,224 +5,252 @@
package org.rocksdb.test;
-import org.rocksdb.DBOptions;
-import org.rocksdb.DBOptionsInterface;
-import org.rocksdb.RocksDB;
-import org.rocksdb.RocksDBException;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.rocksdb.*;
import java.util.Random;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class DBOptionsTest {
- static {
- RocksDB.loadLibrary();
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Test
+ public void dbOptions() throws RocksDBException {
+ testDBOptions(new DBOptions());
}
- public static void testDBOptions(DBOptionsInterface opt) {
+ static void testDBOptions(DBOptionsInterface opt) throws RocksDBException {
Random rand = PlatformRandomHelper.
getPlatformSpecificRandomFactory();
{ // CreateIfMissing test
boolean boolValue = rand.nextBoolean();
opt.setCreateIfMissing(boolValue);
- assert(opt.createIfMissing() == boolValue);
+ assertThat(opt.createIfMissing()).
+ isEqualTo(boolValue);
}
{ // CreateMissingColumnFamilies test
boolean boolValue = rand.nextBoolean();
opt.setCreateMissingColumnFamilies(boolValue);
- assert(opt.createMissingColumnFamilies() == boolValue);
+ assertThat(opt.createMissingColumnFamilies()).
+ isEqualTo(boolValue);
}
{ // ErrorIfExists test
boolean boolValue = rand.nextBoolean();
opt.setErrorIfExists(boolValue);
- assert(opt.errorIfExists() == boolValue);
+ assertThat(opt.errorIfExists()).isEqualTo(boolValue);
}
{ // ParanoidChecks test
boolean boolValue = rand.nextBoolean();
opt.setParanoidChecks(boolValue);
- assert(opt.paranoidChecks() == boolValue);
+ assertThat(opt.paranoidChecks()).
+ isEqualTo(boolValue);
}
{
// MaxTotalWalSize test
long longValue = rand.nextLong();
opt.setMaxTotalWalSize(longValue);
- assert(opt.maxTotalWalSize() == longValue);
+ assertThat(opt.maxTotalWalSize()).
+ isEqualTo(longValue);
}
{ // MaxOpenFiles test
int intValue = rand.nextInt();
opt.setMaxOpenFiles(intValue);
- assert(opt.maxOpenFiles() == intValue);
+ assertThat(opt.maxOpenFiles()).isEqualTo(intValue);
}
{ // DisableDataSync test
boolean boolValue = rand.nextBoolean();
opt.setDisableDataSync(boolValue);
- assert(opt.disableDataSync() == boolValue);
+ assertThat(opt.disableDataSync()).
+ isEqualTo(boolValue);
}
{ // UseFsync test
boolean boolValue = rand.nextBoolean();
opt.setUseFsync(boolValue);
- assert(opt.useFsync() == boolValue);
+ assertThat(opt.useFsync()).isEqualTo(boolValue);
}
{ // DbLogDir test
String str = "path/to/DbLogDir";
opt.setDbLogDir(str);
- assert(opt.dbLogDir().equals(str));
+ assertThat(opt.dbLogDir()).isEqualTo(str);
}
{ // WalDir test
String str = "path/to/WalDir";
opt.setWalDir(str);
- assert(opt.walDir().equals(str));
+ assertThat(opt.walDir()).isEqualTo(str);
}
{ // DeleteObsoleteFilesPeriodMicros test
long longValue = rand.nextLong();
opt.setDeleteObsoleteFilesPeriodMicros(longValue);
- assert(opt.deleteObsoleteFilesPeriodMicros() == longValue);
+ assertThat(opt.deleteObsoleteFilesPeriodMicros()).
+ isEqualTo(longValue);
}
{ // MaxBackgroundCompactions test
int intValue = rand.nextInt();
opt.setMaxBackgroundCompactions(intValue);
- assert(opt.maxBackgroundCompactions() == intValue);
+ assertThat(opt.maxBackgroundCompactions()).
+ isEqualTo(intValue);
}
{ // MaxBackgroundFlushes test
int intValue = rand.nextInt();
opt.setMaxBackgroundFlushes(intValue);
- assert(opt.maxBackgroundFlushes() == intValue);
+ assertThat(opt.maxBackgroundFlushes()).
+ isEqualTo(intValue);
}
{ // MaxLogFileSize test
- try {
- long longValue = rand.nextLong();
- opt.setMaxLogFileSize(longValue);
- assert(opt.maxLogFileSize() == longValue);
- } catch (RocksDBException e) {
- System.out.println(e.getMessage());
- assert(false);
- }
+ long longValue = rand.nextLong();
+ opt.setMaxLogFileSize(longValue);
+ assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
}
{ // LogFileTimeToRoll test
- try {
- long longValue = rand.nextLong();
- opt.setLogFileTimeToRoll(longValue);
- assert(opt.logFileTimeToRoll() == longValue);
- } catch (RocksDBException e) {
- assert(false);
- }
+ long longValue = rand.nextLong();
+ opt.setLogFileTimeToRoll(longValue);
+ assertThat(opt.logFileTimeToRoll()).
+ isEqualTo(longValue);
}
{ // KeepLogFileNum test
- try {
- long longValue = rand.nextLong();
- opt.setKeepLogFileNum(longValue);
- assert(opt.keepLogFileNum() == longValue);
- } catch (RocksDBException e) {
- assert(false);
- }
+ long longValue = rand.nextLong();
+ opt.setKeepLogFileNum(longValue);
+ assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
}
{ // MaxManifestFileSize test
long longValue = rand.nextLong();
opt.setMaxManifestFileSize(longValue);
- assert(opt.maxManifestFileSize() == longValue);
+ assertThat(opt.maxManifestFileSize()).
+ isEqualTo(longValue);
}
{ // TableCacheNumshardbits test
int intValue = rand.nextInt();
opt.setTableCacheNumshardbits(intValue);
- assert(opt.tableCacheNumshardbits() == intValue);
+ assertThat(opt.tableCacheNumshardbits()).
+ isEqualTo(intValue);
}
{ // TableCacheRemoveScanCountLimit test
int intValue = rand.nextInt();
opt.setTableCacheRemoveScanCountLimit(intValue);
- assert(opt.tableCacheRemoveScanCountLimit() == intValue);
+ assertThat(opt.tableCacheRemoveScanCountLimit()).
+ isEqualTo(intValue);
+ }
+
+ { // WalSizeLimitMB test
+ long longValue = rand.nextLong();
+ opt.setWalSizeLimitMB(longValue);
+ assertThat(opt.walSizeLimitMB()).isEqualTo(longValue);
}
{ // WalTtlSeconds test
long longValue = rand.nextLong();
opt.setWalTtlSeconds(longValue);
- assert(opt.walTtlSeconds() == longValue);
+ assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
}
{ // ManifestPreallocationSize test
- try {
- long longValue = rand.nextLong();
- opt.setManifestPreallocationSize(longValue);
- assert(opt.manifestPreallocationSize() == longValue);
- } catch (RocksDBException e) {
- assert(false);
- }
+ long longValue = rand.nextLong();
+ opt.setManifestPreallocationSize(longValue);
+ assertThat(opt.manifestPreallocationSize()).
+ isEqualTo(longValue);
}
{ // AllowOsBuffer test
boolean boolValue = rand.nextBoolean();
opt.setAllowOsBuffer(boolValue);
- assert(opt.allowOsBuffer() == boolValue);
+ assertThat(opt.allowOsBuffer()).isEqualTo(boolValue);
}
{ // AllowMmapReads test
boolean boolValue = rand.nextBoolean();
opt.setAllowMmapReads(boolValue);
- assert(opt.allowMmapReads() == boolValue);
+ assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
}
{ // AllowMmapWrites test
boolean boolValue = rand.nextBoolean();
opt.setAllowMmapWrites(boolValue);
- assert(opt.allowMmapWrites() == boolValue);
+ assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
}
{ // IsFdCloseOnExec test
boolean boolValue = rand.nextBoolean();
opt.setIsFdCloseOnExec(boolValue);
- assert(opt.isFdCloseOnExec() == boolValue);
+ assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
}
{ // SkipLogErrorOnRecovery test
boolean boolValue = rand.nextBoolean();
opt.setSkipLogErrorOnRecovery(boolValue);
- assert(opt.skipLogErrorOnRecovery() == boolValue);
+ assertThat(opt.skipLogErrorOnRecovery()).isEqualTo(boolValue);
}
{ // StatsDumpPeriodSec test
int intValue = rand.nextInt();
opt.setStatsDumpPeriodSec(intValue);
- assert(opt.statsDumpPeriodSec() == intValue);
+ assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
}
{ // AdviseRandomOnOpen test
boolean boolValue = rand.nextBoolean();
opt.setAdviseRandomOnOpen(boolValue);
- assert(opt.adviseRandomOnOpen() == boolValue);
+ assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
}
{ // UseAdaptiveMutex test
boolean boolValue = rand.nextBoolean();
opt.setUseAdaptiveMutex(boolValue);
- assert(opt.useAdaptiveMutex() == boolValue);
+ assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
}
{ // BytesPerSync test
long longValue = rand.nextLong();
opt.setBytesPerSync(longValue);
- assert(opt.bytesPerSync() == longValue);
+ assertThat(opt.bytesPerSync()).isEqualTo(longValue);
}
}
- public static void main(String[] args) {
- DBOptions opt = new DBOptions();
- testDBOptions(opt);
- opt.dispose();
- System.out.println("Passed DBOptionsTest");
+ @Test
+ public void rateLimiterConfig() {
+ DBOptions options = new DBOptions();
+ RateLimiterConfig rateLimiterConfig =
+ new GenericRateLimiterConfig(1000, 0, 1);
+ options.setRateLimiterConfig(rateLimiterConfig);
+ options.dispose();
+ // Test with parameter initialization
+ DBOptions anotherOptions = new DBOptions();
+ anotherOptions.setRateLimiterConfig(
+ new GenericRateLimiterConfig(1000));
+ anotherOptions.dispose();
+ }
+
+ @Test
+ public void statistics() {
+ DBOptions options = new DBOptions();
+ Statistics statistics = options.createStatistics().
+ statisticsPtr();
+ assertThat(statistics).isNotNull();
+
+ DBOptions anotherOptions = new DBOptions();
+ statistics = anotherOptions.statisticsPtr();
+ assertThat(statistics).isNotNull();
}
}
diff --git a/java/org/rocksdb/test/DirectComparatorTest.java b/java/org/rocksdb/test/DirectComparatorTest.java
index 562038897..f09d94843 100644
--- a/java/org/rocksdb/test/DirectComparatorTest.java
+++ b/java/org/rocksdb/test/DirectComparatorTest.java
@@ -23,7 +23,7 @@ public class DirectComparatorTest {
public TemporaryFolder dbFolder = new TemporaryFolder();
@Test
- public void shouldTestDirectComparator() throws IOException {
+ public void directComparator() throws IOException {
final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() {
@Override
@@ -49,7 +49,5 @@ public class DirectComparatorTest {
// test the round-tripability of keys written and read with the DirectComparator
comparatorTest.testRoundtrip(FileSystems.getDefault().getPath(
dbFolder.getRoot().getAbsolutePath()));
-
- System.out.println("Passed DirectComparatorTest");
}
}
diff --git a/java/org/rocksdb/test/FilterTest.java b/java/org/rocksdb/test/FilterTest.java
index 3894167b0..c183f8d95 100644
--- a/java/org/rocksdb/test/FilterTest.java
+++ b/java/org/rocksdb/test/FilterTest.java
@@ -16,10 +16,9 @@ public class FilterTest {
new RocksMemoryResource();
@Test
- public void shouldTestFilter() {
+ public void filter() {
Options options = new Options();
// test table config
- BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
options.setTableFormatConfig(new BlockBasedTableConfig().
setFilter(new BloomFilter()));
options.dispose();
@@ -27,7 +26,7 @@ public class FilterTest {
System.runFinalization();
// new Bloom filter
options = new Options();
- blockConfig = new BlockBasedTableConfig();
+ BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
blockConfig.setFilter(new BloomFilter());
options.setTableFormatConfig(blockConfig);
BloomFilter bloomFilter = new BloomFilter(10);
@@ -38,10 +37,5 @@ public class FilterTest {
blockConfig.setFilter(new BloomFilter(10, false));
options.setTableFormatConfig(blockConfig);
options.dispose();
- options = null;
- blockConfig = null;
- System.gc();
- System.runFinalization();
- System.out.println("Passed FilterTest.");
}
}
diff --git a/java/org/rocksdb/test/KeyMayExistTest.java b/java/org/rocksdb/test/KeyMayExistTest.java
index 03be46fbe..5f6d6225a 100644
--- a/java/org/rocksdb/test/KeyMayExistTest.java
+++ b/java/org/rocksdb/test/KeyMayExistTest.java
@@ -4,73 +4,79 @@
// of patent rights can be found in the PATENTS file in the same directory.
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
import java.util.ArrayList;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class KeyMayExistTest {
- static final String DB_PATH = "/tmp/rocksdbjni_keymayexit_test";
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args){
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @Test
+ public void keyMayExist() throws RocksDBException {
RocksDB db;
DBOptions options = new DBOptions();
options.setCreateIfMissing(true)
.setCreateMissingColumnFamilies(true);
- try {
- // open database using cf names
- List cfNames =
- new ArrayList();
- List columnFamilyHandleList =
- new ArrayList();
- cfNames.add(new ColumnFamilyDescriptor("default"));
- cfNames.add(new ColumnFamilyDescriptor("new_cf"));
- db = RocksDB.open(options, DB_PATH, cfNames, columnFamilyHandleList);
- assert(columnFamilyHandleList.size()==2);
+ // open database using cf names
+ List cfDescriptors =
+ new ArrayList();
+ List columnFamilyHandleList =
+ new ArrayList<>();
+ cfDescriptors.add(new ColumnFamilyDescriptor("default"));
+ cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath(),
+ cfDescriptors, columnFamilyHandleList);
+ assertThat(columnFamilyHandleList.size()).
+ isEqualTo(2);
+ db.put("key".getBytes(), "value".getBytes());
+ // Test without column family
+ StringBuffer retValue = new StringBuffer();
+ boolean exists = db.keyMayExist("key".getBytes(), retValue);
+ assertThat(exists).isTrue();
+ assertThat(retValue.toString()).
+ isEqualTo("value");
+
+ // Test without column family but with readOptions
+ retValue = new StringBuffer();
+ exists = db.keyMayExist(new ReadOptions(), "key".getBytes(),
+ retValue);
+ assertThat(exists).isTrue();
+ assertThat(retValue.toString()).
+ isEqualTo("value");
+
+ // Test with column family
+ retValue = new StringBuffer();
+ exists = db.keyMayExist(columnFamilyHandleList.get(0), "key".getBytes(),
+ retValue);
+ assertThat(exists).isTrue();
+ assertThat(retValue.toString()).
+ isEqualTo("value");
+
+ // Test with column family and readOptions
+ retValue = new StringBuffer();
+ exists = db.keyMayExist(new ReadOptions(),
+ columnFamilyHandleList.get(0), "key".getBytes(),
+ retValue);
+ assertThat(exists).isTrue();
+ assertThat(retValue.toString()).
+ isEqualTo("value");
- db.put("key".getBytes(), "value".getBytes());
- // Test without column family
- StringBuffer retValue = new StringBuffer();
- if (db.keyMayExist("key".getBytes(), retValue)) {
- assert(retValue.toString().equals("value"));
- } else {
- assert(false);
- }
- // Test without column family but with readOptions
- retValue = new StringBuffer();
- if (db.keyMayExist(new ReadOptions(), "key".getBytes(),
- retValue)) {
- assert(retValue.toString().equals("value"));
- } else {
- assert(false);
- }
- // Test with column family
- retValue = new StringBuffer();
- if (db.keyMayExist(columnFamilyHandleList.get(0), "key".getBytes(),
- retValue)) {
- assert(retValue.toString().equals("value"));
- } else {
- assert(false);
- }
- // Test with column family and readOptions
- retValue = new StringBuffer();
- if (db.keyMayExist(new ReadOptions(),
- columnFamilyHandleList.get(0), "key".getBytes(),
- retValue)) {
- assert(retValue.toString().equals("value"));
- } else {
- assert(false);
- }
- // KeyMayExist in CF1 must return false
- assert(db.keyMayExist(columnFamilyHandleList.get(1), "key".getBytes(),
- retValue) == false);
- System.out.println("Passed KeyMayExistTest");
- }catch (RocksDBException e){
- e.printStackTrace();
- assert(false);
- }
+ // KeyMayExist in CF1 must return false
+ assertThat(db.keyMayExist(columnFamilyHandleList.get(1),
+ "key".getBytes(), retValue)).isFalse();
}
}
diff --git a/java/org/rocksdb/test/MemTableTest.java b/java/org/rocksdb/test/MemTableTest.java
index 0b1244fc2..93146303a 100644
--- a/java/org/rocksdb/test/MemTableTest.java
+++ b/java/org/rocksdb/test/MemTableTest.java
@@ -9,6 +9,8 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.*;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class MemTableTest {
@ClassRule
@@ -16,22 +18,27 @@ public class MemTableTest {
new RocksMemoryResource();
@Test
- public void shouldTestMemTable() throws RocksDBException {
+ public void memTable() throws RocksDBException {
Options options = new Options();
// Test HashSkipListMemTableConfig
HashSkipListMemTableConfig memTableConfig =
new HashSkipListMemTableConfig();
- assert(memTableConfig.bucketCount() == 1000000);
+ assertThat(memTableConfig.bucketCount()).
+ isEqualTo(1000000);
memTableConfig.setBucketCount(2000000);
- assert(memTableConfig.bucketCount() == 2000000);
- assert(memTableConfig.height() == 4);
+ assertThat(memTableConfig.bucketCount()).
+ isEqualTo(2000000);
+ assertThat(memTableConfig.height()).
+ isEqualTo(4);
memTableConfig.setHeight(5);
- assert(memTableConfig.height() == 5);
- assert(memTableConfig.branchingFactor() == 4);
+ assertThat(memTableConfig.height()).
+ isEqualTo(5);
+ assertThat(memTableConfig.branchingFactor()).
+ isEqualTo(4);
memTableConfig.setBranchingFactor(6);
- assert(memTableConfig.branchingFactor() == 6);
+ assertThat(memTableConfig.branchingFactor()).
+ isEqualTo(6);
options.setMemTableConfig(memTableConfig);
- memTableConfig = null;
options.dispose();
System.gc();
System.runFinalization();
@@ -39,11 +46,12 @@ public class MemTableTest {
options = new Options();
SkipListMemTableConfig skipMemTableConfig =
new SkipListMemTableConfig();
- assert(skipMemTableConfig.lookahead() == 0);
+ assertThat(skipMemTableConfig.lookahead()).
+ isEqualTo(0);
skipMemTableConfig.setLookahead(20);
- assert(skipMemTableConfig.lookahead() == 20);
+ assertThat(skipMemTableConfig.lookahead()).
+ isEqualTo(20);
options.setMemTableConfig(skipMemTableConfig);
- skipMemTableConfig = null;
options.dispose();
System.gc();
System.runFinalization();
@@ -51,31 +59,38 @@ public class MemTableTest {
options = new Options();
HashLinkedListMemTableConfig hashLinkedListMemTableConfig =
new HashLinkedListMemTableConfig();
- assert(hashLinkedListMemTableConfig.bucketCount() == 50000);
+ assertThat(hashLinkedListMemTableConfig.bucketCount()).
+ isEqualTo(50000);
hashLinkedListMemTableConfig.setBucketCount(100000);
- assert(hashLinkedListMemTableConfig.bucketCount() == 100000);
- assert(hashLinkedListMemTableConfig.hugePageTlbSize() == 0);
+ assertThat(hashLinkedListMemTableConfig.bucketCount()).
+ isEqualTo(100000);
+ assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
+ isEqualTo(0);
hashLinkedListMemTableConfig.setHugePageTlbSize(1);
- assert(hashLinkedListMemTableConfig.hugePageTlbSize() == 1);
- assert(hashLinkedListMemTableConfig.
- bucketEntriesLoggingThreshold() == 4096);
+ assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
+ isEqualTo(1);
+ assertThat(hashLinkedListMemTableConfig.
+ bucketEntriesLoggingThreshold()).
+ isEqualTo(4096);
hashLinkedListMemTableConfig.
setBucketEntriesLoggingThreshold(200);
- assert(hashLinkedListMemTableConfig.
- bucketEntriesLoggingThreshold() == 200);
- assert(hashLinkedListMemTableConfig.
- ifLogBucketDistWhenFlush());
+ assertThat(hashLinkedListMemTableConfig.
+ bucketEntriesLoggingThreshold()).
+ isEqualTo(200);
+ assertThat(hashLinkedListMemTableConfig.
+ ifLogBucketDistWhenFlush()).isTrue();
hashLinkedListMemTableConfig.
setIfLogBucketDistWhenFlush(false);
- assert(!hashLinkedListMemTableConfig.
- ifLogBucketDistWhenFlush());
- assert(hashLinkedListMemTableConfig.
- thresholdUseSkiplist() == 256);
+ assertThat(hashLinkedListMemTableConfig.
+ ifLogBucketDistWhenFlush()).isFalse();
+ assertThat(hashLinkedListMemTableConfig.
+ thresholdUseSkiplist()).
+ isEqualTo(256);
hashLinkedListMemTableConfig.setThresholdUseSkiplist(29);
- assert(hashLinkedListMemTableConfig.
- thresholdUseSkiplist() == 29);
+ assertThat(hashLinkedListMemTableConfig.
+ thresholdUseSkiplist()).
+ isEqualTo(29);
options.setMemTableConfig(hashLinkedListMemTableConfig);
- hashLinkedListMemTableConfig = null;
options.dispose();
System.gc();
System.runFinalization();
@@ -83,14 +98,14 @@ public class MemTableTest {
options = new Options();
VectorMemTableConfig vectorMemTableConfig =
new VectorMemTableConfig();
- assert(vectorMemTableConfig.reservedSize() == 0);
+ assertThat(vectorMemTableConfig.reservedSize()).
+ isEqualTo(0);
vectorMemTableConfig.setReservedSize(123);
- assert(vectorMemTableConfig.reservedSize() == 123);
+ assertThat(vectorMemTableConfig.reservedSize()).
+ isEqualTo(123);
options.setMemTableConfig(vectorMemTableConfig);
- vectorMemTableConfig = null;
options.dispose();
System.gc();
System.runFinalization();
- System.out.println("Passed MemTableTest.");
}
}
diff --git a/java/org/rocksdb/test/MergeTest.java b/java/org/rocksdb/test/MergeTest.java
index 31a3fe5cb..f1e2fb759 100644
--- a/java/org/rocksdb/test/MergeTest.java
+++ b/java/org/rocksdb/test/MergeTest.java
@@ -8,13 +8,14 @@ package org.rocksdb.test;
import java.util.List;
import java.util.ArrayList;
-import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class MergeTest {
@ClassRule
@@ -24,13 +25,8 @@ public class MergeTest {
@Rule
public TemporaryFolder dbFolder = new TemporaryFolder();
- @AfterClass
- public static void printMergePass(){
- System.out.println("Passed MergeTest.");
- }
-
@Test
- public void shouldTestStringOption()
+ public void stringOption()
throws InterruptedException, RocksDBException {
String db_path_string =
dbFolder.getRoot().getAbsolutePath();
@@ -49,11 +45,11 @@ public class MergeTest {
db.close();
opt.dispose();
- assert(strValue.equals("aa,bb"));
+ assertThat(strValue).isEqualTo("aa,bb");
}
@Test
- public void shouldTestCFStringOption()
+ public void cFStringOption()
throws InterruptedException, RocksDBException {
DBOptions opt = new DBOptions();
String db_path_string =
@@ -89,11 +85,11 @@ public class MergeTest {
}
db.close();
opt.dispose();
- assert(strValue.equals("aa,bb"));
+ assertThat(strValue).isEqualTo("aa,bb");
}
@Test
- public void shouldTestOperatorOption()
+ public void operatorOption()
throws InterruptedException, RocksDBException {
String db_path_string =
dbFolder.getRoot().getAbsolutePath();
@@ -115,11 +111,11 @@ public class MergeTest {
db.close();
opt.dispose();
- assert(strValue.equals("aa,bb"));
+ assertThat(strValue).isEqualTo("aa,bb");
}
@Test
- public void shouldTestCFOperatorOption()
+ public void cFOperatorOption()
throws InterruptedException, RocksDBException {
DBOptions opt = new DBOptions();
String db_path_string =
@@ -165,12 +161,12 @@ public class MergeTest {
columnFamilyHandle.dispose();
db.close();
opt.dispose();
- assert(strValue.equals("aa,bb"));
- assert(strValueTmpCf.equals("xx,yy"));
+ assertThat(strValue).isEqualTo("aa,bb");
+ assertThat(strValueTmpCf).isEqualTo("xx,yy");
}
@Test
- public void shouldTestOperatorGcBehaviour()
+ public void operatorGcBehaviour()
throws RocksDBException {
String db_path_string =
dbFolder.getRoot().getAbsolutePath();
@@ -207,9 +203,5 @@ public class MergeTest {
db = RocksDB.open(opt, db_path_string);
db.close();
opt.dispose();
- stringAppendOperator = null;
- newStringAppendOperator = null;
- System.gc();
- System.runFinalization();
}
}
diff --git a/java/org/rocksdb/test/OptionsTest.java b/java/org/rocksdb/test/OptionsTest.java
index defdcc304..f8fbd7bcc 100644
--- a/java/org/rocksdb/test/OptionsTest.java
+++ b/java/org/rocksdb/test/OptionsTest.java
@@ -6,23 +6,296 @@
package org.rocksdb.test;
import java.util.Random;
-import org.rocksdb.RocksDB;
-import org.rocksdb.Options;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.rocksdb.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
public class OptionsTest {
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args) {
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Test
+ public void options() throws RocksDBException {
Options opt = new Options();
Random rand = PlatformRandomHelper.
getPlatformSpecificRandomFactory();
DBOptionsTest.testDBOptions(opt);
- ColumnFamilyOptionsTest.testCFOptions(opt);
+
+ { // WriteBufferSize test
+ long longValue = rand.nextLong();
+ opt.setWriteBufferSize(longValue);
+ assert(opt.writeBufferSize() == longValue);
+ }
+
+ { // MaxWriteBufferNumber test
+ int intValue = rand.nextInt();
+ opt.setMaxWriteBufferNumber(intValue);
+ assert(opt.maxWriteBufferNumber() == intValue);
+ }
+
+ { // MinWriteBufferNumberToMerge test
+ int intValue = rand.nextInt();
+ opt.setMinWriteBufferNumberToMerge(intValue);
+ assert(opt.minWriteBufferNumberToMerge() == intValue);
+ }
+
+ { // NumLevels test
+ int intValue = rand.nextInt();
+ opt.setNumLevels(intValue);
+ assert(opt.numLevels() == intValue);
+ }
+
+ { // LevelFileNumCompactionTrigger test
+ int intValue = rand.nextInt();
+ opt.setLevelZeroFileNumCompactionTrigger(intValue);
+ assert(opt.levelZeroFileNumCompactionTrigger() == intValue);
+ }
+
+ { // LevelSlowdownWritesTrigger test
+ int intValue = rand.nextInt();
+ opt.setLevelZeroSlowdownWritesTrigger(intValue);
+ assert(opt.levelZeroSlowdownWritesTrigger() == intValue);
+ }
+
+ { // LevelStopWritesTrigger test
+ int intValue = rand.nextInt();
+ opt.setLevelZeroStopWritesTrigger(intValue);
+ assert(opt.levelZeroStopWritesTrigger() == intValue);
+ }
+
+ { // MaxMemCompactionLevel test
+ int intValue = rand.nextInt();
+ opt.setMaxMemCompactionLevel(intValue);
+ assert(opt.maxMemCompactionLevel() == intValue);
+ }
+
+ { // TargetFileSizeBase test
+ long longValue = rand.nextLong();
+ opt.setTargetFileSizeBase(longValue);
+ assert(opt.targetFileSizeBase() == longValue);
+ }
+
+ { // TargetFileSizeMultiplier test
+ int intValue = rand.nextInt();
+ opt.setTargetFileSizeMultiplier(intValue);
+ assert(opt.targetFileSizeMultiplier() == intValue);
+ }
+
+ { // MaxBytesForLevelBase test
+ long longValue = rand.nextLong();
+ opt.setMaxBytesForLevelBase(longValue);
+ assert(opt.maxBytesForLevelBase() == longValue);
+ }
+
+ { // MaxBytesForLevelMultiplier test
+ int intValue = rand.nextInt();
+ opt.setMaxBytesForLevelMultiplier(intValue);
+ assert(opt.maxBytesForLevelMultiplier() == intValue);
+ }
+
+ { // ExpandedCompactionFactor test
+ int intValue = rand.nextInt();
+ opt.setExpandedCompactionFactor(intValue);
+ assert(opt.expandedCompactionFactor() == intValue);
+ }
+
+ { // SourceCompactionFactor test
+ int intValue = rand.nextInt();
+ opt.setSourceCompactionFactor(intValue);
+ assert(opt.sourceCompactionFactor() == intValue);
+ }
+
+ { // MaxGrandparentOverlapFactor test
+ int intValue = rand.nextInt();
+ opt.setMaxGrandparentOverlapFactor(intValue);
+ assert(opt.maxGrandparentOverlapFactor() == intValue);
+ }
+
+ { // SoftRateLimit test
+ double doubleValue = rand.nextDouble();
+ opt.setSoftRateLimit(doubleValue);
+ assert(opt.softRateLimit() == doubleValue);
+ }
+
+ { // HardRateLimit test
+ double doubleValue = rand.nextDouble();
+ opt.setHardRateLimit(doubleValue);
+ assert(opt.hardRateLimit() == doubleValue);
+ }
+
+ { // RateLimitDelayMaxMilliseconds test
+ int intValue = rand.nextInt();
+ opt.setRateLimitDelayMaxMilliseconds(intValue);
+ assert(opt.rateLimitDelayMaxMilliseconds() == intValue);
+ }
+
+ { // ArenaBlockSize test
+ long longValue = rand.nextLong();
+ opt.setArenaBlockSize(longValue);
+ assert(opt.arenaBlockSize() == longValue);
+ }
+
+ { // DisableAutoCompactions test
+ boolean boolValue = rand.nextBoolean();
+ opt.setDisableAutoCompactions(boolValue);
+ assert(opt.disableAutoCompactions() == boolValue);
+ }
+
+ { // PurgeRedundantKvsWhileFlush test
+ boolean boolValue = rand.nextBoolean();
+ opt.setPurgeRedundantKvsWhileFlush(boolValue);
+ assert(opt.purgeRedundantKvsWhileFlush() == boolValue);
+ }
+
+ { // VerifyChecksumsInCompaction test
+ boolean boolValue = rand.nextBoolean();
+ opt.setVerifyChecksumsInCompaction(boolValue);
+ assert(opt.verifyChecksumsInCompaction() == boolValue);
+ }
+
+ { // FilterDeletes test
+ boolean boolValue = rand.nextBoolean();
+ opt.setFilterDeletes(boolValue);
+ assert(opt.filterDeletes() == boolValue);
+ }
+
+ { // MaxSequentialSkipInIterations test
+ long longValue = rand.nextLong();
+ opt.setMaxSequentialSkipInIterations(longValue);
+ assert(opt.maxSequentialSkipInIterations() == longValue);
+ }
+
+ { // InplaceUpdateSupport test
+ boolean boolValue = rand.nextBoolean();
+ opt.setInplaceUpdateSupport(boolValue);
+ assert(opt.inplaceUpdateSupport() == boolValue);
+ }
+
+ { // InplaceUpdateNumLocks test
+ long longValue = rand.nextLong();
+ opt.setInplaceUpdateNumLocks(longValue);
+ assert(opt.inplaceUpdateNumLocks() == longValue);
+ }
+
+ { // MemtablePrefixBloomBits test
+ int intValue = rand.nextInt();
+ opt.setMemtablePrefixBloomBits(intValue);
+ assert(opt.memtablePrefixBloomBits() == intValue);
+ }
+
+ { // MemtablePrefixBloomProbes test
+ int intValue = rand.nextInt();
+ opt.setMemtablePrefixBloomProbes(intValue);
+ assert(opt.memtablePrefixBloomProbes() == intValue);
+ }
+
+ { // BloomLocality test
+ int intValue = rand.nextInt();
+ opt.setBloomLocality(intValue);
+ assert(opt.bloomLocality() == intValue);
+ }
+
+ { // MaxSuccessiveMerges test
+ long longValue = rand.nextLong();
+ opt.setMaxSuccessiveMerges(longValue);
+ assert(opt.maxSuccessiveMerges() == longValue);
+ }
+
+ { // MinPartialMergeOperands test
+ int intValue = rand.nextInt();
+ opt.setMinPartialMergeOperands(intValue);
+ assert(opt.minPartialMergeOperands() == intValue);
+ }
opt.dispose();
- System.out.println("Passed OptionsTest");
+ }
+
+ @Test
+ public void linkageOfPrepMethods() {
+ Options options = new Options();
+ options.optimizeUniversalStyleCompaction();
+ options.optimizeUniversalStyleCompaction(4000);
+ options.optimizeLevelStyleCompaction();
+ options.optimizeLevelStyleCompaction(3000);
+ options.optimizeForPointLookup(10);
+ options.prepareForBulkLoad();
+ }
+
+ @Test
+ public void compressionTypes() {
+ Options options = new Options();
+ for(CompressionType compressionType :
+ CompressionType.values()) {
+ options.setCompressionType(compressionType);
+ assertThat(options.compressionType()).
+ isEqualTo(compressionType);
+ }
+ options.dispose();
+ }
+
+ @Test
+ public void compactionStyles() {
+ Options options = new Options();
+ for (CompactionStyle compactionStyle :
+ CompactionStyle.values()) {
+ options.setCompactionStyle(compactionStyle);
+ assertThat(options.compactionStyle()).
+ isEqualTo(compactionStyle);
+ }
+ options.dispose();
+ }
+
+ @Test
+ public void rateLimiterConfig() {
+ Options options = new Options();
+ RateLimiterConfig rateLimiterConfig =
+ new GenericRateLimiterConfig(1000, 0, 1);
+ options.setRateLimiterConfig(rateLimiterConfig);
+ options.dispose();
+ // Test with parameter initialization
+ Options anotherOptions = new Options();
+ anotherOptions.setRateLimiterConfig(
+ new GenericRateLimiterConfig(1000));
+ anotherOptions.dispose();
+ }
+
+ @Test
+ public void shouldSetTestPrefixExtractor() {
+ Options options = new Options();
+ options.useFixedLengthPrefixExtractor(100);
+ options.useFixedLengthPrefixExtractor(10);
+ options.dispose();
+ }
+
+ @Test
+ public void shouldTestMemTableFactoryName()
+ throws RocksDBException {
+ Options options = new Options();
+ options.setMemTableConfig(new VectorMemTableConfig());
+ assertThat(options.memTableFactoryName()).
+ isEqualTo("VectorRepFactory");
+ options.setMemTableConfig(
+ new HashLinkedListMemTableConfig());
+ assertThat(options.memTableFactoryName()).
+ isEqualTo("HashLinkedListRepFactory");
+ options.dispose();
+ }
+
+ @Test
+ public void statistics() {
+ Options options = new Options();
+ Statistics statistics = options.createStatistics().
+ statisticsPtr();
+ assertThat(statistics).isNotNull();
+
+ Options anotherOptions = new Options();
+ statistics = anotherOptions.statisticsPtr();
+ assertThat(statistics).isNotNull();
}
}
diff --git a/java/org/rocksdb/test/PlainTableConfigTest.java b/java/org/rocksdb/test/PlainTableConfigTest.java
index 1891cd19a..abd2cda12 100644
--- a/java/org/rocksdb/test/PlainTableConfigTest.java
+++ b/java/org/rocksdb/test/PlainTableConfigTest.java
@@ -5,42 +5,44 @@
package org.rocksdb.test;
-import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.EncodingType;
import org.rocksdb.PlainTableConfig;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class PlainTableConfigTest {
@ClassRule
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
- @AfterClass
- public static void printMessage(){
- System.out.println("Passed PlainTableConfigTest.");
- }
-
@Test
- public void shouldTestPlainTableConfig() {
+ public void plainTableConfig() {
PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setKeySize(5);
- assert(plainTableConfig.keySize() == 5);
+ assertThat(plainTableConfig.keySize()).
+ isEqualTo(5);
plainTableConfig.setBloomBitsPerKey(11);
- assert(plainTableConfig.bloomBitsPerKey() == 11);
+ assertThat(plainTableConfig.bloomBitsPerKey()).
+ isEqualTo(11);
plainTableConfig.setHashTableRatio(0.95);
- assert(plainTableConfig.hashTableRatio() == 0.95);
+ assertThat(plainTableConfig.hashTableRatio()).
+ isEqualTo(0.95);
plainTableConfig.setIndexSparseness(18);
- assert(plainTableConfig.indexSparseness() == 18);
+ assertThat(plainTableConfig.indexSparseness()).
+ isEqualTo(18);
plainTableConfig.setHugePageTlbSize(1);
- assert(plainTableConfig.hugePageTlbSize() == 1);
+ assertThat(plainTableConfig.hugePageTlbSize()).
+ isEqualTo(1);
plainTableConfig.setEncodingType(EncodingType.kPrefix);
- assert(plainTableConfig.encodingType().equals(
- EncodingType.kPrefix));
+ assertThat(plainTableConfig.encodingType()).isEqualTo(
+ EncodingType.kPrefix);
plainTableConfig.setFullScanMode(true);
- assert(plainTableConfig.fullScanMode());
+ assertThat(plainTableConfig.fullScanMode()).isTrue();
plainTableConfig.setStoreIndexInFile(true);
- assert(plainTableConfig.storeIndexInFile());
+ assertThat(plainTableConfig.storeIndexInFile()).
+ isTrue();
}
}
diff --git a/java/org/rocksdb/test/ReadOnlyTest.java b/java/org/rocksdb/test/ReadOnlyTest.java
index 057d2d4b8..1151f93dc 100644
--- a/java/org/rocksdb/test/ReadOnlyTest.java
+++ b/java/org/rocksdb/test/ReadOnlyTest.java
@@ -13,6 +13,8 @@ import org.rocksdb.*;
import java.util.ArrayList;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class ReadOnlyTest {
@ClassRule
@@ -23,119 +25,204 @@ public class ReadOnlyTest {
public TemporaryFolder dbFolder = new TemporaryFolder();
@Test
- public void shouldTestReadOnlyOpen() {
- RocksDB db = null, db2 = null, db3 = null;
+ public void readOnlyOpen() throws RocksDBException {
+ RocksDB db, db2, db3;
List columnFamilyHandleList =
new ArrayList<>();
- List db2ColumnFamilyHandleList =
+ List readOnlyColumnFamilyHandleList =
+ new ArrayList<>();
+ List readOnlyColumnFamilyHandleList2 =
new ArrayList<>();
- List db3ColumnFamilyHandleList =
+
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.put("key".getBytes(), "value".getBytes());
+ db2 = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath());
+ assertThat("value").
+ isEqualTo(new String(db2.get("key".getBytes())));
+ db.close();
+ db2.close();
+
+ List cfDescriptors = new ArrayList<>();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+
+ db = RocksDB.open(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors, columnFamilyHandleList);
+ columnFamilyHandleList.add(db.createColumnFamily(
+ new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
+ columnFamilyHandleList.add(db.createColumnFamily(
+ new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions())));
+ db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
+ "value2".getBytes());
+
+ db2 = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+ assertThat(db2.get("key2".getBytes())).isNull();
+ assertThat(db2.get(readOnlyColumnFamilyHandleList.get(0), "key2".getBytes())).
+ isNull();
+
+ cfDescriptors.clear();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions()));
+ db3 = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList2);
+ assertThat(new String(db3.get(readOnlyColumnFamilyHandleList2.get(1),
+ "key2".getBytes()))).isEqualTo("value2");
+ db.close();
+ db2.close();
+ db3.close();
+ options.dispose();
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failToWriteInReadOnly() throws RocksDBException {
+ List cfDescriptors = new ArrayList<>();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+ List readOnlyColumnFamilyHandleList =
new ArrayList<>();
Options options = new Options();
options.setCreateIfMissing(true);
- try {
- db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.put("key".getBytes(), "value".getBytes());
- db2 = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath());
- assert("value".equals(new String(db2.get("key".getBytes()))));
- db.close();
- db2.close();
-
-
- List cfNames =
- new ArrayList();
- cfNames.add(new ColumnFamilyDescriptor("default"));
-
- db = RocksDB.open(dbFolder.getRoot().getAbsolutePath(), cfNames, columnFamilyHandleList);
- columnFamilyHandleList.add(db.createColumnFamily(
- new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
- columnFamilyHandleList.add(db.createColumnFamily(
- new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions())));
- db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
- "value2".getBytes());
-
- db2 = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfNames, db2ColumnFamilyHandleList);
- assert(db2.get("key2".getBytes())==null);
- assert(db2.get(columnFamilyHandleList.get(0), "key2".getBytes())==null);
-
- List cfNewName =
- new ArrayList<>();
- cfNewName.add(new ColumnFamilyDescriptor("default"));
- cfNewName.add(new ColumnFamilyDescriptor("new_cf2"));
- db3 = RocksDB.openReadOnly(dbFolder.getRoot().getAbsolutePath(), cfNewName, db3ColumnFamilyHandleList);
- assert(new String(db3.get(db3ColumnFamilyHandleList.get(1),
- "key2".getBytes())).equals("value2"));
- }catch (RocksDBException e){
- e.printStackTrace();
- assert(false);
- }
+
+ RocksDB db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+ RocksDB rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
// test that put fails in readonly mode
- try {
- db2.put("key".getBytes(), "value".getBytes());
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
- }
- try {
- db3.put(db3ColumnFamilyHandleList.get(1),
- "key".getBytes(), "value".getBytes());
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
- }
- // test that remove fails in readonly mode
- try {
- db2.remove("key".getBytes());
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
- }
- try {
- db3.remove(db3ColumnFamilyHandleList.get(1),
- "key".getBytes());
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
- }
- // test that write fails in readonly mode
+ rDb.put("key".getBytes(), "value".getBytes());
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failToCFWriteInReadOnly() throws RocksDBException {
+ List cfDescriptors = new ArrayList<>();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+ List readOnlyColumnFamilyHandleList =
+ new ArrayList<>();
+
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ RocksDB db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+ RocksDB rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ rDb.put(readOnlyColumnFamilyHandleList.get(0),
+ "key".getBytes(), "value".getBytes());
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failToRemoveInReadOnly() throws RocksDBException {
+ List cfDescriptors = new ArrayList<>();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+ List readOnlyColumnFamilyHandleList =
+ new ArrayList<>();
+
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ RocksDB db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+ RocksDB rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ rDb.remove("key".getBytes());
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failToCFRemoveInReadOnly() throws RocksDBException {
+ List cfDescriptors = new ArrayList<>();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+ List readOnlyColumnFamilyHandleList =
+ new ArrayList<>();
+
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ RocksDB db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+
+ RocksDB rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ rDb.remove(readOnlyColumnFamilyHandleList.get(0),
+ "key".getBytes());
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failToWriteBatchReadOnly() throws RocksDBException {
+ List cfDescriptors = new ArrayList<>();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+ List readOnlyColumnFamilyHandleList =
+ new ArrayList<>();
+
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ RocksDB db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+
+ RocksDB rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
WriteBatch wb = new WriteBatch();
wb.put("key".getBytes(), "value".getBytes());
- try {
- db2.write(new WriteOptions(), wb);
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
- }
- wb.dispose();
- wb = new WriteBatch();
- wb.put(db3ColumnFamilyHandleList.get(1),
- "key".getBytes(), "value".getBytes());
- try {
- db3.write(new WriteOptions(), wb);
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
- }
- wb.dispose();
- // cleanup c++ pointers
- for (ColumnFamilyHandle columnFamilyHandle :
- columnFamilyHandleList) {
- columnFamilyHandle.dispose();
- }
+ rDb.write(new WriteOptions(), wb);
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failToCFWriteBatchReadOnly() throws RocksDBException {
+ List cfDescriptors = new ArrayList<>();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+ List readOnlyColumnFamilyHandleList =
+ new ArrayList<>();
+
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ RocksDB db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
db.close();
- for (ColumnFamilyHandle columnFamilyHandle :
- db2ColumnFamilyHandleList) {
- columnFamilyHandle.dispose();
- }
- db2.close();
- for (ColumnFamilyHandle columnFamilyHandle :
- db3ColumnFamilyHandleList) {
- columnFamilyHandle.dispose();
- }
- db3.close();
- System.out.println("Passed ReadOnlyTest.");
+
+ RocksDB rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ WriteBatch wb = new WriteBatch();
+ wb.put(readOnlyColumnFamilyHandleList.get(0),
+ "key".getBytes(), "value".getBytes());
+ rDb.write(new WriteOptions(), wb);
}
}
diff --git a/java/org/rocksdb/test/ReadOptionsTest.java b/java/org/rocksdb/test/ReadOptionsTest.java
index e00e143cf..5b58fe5e9 100644
--- a/java/org/rocksdb/test/ReadOptionsTest.java
+++ b/java/org/rocksdb/test/ReadOptionsTest.java
@@ -7,7 +7,6 @@ package org.rocksdb.test;
import java.util.Random;
-import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -25,13 +24,8 @@ public class ReadOptionsTest {
@Rule
public ExpectedException exception = ExpectedException.none();
- @AfterClass
- public static void printMessage(){
- System.out.println("Passed ReadOptionsTest.");
- }
-
@Test
- public void shouldTestReadOptions() {
+ public void readOptions() {
ReadOptions opt = new ReadOptions();
Random rand = new Random();
{ // VerifyChecksums test
@@ -60,49 +54,49 @@ public class ReadOptionsTest {
}
@Test
- public void shouldFailVerifyChecksumUninitialized(){
+ public void failVerifyChecksumUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setVerifyChecksums(true);
}
@Test
- public void shouldFailSetFillCacheUninitialized(){
+ public void failSetFillCacheUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setFillCache(true);
}
@Test
- public void shouldFailFillCacheUninitialized(){
+ public void failFillCacheUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.fillCache();
}
@Test
- public void shouldFailSetTailingUninitialized(){
+ public void failSetTailingUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setTailing(true);
}
@Test
- public void shouldFailTailingUninitialized(){
+ public void failTailingUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.tailing();
}
@Test
- public void shouldFailSetSnapshotUninitialized(){
+ public void failSetSnapshotUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setSnapshot(null);
}
@Test
- public void shouldFailSnapshotUninitialized(){
+ public void failSnapshotUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.snapshot();
diff --git a/java/org/rocksdb/test/RocksIteratorTest.java b/java/org/rocksdb/test/RocksIteratorTest.java
index 7de27cad9..d2dae63aa 100644
--- a/java/org/rocksdb/test/RocksIteratorTest.java
+++ b/java/org/rocksdb/test/RocksIteratorTest.java
@@ -23,7 +23,7 @@ public class RocksIteratorTest {
public TemporaryFolder dbFolder = new TemporaryFolder();
@Test
- public void shouldTestRocksIteratorGc()
+ public void rocksIteratorGc()
throws RocksDBException {
RocksDB db;
Options options = new Options();
@@ -44,6 +44,5 @@ public class RocksIteratorTest {
iter3.dispose();
System.gc();
System.runFinalization();
- System.out.println("Passed RocksIteratorTest.");
}
}
diff --git a/java/org/rocksdb/test/RocksJunitRunner.java b/java/org/rocksdb/test/RocksJunitRunner.java
new file mode 100644
index 000000000..61655f33c
--- /dev/null
+++ b/java/org/rocksdb/test/RocksJunitRunner.java
@@ -0,0 +1,65 @@
+// Copyright (c) 2014, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+package org.rocksdb.test;
+
+import org.junit.internal.JUnitSystem;
+import org.junit.internal.RealSystem;
+import org.junit.internal.TextListener;
+import org.junit.runner.Description;
+import org.junit.runner.JUnitCore;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Custom Junit Runner to print also Test classes
+ * and executed methods to command prompt.
+ */
+public class RocksJunitRunner {
+
+ /**
+ * Listener which overrides default functionality
+ * to print class and method to system out.
+ */
+ static class RocksJunitListener extends TextListener {
+
+ /**
+ * RocksJunitListener constructor
+ *
+ * @param system JUnitSystem
+ */
+ public RocksJunitListener(JUnitSystem system) {
+ super(system);
+ }
+
+ @Override
+ public void testStarted(Description description) {
+ System.out.format("Run: %s testing now -> %s \n",
+ description.getClassName(),
+ description.getMethodName());
+ }
+ }
+
+ /**
+ * Main method to execute tests
+ *
+ * @param args Test classes as String names
+ */
+ public static void main(String[] args){
+ JUnitCore runner = new JUnitCore();
+ final JUnitSystem system = new RealSystem();
+ runner.addListener(new RocksJunitListener(system));
+ try {
+ List> classes = new ArrayList<>();
+ for (String arg : args) {
+ classes.add(Class.forName(arg));
+ }
+ runner.run(classes.toArray(new Class[1]));
+
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/java/org/rocksdb/test/SnapshotTest.java b/java/org/rocksdb/test/SnapshotTest.java
index ad3546de3..7140a1fcb 100644
--- a/java/org/rocksdb/test/SnapshotTest.java
+++ b/java/org/rocksdb/test/SnapshotTest.java
@@ -14,6 +14,8 @@ import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.Snapshot;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class SnapshotTest {
@ClassRule
@@ -24,7 +26,7 @@ public class SnapshotTest {
public TemporaryFolder dbFolder = new TemporaryFolder();
@Test
- public void shouldTestSnapshots() throws RocksDBException {
+ public void snapshots() throws RocksDBException {
RocksDB db;
Options options = new Options();
options.setCreateIfMissing(true);
@@ -37,43 +39,43 @@ public class SnapshotTest {
// set snapshot in ReadOptions
readOptions.setSnapshot(snapshot);
// retrieve key value pair
- assert(new String(db.get("key".getBytes()))
- .equals("value"));
+ assertThat(new String(db.get("key".getBytes()))).
+ isEqualTo("value");
// retrieve key value pair created before
// the snapshot was made
- assert(new String(db.get(readOptions,
- "key".getBytes())).equals("value"));
+ assertThat(new String(db.get(readOptions,
+ "key".getBytes()))).isEqualTo("value");
// add new key/value pair
db.put("newkey".getBytes(), "newvalue".getBytes());
// using no snapshot the latest db entries
// will be taken into account
- assert(new String(db.get("newkey".getBytes()))
- .equals("newvalue"));
+ assertThat(new String(db.get("newkey".getBytes()))).
+ isEqualTo("newvalue");
// snapshopot was created before newkey
- assert(db.get(readOptions, "newkey".getBytes())
- == null);
+ assertThat(db.get(readOptions, "newkey".getBytes())).
+ isNull();
// Retrieve snapshot from read options
Snapshot sameSnapshot = readOptions.snapshot();
readOptions.setSnapshot(sameSnapshot);
// results must be the same with new Snapshot
// instance using the same native pointer
- assert(new String(db.get(readOptions,
- "key".getBytes())).equals("value"));
+ assertThat(new String(db.get(readOptions,
+ "key".getBytes()))).isEqualTo("value");
// update key value pair to newvalue
db.put("key".getBytes(), "newvalue".getBytes());
// read with previously created snapshot will
// read previous version of key value pair
- assert(new String(db.get(readOptions,
- "key".getBytes())).equals("value"));
+ assertThat(new String(db.get(readOptions,
+ "key".getBytes()))).isEqualTo("value");
// read for newkey using the snapshot must be
// null
- assert(db.get(readOptions, "newkey".getBytes())
- == null);
+ assertThat(db.get(readOptions, "newkey".getBytes())).
+ isNull();
// setting null to snapshot in ReadOptions leads
// to no Snapshot being used.
readOptions.setSnapshot(null);
- assert(new String(db.get(readOptions,
- "newkey".getBytes())).equals("newvalue"));
+ assertThat(new String(db.get(readOptions,
+ "newkey".getBytes()))).isEqualTo("newvalue");
// release Snapshot
db.releaseSnapshot(snapshot);
// Close database
diff --git a/java/org/rocksdb/test/StatisticsCollectorTest.java b/java/org/rocksdb/test/StatisticsCollectorTest.java
index b748c21ce..57842af10 100644
--- a/java/org/rocksdb/test/StatisticsCollectorTest.java
+++ b/java/org/rocksdb/test/StatisticsCollectorTest.java
@@ -25,7 +25,7 @@ public class StatisticsCollectorTest {
public TemporaryFolder dbFolder = new TemporaryFolder();
@Test
- public void shouldTestStatisticsCollector()
+ public void statisticsCollector()
throws InterruptedException, RocksDBException {
Options opt = new Options().createStatistics().setCreateIfMissing(true);
Statistics stats = opt.statisticsPtr();
@@ -49,7 +49,5 @@ public class StatisticsCollectorTest {
db.close();
opt.dispose();
-
- System.out.println("Stats collector test passed.!");
}
}
diff --git a/java/org/rocksdb/test/WriteBatchTest.java b/java/org/rocksdb/test/WriteBatchTest.java
index 72e0e464e..cf855c121 100644
--- a/java/org/rocksdb/test/WriteBatchTest.java
+++ b/java/org/rocksdb/test/WriteBatchTest.java
@@ -8,7 +8,6 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors.
package org.rocksdb.test;
-import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -36,19 +35,14 @@ public class WriteBatchTest {
@Rule
public TemporaryFolder dbFolder = new TemporaryFolder();
- @AfterClass
- public static void printMergePass(){
- System.out.println("Passed WriteBatchTest.");
- }
-
@Test
- public void shouldTestEmptyWriteBatch() {
+ public void emptyWriteBatch() {
WriteBatch batch = new WriteBatch();
assertThat(batch.count()).isEqualTo(0);
}
@Test
- public void shouldTestMultipleBatchOperations()
+ public void multipleBatchOperations()
throws UnsupportedEncodingException {
WriteBatch batch = new WriteBatch();
batch.put("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
@@ -66,7 +60,7 @@ public class WriteBatchTest {
}
@Test
- public void shouldTestAppendOperation()
+ public void testAppendOperation()
throws UnsupportedEncodingException {
WriteBatch b1 = new WriteBatch();
WriteBatch b2 = new WriteBatch();
@@ -97,7 +91,7 @@ public class WriteBatchTest {
}
@Test
- public void shouldTestBlobOperation()
+ public void blobOperation()
throws UnsupportedEncodingException {
WriteBatch batch = new WriteBatch();
batch.put("k1".getBytes("US-ASCII"), "v1".getBytes("US-ASCII"));
diff --git a/java/org/rocksdb/test/WriteOptionsTest.java b/java/org/rocksdb/test/WriteOptionsTest.java
index 7a92bf9fa..70a68335d 100644
--- a/java/org/rocksdb/test/WriteOptionsTest.java
+++ b/java/org/rocksdb/test/WriteOptionsTest.java
@@ -5,7 +5,6 @@
package org.rocksdb.test;
-import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.WriteOptions;
@@ -18,13 +17,8 @@ public class WriteOptionsTest {
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
- @AfterClass
- public static void printMessage(){
- System.out.println("Passed WriteOptionsTest.");
- }
-
@Test
- public void shouldTestWriteOptions(){
+ public void writeOptions(){
WriteOptions writeOptions = new WriteOptions();
writeOptions.setDisableWAL(true);
assertThat(writeOptions.disableWAL()).isTrue();
diff --git a/java/rocksjni.pom b/java/rocksjni.pom
index 2966a8a6b..552e26f8e 100644
--- a/java/rocksjni.pom
+++ b/java/rocksjni.pom
@@ -159,6 +159,7 @@
org.mockito
mockito-all
1.9.5
+ test
From a4b28c1ae7ed6697779d68a8ed61153866228163 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Wed, 5 Nov 2014 21:16:35 +0100
Subject: [PATCH 06/12] [RocksJava] Extended Testcases
---
java/org/rocksdb/test/EnvironmentTest.java | 125 +++++++++++++++++++
java/org/rocksdb/test/RocksIteratorTest.java | 38 ++++++
2 files changed, 163 insertions(+)
create mode 100644 java/org/rocksdb/test/EnvironmentTest.java
diff --git a/java/org/rocksdb/test/EnvironmentTest.java b/java/org/rocksdb/test/EnvironmentTest.java
new file mode 100644
index 000000000..c6542afed
--- /dev/null
+++ b/java/org/rocksdb/test/EnvironmentTest.java
@@ -0,0 +1,125 @@
+package org.rocksdb.test;
+
+import org.junit.Test;
+import org.rocksdb.util.Environment;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class EnvironmentTest {
+
+ // Init static context
+ private static Environment environment =
+ new Environment();
+
+ @Test
+ public void mac32() {
+ setEnvironmentClassFields("mac", "32");
+ assertThat(Environment.getJniLibraryExtension()).
+ isEqualTo(".jnilib");
+ assertThat(Environment.getJniLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni-osx.jnilib");
+ assertThat(Environment.getSharedLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni.dylib");
+ }
+
+ @Test
+ public void mac64() {
+ setEnvironmentClassFields("mac", "64");
+ assertThat(Environment.getJniLibraryExtension()).
+ isEqualTo(".jnilib");
+ assertThat(Environment.getJniLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni-osx.jnilib");
+ assertThat(Environment.getSharedLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni.dylib");
+ }
+
+ @Test
+ public void nix32() {
+ // Linux
+ setEnvironmentClassFields("Linux", "32");
+ assertThat(Environment.getJniLibraryExtension()).
+ isEqualTo(".so");
+ assertThat(Environment.getJniLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni-linux32.so");
+ assertThat(Environment.getSharedLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni.so");
+ // UNIX
+ setEnvironmentClassFields("Unix", "32");
+ assertThat(Environment.getJniLibraryExtension()).
+ isEqualTo(".so");
+ assertThat(Environment.getJniLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni-linux32.so");
+ assertThat(Environment.getSharedLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni.so");
+ // AIX
+ setEnvironmentClassFields("aix", "32");
+ assertThat(Environment.getJniLibraryExtension()).
+ isEqualTo(".so");
+ assertThat(Environment.getJniLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni-linux32.so");
+ assertThat(Environment.getSharedLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni.so");
+ }
+
+ @Test
+ public void nix64() {
+ setEnvironmentClassFields("Linux", "x64");
+ assertThat(Environment.getJniLibraryExtension()).
+ isEqualTo(".so");
+ assertThat(Environment.getJniLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni-linux64.so");
+ assertThat(Environment.getSharedLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni.so");
+ // UNIX
+ setEnvironmentClassFields("Unix", "x64");
+ assertThat(Environment.getJniLibraryExtension()).
+ isEqualTo(".so");
+ assertThat(Environment.getJniLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni-linux64.so");
+ assertThat(Environment.getSharedLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni.so");
+ // AIX
+ setEnvironmentClassFields("aix", "x64");
+ assertThat(Environment.getJniLibraryExtension()).
+ isEqualTo(".so");
+ assertThat(Environment.getJniLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni-linux64.so");
+ assertThat(Environment.getSharedLibraryName("rocksdb")).
+ isEqualTo("librocksdbjni.so");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void failLinuxJniLibraryName(){
+ setEnvironmentClassFields("win", "x64");
+ Environment.getJniLibraryName("rocksdb");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void failWinSharedLibrary(){
+ setEnvironmentClassFields("win", "x64");
+ Environment.getSharedLibraryName("rocksdb");
+ }
+
+ private void setEnvironmentClassFields(String osName,
+ String osArch) {
+ setEnvironmentClassField("OS", osName);
+ setEnvironmentClassField("ARCH", osArch);
+ }
+
+ private void setEnvironmentClassField(String fieldName, String value) {
+ final Field field;
+ try {
+ field = Environment.class.getDeclaredField(fieldName);
+ field.setAccessible(true);
+ final Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+ field.set(null, value);
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/java/org/rocksdb/test/RocksIteratorTest.java b/java/org/rocksdb/test/RocksIteratorTest.java
index d2dae63aa..961b7c789 100644
--- a/java/org/rocksdb/test/RocksIteratorTest.java
+++ b/java/org/rocksdb/test/RocksIteratorTest.java
@@ -13,6 +13,8 @@ import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class RocksIteratorTest {
@ClassRule
@@ -22,6 +24,42 @@ public class RocksIteratorTest {
@Rule
public TemporaryFolder dbFolder = new TemporaryFolder();
+ @Test
+ public void rocksIterator() throws RocksDBException {
+ RocksDB db;
+ Options options = new Options();
+ options.setCreateIfMissing(true)
+ .setCreateMissingColumnFamilies(true);
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.put("key1".getBytes(), "value1".getBytes());
+ db.put("key2".getBytes(), "value2".getBytes());
+
+ RocksIterator iterator = db.newIterator();
+
+ iterator.seekToFirst();
+ assertThat(iterator.isValid()).isTrue();
+ assertThat(iterator.key()).isEqualTo("key1".getBytes());
+ assertThat(iterator.value()).isEqualTo("value1".getBytes());
+ iterator.next();
+ assertThat(iterator.isValid()).isTrue();
+ assertThat(iterator.key()).isEqualTo("key2".getBytes());
+ assertThat(iterator.value()).isEqualTo("value2".getBytes());
+ iterator.next();
+ assertThat(iterator.isValid()).isFalse();
+ iterator.seekToLast();
+ iterator.prev();
+ assertThat(iterator.isValid()).isTrue();
+ assertThat(iterator.key()).isEqualTo("key1".getBytes());
+ assertThat(iterator.value()).isEqualTo("value1".getBytes());
+ iterator.seekToFirst();
+ iterator.seekToLast();
+ assertThat(iterator.isValid()).isTrue();
+ assertThat(iterator.key()).isEqualTo("key2".getBytes());
+ assertThat(iterator.value()).isEqualTo("value2".getBytes());
+ iterator.status();
+ }
+
@Test
public void rocksIteratorGc()
throws RocksDBException {
From 628e39e97df75554720063cb43c2bddce99bfec4 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Fri, 7 Nov 2014 14:38:21 +0100
Subject: [PATCH 07/12] [RocksJava] Integrated review comments from D28209
---
java/Makefile | 11 +-
java/org/rocksdb/Options.java | 1 -
java/org/rocksdb/test/BackupableDBTest.java | 244 ++++----
java/org/rocksdb/test/ComparatorTest.java | 229 ++++----
java/org/rocksdb/test/FilterTest.java | 47 +-
java/org/rocksdb/test/KeyMayExistTest.java | 80 ++-
java/org/rocksdb/test/MemTableTest.java | 205 ++++---
java/org/rocksdb/test/MergeTest.java | 353 ++++++-----
java/org/rocksdb/test/OptionsTest.java | 553 ++++++++++--------
java/org/rocksdb/test/ReadOnlyTest.java | 441 ++++++++------
java/org/rocksdb/test/ReadOptionsTest.java | 50 +-
java/org/rocksdb/test/RocksEnvTest.java | 39 ++
java/org/rocksdb/test/RocksIteratorTest.java | 120 ++--
java/org/rocksdb/test/SnapshotTest.java | 117 ++--
.../rocksdb/test/StatisticsCollectorTest.java | 52 +-
java/rocksjni/backupablejni.cc | 2 +-
java/rocksjni/options.cc | 11 +
17 files changed, 1514 insertions(+), 1041 deletions(-)
create mode 100644 java/org/rocksdb/test/RocksEnvTest.java
diff --git a/java/Makefile b/java/Makefile
index 83bf34afc..3c7b8bb1a 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -66,6 +66,7 @@ JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
org.rocksdb.test.PlainTableConfigTest\
org.rocksdb.test.ReadOnlyTest\
org.rocksdb.test.ReadOptionsTest\
+ org.rocksdb.test.RocksEnvTest\
org.rocksdb.test.RocksIteratorTest\
org.rocksdb.test.SnapshotTest\
org.rocksdb.test.StatisticsCollectorTest\
@@ -112,11 +113,11 @@ column_family_sample: java
resolve_test_deps:
mkdir -p "$(JAVA_TEST_LIBDIR)"
- test -s "$(JAVA_JUNIT_JAR)" || curl -L -o $(JAVA_JUNIT_JAR) http://search.maven.org/remotecontent?filepath=junit/junit/4.12-beta-2/junit-4.12-beta-2.jar
- test -s "$(JAVA_HAMCR_JAR)" || curl -L -o $(JAVA_HAMCR_JAR) http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
- test -s "$(JAVA_MOCKITO_JAR)" || curl -L -o "$(JAVA_MOCKITO_JAR)" http://search.maven.org/remotecontent?filepath=org/mockito/mockito-all/1.9.5/mockito-all-1.9.5.jar
- test -s "$(JAVA_CGLIB_JAR)" || curl -L -o "$(JAVA_CGLIB_JAR)" http://search.maven.org/remotecontent?filepath=cglib/cglib/2.2.2/cglib-2.2.2.jar
- test -s "$(JAVA_ASSERTJ_JAR)" || curl -L -o "$(JAVA_ASSERTJ_JAR)" http://central.maven.org/maven2/org/assertj/assertj-core/1.7.0/assertj-core-1.7.0.jar
+ test -s "$(JAVA_JUNIT_JAR)" || curl -k -L -o $(JAVA_JUNIT_JAR) http://search.maven.org/remotecontent?filepath=junit/junit/4.12-beta-2/junit-4.12-beta-2.jar
+ test -s "$(JAVA_HAMCR_JAR)" || curl -k -L -o $(JAVA_HAMCR_JAR) http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
+ test -s "$(JAVA_MOCKITO_JAR)" || curl -k -L -o "$(JAVA_MOCKITO_JAR)" http://search.maven.org/remotecontent?filepath=org/mockito/mockito-all/1.9.5/mockito-all-1.9.5.jar
+ test -s "$(JAVA_CGLIB_JAR)" || curl -k -L -o "$(JAVA_CGLIB_JAR)" http://search.maven.org/remotecontent?filepath=cglib/cglib/2.2.2/cglib-2.2.2.jar
+ test -s "$(JAVA_ASSERTJ_JAR)" || curl -k -L -o "$(JAVA_ASSERTJ_JAR)" http://central.maven.org/maven2/org/assertj/assertj-core/1.7.0/assertj-core-1.7.0.jar
test: java resolve_test_deps
javac -cp $(JAVA_TESTCLASSPATH) org/rocksdb/test/*.java
diff --git a/java/org/rocksdb/Options.java b/java/org/rocksdb/Options.java
index 7307608af..c5ea7216e 100644
--- a/java/org/rocksdb/Options.java
+++ b/java/org/rocksdb/Options.java
@@ -1010,7 +1010,6 @@ public class Options extends RocksObject
long cfOptHandle);
private native void disposeInternal(long handle);
private native void setEnv(long optHandle, long envHandle);
- private native long getEnvHandle(long handle);
private native void prepareForBulkLoad(long handle);
// DB native handles
diff --git a/java/org/rocksdb/test/BackupableDBTest.java b/java/org/rocksdb/test/BackupableDBTest.java
index aa6c07c14..55a707687 100644
--- a/java/org/rocksdb/test/BackupableDBTest.java
+++ b/java/org/rocksdb/test/BackupableDBTest.java
@@ -29,117 +29,137 @@ public class BackupableDBTest {
@Test
public void backupableDb() throws RocksDBException {
-
- Options opt = new Options();
- opt.setCreateIfMissing(true);
-
- BackupableDBOptions bopt = new BackupableDBOptions(
- backupFolder.getRoot().getAbsolutePath(), false,
- true, false, true, 0, 0);
- BackupableDB bdb;
- List backupInfos;
- List restoreInfos;
-
- bdb = BackupableDB.open(opt, bopt,
- dbFolder.getRoot().getAbsolutePath());
- bdb.put("abc".getBytes(), "def".getBytes());
- bdb.put("ghi".getBytes(), "jkl".getBytes());
-
- backupInfos = bdb.getBackupInfos();
- assertThat(backupInfos.size()).
- isEqualTo(0);
-
- bdb.createNewBackup(true);
- backupInfos = bdb.getBackupInfos();
- assertThat(backupInfos.size()).
- isEqualTo(1);
-
- // Retrieving backup infos twice shall not
- // lead to different results
- List tmpBackupInfo = bdb.getBackupInfos();
- assertThat(tmpBackupInfo.get(0).backupId()).
- isEqualTo(backupInfos.get(0).backupId());
- assertThat(tmpBackupInfo.get(0).timestamp()).
- isEqualTo(backupInfos.get(0).timestamp());
- assertThat(tmpBackupInfo.get(0).size()).
- isEqualTo(backupInfos.get(0).size());
- assertThat(tmpBackupInfo.get(0).numberFiles()).
- isEqualTo(backupInfos.get(0).numberFiles());
-
- // delete record after backup
- bdb.remove("abc".getBytes());
- byte[] value = bdb.get("abc".getBytes());
- assertThat(value).isNull();
- bdb.close();
-
- // restore from backup
- RestoreOptions ropt = new RestoreOptions(false);
- RestoreBackupableDB rdb = new RestoreBackupableDB(bopt);
-
- // getting backup infos from restorable db should
- // lead to the same infos as from backupable db
- restoreInfos = rdb.getBackupInfos();
- assertThat(restoreInfos.size()).
- isEqualTo(backupInfos.size());
- assertThat(restoreInfos.get(0).backupId()).
- isEqualTo(backupInfos.get(0).backupId());
- assertThat(restoreInfos.get(0).timestamp()).
- isEqualTo(backupInfos.get(0).timestamp());
- assertThat(restoreInfos.get(0).size()).
- isEqualTo(backupInfos.get(0).size());
- assertThat(restoreInfos.get(0).numberFiles()).
- isEqualTo(backupInfos.get(0).numberFiles());
-
- rdb.restoreDBFromLatestBackup(
- dbFolder.getRoot().getAbsolutePath(),
- dbFolder.getRoot().getAbsolutePath(),
- ropt);
- // do nothing because there is only one backup
- rdb.purgeOldBackups(1);
- restoreInfos = rdb.getBackupInfos();
- assertThat(restoreInfos.size()).
- isEqualTo(1);
- rdb.dispose();
- ropt.dispose();
-
- // verify that backed up data contains deleted record
- bdb = BackupableDB.open(opt, bopt,
- dbFolder.getRoot().getAbsolutePath());
- value = bdb.get("abc".getBytes());
- assertThat(new String(value)).
- isEqualTo("def");
-
- bdb.createNewBackup(false);
- // after new backup there must be two backup infos
- backupInfos = bdb.getBackupInfos();
- assertThat(backupInfos.size()).
- isEqualTo(2);
- // deleting the backup must be possible using the
- // id provided by backup infos
- bdb.deleteBackup(backupInfos.get(1).backupId());
- // after deletion there should only be one info
- backupInfos = bdb.getBackupInfos();
- assertThat(backupInfos.size()).
- isEqualTo(1);
- bdb.createNewBackup(false);
- bdb.createNewBackup(false);
- bdb.createNewBackup(false);
- backupInfos = bdb.getBackupInfos();
- assertThat(backupInfos.size()).
- isEqualTo(4);
- // purge everything and keep two
- bdb.purgeOldBackups(2);
- // backup infos need to be two
- backupInfos = bdb.getBackupInfos();
- assertThat(backupInfos.size()).
- isEqualTo(2);
- assertThat(backupInfos.get(0).backupId()).
- isEqualTo(4);
- assertThat(backupInfos.get(1).backupId()).
- isEqualTo(5);
-
- opt.dispose();
- bopt.dispose();
- bdb.close();
+ Options opt = null;
+ BackupableDBOptions bopt = null;
+ BackupableDB bdb = null;
+ RestoreOptions ropt = null;
+ RestoreBackupableDB rdb = null;
+ try {
+ opt = new Options();
+ opt.setCreateIfMissing(true);
+
+ bopt = new BackupableDBOptions(
+ backupFolder.getRoot().getAbsolutePath(), false,
+ true, false, true, 0, 0);
+ assertThat(bopt.backupDir()).isEqualTo(
+ backupFolder.getRoot().getAbsolutePath());
+
+ List backupInfos;
+ List restoreInfos;
+
+ bdb = BackupableDB.open(opt, bopt,
+ dbFolder.getRoot().getAbsolutePath());
+ bdb.put("abc".getBytes(), "def".getBytes());
+ bdb.put("ghi".getBytes(), "jkl".getBytes());
+
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(0);
+
+ bdb.createNewBackup(true);
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(1);
+
+ // Retrieving backup infos twice shall not
+ // lead to different results
+ List tmpBackupInfo = bdb.getBackupInfos();
+ assertThat(tmpBackupInfo.get(0).backupId()).
+ isEqualTo(backupInfos.get(0).backupId());
+ assertThat(tmpBackupInfo.get(0).timestamp()).
+ isEqualTo(backupInfos.get(0).timestamp());
+ assertThat(tmpBackupInfo.get(0).size()).
+ isEqualTo(backupInfos.get(0).size());
+ assertThat(tmpBackupInfo.get(0).numberFiles()).
+ isEqualTo(backupInfos.get(0).numberFiles());
+
+ // delete record after backup
+ bdb.remove("abc".getBytes());
+ byte[] value = bdb.get("abc".getBytes());
+ assertThat(value).isNull();
+ bdb.close();
+
+ // restore from backup
+ ropt = new RestoreOptions(false);
+ rdb = new RestoreBackupableDB(bopt);
+
+ // getting backup infos from restorable db should
+ // lead to the same infos as from backupable db
+ restoreInfos = rdb.getBackupInfos();
+ assertThat(restoreInfos.size()).
+ isEqualTo(backupInfos.size());
+ assertThat(restoreInfos.get(0).backupId()).
+ isEqualTo(backupInfos.get(0).backupId());
+ assertThat(restoreInfos.get(0).timestamp()).
+ isEqualTo(backupInfos.get(0).timestamp());
+ assertThat(restoreInfos.get(0).size()).
+ isEqualTo(backupInfos.get(0).size());
+ assertThat(restoreInfos.get(0).numberFiles()).
+ isEqualTo(backupInfos.get(0).numberFiles());
+
+ rdb.restoreDBFromLatestBackup(
+ dbFolder.getRoot().getAbsolutePath(),
+ dbFolder.getRoot().getAbsolutePath(),
+ ropt);
+ // do nothing because there is only one backup
+ rdb.purgeOldBackups(1);
+ restoreInfos = rdb.getBackupInfos();
+ assertThat(restoreInfos.size()).
+ isEqualTo(1);
+ rdb.dispose();
+ ropt.dispose();
+
+ // verify that backed up data contains deleted record
+ bdb = BackupableDB.open(opt, bopt,
+ dbFolder.getRoot().getAbsolutePath());
+ value = bdb.get("abc".getBytes());
+ assertThat(new String(value)).
+ isEqualTo("def");
+
+ bdb.createNewBackup(false);
+ // after new backup there must be two backup infos
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(2);
+ // deleting the backup must be possible using the
+ // id provided by backup infos
+ bdb.deleteBackup(backupInfos.get(1).backupId());
+ // after deletion there should only be one info
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(1);
+ bdb.createNewBackup(false);
+ bdb.createNewBackup(false);
+ bdb.createNewBackup(false);
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(4);
+ // purge everything and keep two
+ bdb.purgeOldBackups(2);
+ // backup infos need to be two
+ backupInfos = bdb.getBackupInfos();
+ assertThat(backupInfos.size()).
+ isEqualTo(2);
+ assertThat(backupInfos.get(0).backupId()).
+ isEqualTo(4);
+ assertThat(backupInfos.get(1).backupId()).
+ isEqualTo(5);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ if (bopt != null) {
+ bopt.dispose();
+ }
+ if (bdb != null) {
+ bdb.close();
+ }
+ if (ropt != null) {
+ ropt.dispose();
+ }
+ if (rdb != null) {
+ rdb.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/ComparatorTest.java b/java/org/rocksdb/test/ComparatorTest.java
index c9037954e..299d8f62d 100644
--- a/java/org/rocksdb/test/ComparatorTest.java
+++ b/java/org/rocksdb/test/ComparatorTest.java
@@ -54,113 +54,138 @@ public class ComparatorTest {
@Test
public void builtinForwardComparator()
throws RocksDBException {
- Options options = new Options();
- options.setCreateIfMissing(true);
- options.setComparator(BuiltinComparator.BYTEWISE_COMPARATOR);
- RocksDB rocksDB = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
-
- rocksDB.put("abc1".getBytes(), "abc1".getBytes());
- rocksDB.put("abc2".getBytes(), "abc2".getBytes());
- rocksDB.put("abc3".getBytes(), "abc3".getBytes());
-
- RocksIterator rocksIterator = rocksDB.newIterator();
- // Iterate over keys using a iterator
- rocksIterator.seekToFirst();
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc1".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc1".getBytes());
- rocksIterator.next();
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc2".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc2".getBytes());
- rocksIterator.next();
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc3".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc3".getBytes());
- rocksIterator.next();
- assertThat(rocksIterator.isValid()).isFalse();
- // Get last one
- rocksIterator.seekToLast();
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc3".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc3".getBytes());
- // Seek for abc
- rocksIterator.seek("abc".getBytes());
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc1".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc1".getBytes());
- rocksIterator.dispose();
- rocksDB.close();
- options.dispose();
+ Options options = null;
+ RocksDB rocksDB = null;
+ RocksIterator rocksIterator = null;
+ try {
+ options = new Options();
+ options.setCreateIfMissing(true);
+ options.setComparator(BuiltinComparator.BYTEWISE_COMPARATOR);
+ rocksDB = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+
+ rocksDB.put("abc1".getBytes(), "abc1".getBytes());
+ rocksDB.put("abc2".getBytes(), "abc2".getBytes());
+ rocksDB.put("abc3".getBytes(), "abc3".getBytes());
+
+ rocksIterator = rocksDB.newIterator();
+ // Iterate over keys using a iterator
+ rocksIterator.seekToFirst();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc1".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc1".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc2".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc2".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc3".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc3".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isFalse();
+ // Get last one
+ rocksIterator.seekToLast();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc3".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc3".getBytes());
+ // Seek for abc
+ rocksIterator.seek("abc".getBytes());
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc1".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc1".getBytes());
+
+ } finally {
+ if (rocksIterator != null) {
+ rocksIterator.dispose();
+ }
+ if (rocksDB != null) {
+ rocksDB.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test
public void builtinReverseComparator()
throws RocksDBException {
- Options options = new Options();
- options.setCreateIfMissing(true);
- options.setComparator(
- BuiltinComparator.REVERSE_BYTEWISE_COMPARATOR);
- RocksDB rocksDB = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
-
- rocksDB.put("abc1".getBytes(), "abc1".getBytes());
- rocksDB.put("abc2".getBytes(), "abc2".getBytes());
- rocksDB.put("abc3".getBytes(), "abc3".getBytes());
-
- RocksIterator rocksIterator = rocksDB.newIterator();
- // Iterate over keys using a iterator
- rocksIterator.seekToFirst();
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc3".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc3".getBytes());
- rocksIterator.next();
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc2".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc2".getBytes());
- rocksIterator.next();
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc1".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc1".getBytes());
- rocksIterator.next();
- assertThat(rocksIterator.isValid()).isFalse();
- // Get last one
- rocksIterator.seekToLast();
- assertThat(rocksIterator.isValid()).isTrue();
- assertThat(rocksIterator.key()).isEqualTo(
- "abc1".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc1".getBytes());
- // Will be invalid because abc is after abc1
- rocksIterator.seek("abc".getBytes());
- assertThat(rocksIterator.isValid()).isFalse();
- // Will be abc3 because the next one after abc999
- // is abc3
- rocksIterator.seek("abc999".getBytes());
- assertThat(rocksIterator.key()).isEqualTo(
- "abc3".getBytes());
- assertThat(rocksIterator.value()).isEqualTo(
- "abc3".getBytes());
- rocksIterator.dispose();
- rocksDB.close();
- options.dispose();
+ Options options = null;
+ RocksDB rocksDB = null;
+ RocksIterator rocksIterator = null;
+ try {
+ options = new Options();
+ options.setCreateIfMissing(true);
+ options.setComparator(
+ BuiltinComparator.REVERSE_BYTEWISE_COMPARATOR);
+ rocksDB = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+
+ rocksDB.put("abc1".getBytes(), "abc1".getBytes());
+ rocksDB.put("abc2".getBytes(), "abc2".getBytes());
+ rocksDB.put("abc3".getBytes(), "abc3".getBytes());
+
+ rocksIterator = rocksDB.newIterator();
+ // Iterate over keys using a iterator
+ rocksIterator.seekToFirst();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc3".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc3".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc2".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc2".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc1".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc1".getBytes());
+ rocksIterator.next();
+ assertThat(rocksIterator.isValid()).isFalse();
+ // Get last one
+ rocksIterator.seekToLast();
+ assertThat(rocksIterator.isValid()).isTrue();
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc1".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc1".getBytes());
+ // Will be invalid because abc is after abc1
+ rocksIterator.seek("abc".getBytes());
+ assertThat(rocksIterator.isValid()).isFalse();
+ // Will be abc3 because the next one after abc999
+ // is abc3
+ rocksIterator.seek("abc999".getBytes());
+ assertThat(rocksIterator.key()).isEqualTo(
+ "abc3".getBytes());
+ assertThat(rocksIterator.value()).isEqualTo(
+ "abc3".getBytes());
+ } finally {
+ if (rocksIterator != null) {
+ rocksIterator.dispose();
+ }
+ if (rocksDB != null) {
+ rocksDB.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test
diff --git a/java/org/rocksdb/test/FilterTest.java b/java/org/rocksdb/test/FilterTest.java
index c183f8d95..da4783fbf 100644
--- a/java/org/rocksdb/test/FilterTest.java
+++ b/java/org/rocksdb/test/FilterTest.java
@@ -17,25 +17,32 @@ public class FilterTest {
@Test
public void filter() {
- Options options = new Options();
- // test table config
- options.setTableFormatConfig(new BlockBasedTableConfig().
- setFilter(new BloomFilter()));
- options.dispose();
- System.gc();
- System.runFinalization();
- // new Bloom filter
- options = new Options();
- BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
- blockConfig.setFilter(new BloomFilter());
- options.setTableFormatConfig(blockConfig);
- BloomFilter bloomFilter = new BloomFilter(10);
- blockConfig.setFilter(bloomFilter);
- options.setTableFormatConfig(blockConfig);
- System.gc();
- System.runFinalization();
- blockConfig.setFilter(new BloomFilter(10, false));
- options.setTableFormatConfig(blockConfig);
- options.dispose();
+ Options options = null;
+ try {
+ options = new Options();
+ // test table config
+ options.setTableFormatConfig(new BlockBasedTableConfig().
+ setFilter(new BloomFilter()));
+ options.dispose();
+ System.gc();
+ System.runFinalization();
+ // new Bloom filter
+ options = new Options();
+ BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
+ blockConfig.setFilter(new BloomFilter());
+ options.setTableFormatConfig(blockConfig);
+ BloomFilter bloomFilter = new BloomFilter(10);
+ blockConfig.setFilter(bloomFilter);
+ options.setTableFormatConfig(blockConfig);
+ System.gc();
+ System.runFinalization();
+ blockConfig.setFilter(new BloomFilter(10, false));
+ options.setTableFormatConfig(blockConfig);
+
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/KeyMayExistTest.java b/java/org/rocksdb/test/KeyMayExistTest.java
index 5f6d6225a..c0613bf53 100644
--- a/java/org/rocksdb/test/KeyMayExistTest.java
+++ b/java/org/rocksdb/test/KeyMayExistTest.java
@@ -26,6 +26,7 @@ public class KeyMayExistTest {
@Test
public void keyMayExist() throws RocksDBException {
+<<<<<<< HEAD
RocksDB db;
DBOptions options = new DBOptions();
options.setCreateIfMissing(true)
@@ -49,23 +50,50 @@ public class KeyMayExistTest {
assertThat(exists).isTrue();
assertThat(retValue.toString()).
isEqualTo("value");
+=======
+ RocksDB db = null;
+ Options options = null;
+ try {
+ options = new Options();
+ options.setCreateIfMissing(true)
+ .setCreateMissingColumnFamilies(true);
+ // open database using cf names
+ List cfNames = new ArrayList<>();
+ List columnFamilyHandleList =
+ new ArrayList<>();
+ cfNames.add("default");
+ cfNames.add("new_cf");
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
+ assertThat(columnFamilyHandleList.size()).
+ isEqualTo(2);
+ db.put("key".getBytes(), "value".getBytes());
+ // Test without column family
+ StringBuffer retValue = new StringBuffer();
+ boolean exists = db.keyMayExist("key".getBytes(), retValue);
+ assertThat(exists).isTrue();
+ assertThat(retValue.toString()).
+ isEqualTo("value");
+>>>>>>> [RocksJava] Integrated review comments from D28209
- // Test without column family but with readOptions
- retValue = new StringBuffer();
- exists = db.keyMayExist(new ReadOptions(), "key".getBytes(),
- retValue);
- assertThat(exists).isTrue();
- assertThat(retValue.toString()).
- isEqualTo("value");
+ // Test without column family but with readOptions
+ retValue = new StringBuffer();
+ exists = db.keyMayExist(new ReadOptions(), "key".getBytes(),
+ retValue);
+ assertThat(exists).isTrue();
+ assertThat(retValue.toString()).
+ isEqualTo("value");
- // Test with column family
- retValue = new StringBuffer();
- exists = db.keyMayExist(columnFamilyHandleList.get(0), "key".getBytes(),
- retValue);
- assertThat(exists).isTrue();
- assertThat(retValue.toString()).
- isEqualTo("value");
+ // Test with column family
+ retValue = new StringBuffer();
+ exists = db.keyMayExist(columnFamilyHandleList.get(0), "key".getBytes(),
+ retValue);
+ assertThat(exists).isTrue();
+ assertThat(retValue.toString()).
+ isEqualTo("value");
+<<<<<<< HEAD
// Test with column family and readOptions
retValue = new StringBuffer();
exists = db.keyMayExist(new ReadOptions(),
@@ -74,9 +102,27 @@ public class KeyMayExistTest {
assertThat(exists).isTrue();
assertThat(retValue.toString()).
isEqualTo("value");
+=======
+ // Test with column family and readOptions
+ retValue = new StringBuffer();
+ exists = db.keyMayExist(new ReadOptions(),
+ columnFamilyHandleList.get(0), "key".getBytes(),
+ retValue);
+ assertThat(exists).isTrue();
+ assertThat(retValue.toString()).
+ isEqualTo("value");
+>>>>>>> [RocksJava] Integrated review comments from D28209
- // KeyMayExist in CF1 must return false
- assertThat(db.keyMayExist(columnFamilyHandleList.get(1),
- "key".getBytes(), retValue)).isFalse();
+ // KeyMayExist in CF1 must return false
+ assertThat(db.keyMayExist(columnFamilyHandleList.get(1),
+ "key".getBytes(), retValue)).isFalse();
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/MemTableTest.java b/java/org/rocksdb/test/MemTableTest.java
index 93146303a..dbf6b0bef 100644
--- a/java/org/rocksdb/test/MemTableTest.java
+++ b/java/org/rocksdb/test/MemTableTest.java
@@ -18,94 +18,121 @@ public class MemTableTest {
new RocksMemoryResource();
@Test
- public void memTable() throws RocksDBException {
- Options options = new Options();
- // Test HashSkipListMemTableConfig
- HashSkipListMemTableConfig memTableConfig =
- new HashSkipListMemTableConfig();
- assertThat(memTableConfig.bucketCount()).
- isEqualTo(1000000);
- memTableConfig.setBucketCount(2000000);
- assertThat(memTableConfig.bucketCount()).
- isEqualTo(2000000);
- assertThat(memTableConfig.height()).
- isEqualTo(4);
- memTableConfig.setHeight(5);
- assertThat(memTableConfig.height()).
- isEqualTo(5);
- assertThat(memTableConfig.branchingFactor()).
- isEqualTo(4);
- memTableConfig.setBranchingFactor(6);
- assertThat(memTableConfig.branchingFactor()).
- isEqualTo(6);
- options.setMemTableConfig(memTableConfig);
- options.dispose();
- System.gc();
- System.runFinalization();
- // Test SkipList
- options = new Options();
- SkipListMemTableConfig skipMemTableConfig =
- new SkipListMemTableConfig();
- assertThat(skipMemTableConfig.lookahead()).
- isEqualTo(0);
- skipMemTableConfig.setLookahead(20);
- assertThat(skipMemTableConfig.lookahead()).
- isEqualTo(20);
- options.setMemTableConfig(skipMemTableConfig);
- options.dispose();
- System.gc();
- System.runFinalization();
- // Test HashLinkedListMemTableConfig
- options = new Options();
- HashLinkedListMemTableConfig hashLinkedListMemTableConfig =
- new HashLinkedListMemTableConfig();
- assertThat(hashLinkedListMemTableConfig.bucketCount()).
- isEqualTo(50000);
- hashLinkedListMemTableConfig.setBucketCount(100000);
- assertThat(hashLinkedListMemTableConfig.bucketCount()).
- isEqualTo(100000);
- assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
- isEqualTo(0);
- hashLinkedListMemTableConfig.setHugePageTlbSize(1);
- assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
- isEqualTo(1);
- assertThat(hashLinkedListMemTableConfig.
- bucketEntriesLoggingThreshold()).
- isEqualTo(4096);
- hashLinkedListMemTableConfig.
- setBucketEntriesLoggingThreshold(200);
- assertThat(hashLinkedListMemTableConfig.
- bucketEntriesLoggingThreshold()).
- isEqualTo(200);
- assertThat(hashLinkedListMemTableConfig.
- ifLogBucketDistWhenFlush()).isTrue();
- hashLinkedListMemTableConfig.
- setIfLogBucketDistWhenFlush(false);
- assertThat(hashLinkedListMemTableConfig.
- ifLogBucketDistWhenFlush()).isFalse();
- assertThat(hashLinkedListMemTableConfig.
- thresholdUseSkiplist()).
- isEqualTo(256);
- hashLinkedListMemTableConfig.setThresholdUseSkiplist(29);
- assertThat(hashLinkedListMemTableConfig.
- thresholdUseSkiplist()).
- isEqualTo(29);
- options.setMemTableConfig(hashLinkedListMemTableConfig);
- options.dispose();
- System.gc();
- System.runFinalization();
- // test VectorMemTableConfig
- options = new Options();
- VectorMemTableConfig vectorMemTableConfig =
- new VectorMemTableConfig();
- assertThat(vectorMemTableConfig.reservedSize()).
- isEqualTo(0);
- vectorMemTableConfig.setReservedSize(123);
- assertThat(vectorMemTableConfig.reservedSize()).
- isEqualTo(123);
- options.setMemTableConfig(vectorMemTableConfig);
- options.dispose();
- System.gc();
- System.runFinalization();
+ public void hashSkipListMemTable() throws RocksDBException {
+ Options options = null;
+ try {
+ options = new Options();
+ // Test HashSkipListMemTableConfig
+ HashSkipListMemTableConfig memTableConfig =
+ new HashSkipListMemTableConfig();
+ assertThat(memTableConfig.bucketCount()).
+ isEqualTo(1000000);
+ memTableConfig.setBucketCount(2000000);
+ assertThat(memTableConfig.bucketCount()).
+ isEqualTo(2000000);
+ assertThat(memTableConfig.height()).
+ isEqualTo(4);
+ memTableConfig.setHeight(5);
+ assertThat(memTableConfig.height()).
+ isEqualTo(5);
+ assertThat(memTableConfig.branchingFactor()).
+ isEqualTo(4);
+ memTableConfig.setBranchingFactor(6);
+ assertThat(memTableConfig.branchingFactor()).
+ isEqualTo(6);
+ options.setMemTableConfig(memTableConfig);
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void skipListMemTable() throws RocksDBException {
+ Options options = null;
+ try {
+ options = new Options();
+ SkipListMemTableConfig skipMemTableConfig =
+ new SkipListMemTableConfig();
+ assertThat(skipMemTableConfig.lookahead()).
+ isEqualTo(0);
+ skipMemTableConfig.setLookahead(20);
+ assertThat(skipMemTableConfig.lookahead()).
+ isEqualTo(20);
+ options.setMemTableConfig(skipMemTableConfig);
+ options.dispose();
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void hashLinkedListMemTable() throws RocksDBException {
+ Options options = null;
+ try {
+ options = new Options();
+ HashLinkedListMemTableConfig hashLinkedListMemTableConfig =
+ new HashLinkedListMemTableConfig();
+ assertThat(hashLinkedListMemTableConfig.bucketCount()).
+ isEqualTo(50000);
+ hashLinkedListMemTableConfig.setBucketCount(100000);
+ assertThat(hashLinkedListMemTableConfig.bucketCount()).
+ isEqualTo(100000);
+ assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
+ isEqualTo(0);
+ hashLinkedListMemTableConfig.setHugePageTlbSize(1);
+ assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
+ isEqualTo(1);
+ assertThat(hashLinkedListMemTableConfig.
+ bucketEntriesLoggingThreshold()).
+ isEqualTo(4096);
+ hashLinkedListMemTableConfig.
+ setBucketEntriesLoggingThreshold(200);
+ assertThat(hashLinkedListMemTableConfig.
+ bucketEntriesLoggingThreshold()).
+ isEqualTo(200);
+ assertThat(hashLinkedListMemTableConfig.
+ ifLogBucketDistWhenFlush()).isTrue();
+ hashLinkedListMemTableConfig.
+ setIfLogBucketDistWhenFlush(false);
+ assertThat(hashLinkedListMemTableConfig.
+ ifLogBucketDistWhenFlush()).isFalse();
+ assertThat(hashLinkedListMemTableConfig.
+ thresholdUseSkiplist()).
+ isEqualTo(256);
+ hashLinkedListMemTableConfig.setThresholdUseSkiplist(29);
+ assertThat(hashLinkedListMemTableConfig.
+ thresholdUseSkiplist()).
+ isEqualTo(29);
+ options.setMemTableConfig(hashLinkedListMemTableConfig);
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void vectorMemTable() throws RocksDBException {
+ Options options = null;
+ try {
+ options = new Options();
+ VectorMemTableConfig vectorMemTableConfig =
+ new VectorMemTableConfig();
+ assertThat(vectorMemTableConfig.reservedSize()).
+ isEqualTo(0);
+ vectorMemTableConfig.setReservedSize(123);
+ assertThat(vectorMemTableConfig.reservedSize()).
+ isEqualTo(123);
+ options.setMemTableConfig(vectorMemTableConfig);
+ options.dispose();
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/MergeTest.java b/java/org/rocksdb/test/MergeTest.java
index f1e2fb759..962674716 100644
--- a/java/org/rocksdb/test/MergeTest.java
+++ b/java/org/rocksdb/test/MergeTest.java
@@ -28,180 +28,227 @@ public class MergeTest {
@Test
public void stringOption()
throws InterruptedException, RocksDBException {
- String db_path_string =
- dbFolder.getRoot().getAbsolutePath();
- Options opt = new Options();
- opt.setCreateIfMissing(true);
- opt.setMergeOperatorName("stringappend");
-
- RocksDB db = RocksDB.open(opt, db_path_string);
- // writing aa under key
- db.put("key".getBytes(), "aa".getBytes());
- // merge bb under key
- db.merge("key".getBytes(), "bb".getBytes());
-
- byte[] value = db.get("key".getBytes());
- String strValue = new String(value);
-
- db.close();
- opt.dispose();
- assertThat(strValue).isEqualTo("aa,bb");
+ RocksDB db = null;
+ Options opt = null;
+ try {
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
+ opt = new Options();
+ opt.setCreateIfMissing(true);
+ opt.setMergeOperatorName("stringappend");
+
+ db = RocksDB.open(opt, db_path_string);
+ // writing aa under key
+ db.put("key".getBytes(), "aa".getBytes());
+ // merge bb under key
+ db.merge("key".getBytes(), "bb".getBytes());
+
+ byte[] value = db.get("key".getBytes());
+ String strValue = new String(value);
+ assertThat(strValue).isEqualTo("aa,bb");
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
}
@Test
public void cFStringOption()
throws InterruptedException, RocksDBException {
- DBOptions opt = new DBOptions();
- String db_path_string =
- dbFolder.getRoot().getAbsolutePath();
- opt.setCreateIfMissing(true);
- opt.setCreateMissingColumnFamilies(true);
-
- List cfDescr =
- new ArrayList<>();
+ RocksDB db = null;
+ DBOptions opt = null;
List columnFamilyHandleList =
- new ArrayList<>();
- cfDescr.add(new ColumnFamilyDescriptor("default",
- new ColumnFamilyOptions().setMergeOperatorName(
- "stringappend")));
- cfDescr.add(new ColumnFamilyDescriptor("default",
- new ColumnFamilyOptions().setMergeOperatorName(
- "stringappend")));
- RocksDB db = RocksDB.open(opt, db_path_string,
- cfDescr, columnFamilyHandleList);
-
- // writing aa under key
- db.put(columnFamilyHandleList.get(1),
- "cfkey".getBytes(), "aa".getBytes());
- // merge bb under key
- db.merge(columnFamilyHandleList.get(1),
- "cfkey".getBytes(), "bb".getBytes());
-
- byte[] value = db.get(columnFamilyHandleList.get(1), "cfkey".getBytes());
- String strValue = new String(value);
-
- for (ColumnFamilyHandle handle : columnFamilyHandleList) {
- handle.dispose();
+ new ArrayList<>();
+ try {
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
+ opt = new DBOptions();
+ opt.setCreateIfMissing(true);
+ opt.setCreateMissingColumnFamilies(true);
+
+ List cfDescriptors =
+ new ArrayList<>();
+ cfDescriptors.add(new ColumnFamilyDescriptor("default",
+ new ColumnFamilyOptions().setMergeOperatorName(
+ "stringappend")));
+ cfDescriptors.add(new ColumnFamilyDescriptor("default",
+ new ColumnFamilyOptions().setMergeOperatorName(
+ "stringappend")));
+ db = RocksDB.open(opt, db_path_string,
+ cfDescriptors, columnFamilyHandleList);
+
+ // writing aa under key
+ db.put(columnFamilyHandleList.get(1),
+ "cfkey".getBytes(), "aa".getBytes());
+ // merge bb under key
+ db.merge(columnFamilyHandleList.get(1),
+ "cfkey".getBytes(), "bb".getBytes());
+
+ byte[] value = db.get(columnFamilyHandleList.get(1), "cfkey".getBytes());
+ String strValue = new String(value);
+ assertThat(strValue).isEqualTo("aa,bb");
+ } finally {
+ for (ColumnFamilyHandle handle : columnFamilyHandleList) {
+ handle.dispose();
+ }
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
}
- db.close();
- opt.dispose();
- assertThat(strValue).isEqualTo("aa,bb");
}
@Test
public void operatorOption()
throws InterruptedException, RocksDBException {
- String db_path_string =
- dbFolder.getRoot().getAbsolutePath();
- Options opt = new Options();
- opt.setCreateIfMissing(true);
-
- StringAppendOperator stringAppendOperator = new StringAppendOperator();
- opt.setMergeOperator(stringAppendOperator);
-
- RocksDB db = RocksDB.open(opt, db_path_string);
- // Writing aa under key
- db.put("key".getBytes(), "aa".getBytes());
-
- // Writing bb under key
- db.merge("key".getBytes(), "bb".getBytes());
-
- byte[] value = db.get("key".getBytes());
- String strValue = new String(value);
-
- db.close();
- opt.dispose();
- assertThat(strValue).isEqualTo("aa,bb");
+ RocksDB db = null;
+ Options opt = null;
+ try {
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
+ opt = new Options();
+ opt.setCreateIfMissing(true);
+
+ StringAppendOperator stringAppendOperator = new StringAppendOperator();
+ opt.setMergeOperator(stringAppendOperator);
+
+ db = RocksDB.open(opt, db_path_string);
+ // Writing aa under key
+ db.put("key".getBytes(), "aa".getBytes());
+
+ // Writing bb under key
+ db.merge("key".getBytes(), "bb".getBytes());
+
+ byte[] value = db.get("key".getBytes());
+ String strValue = new String(value);
+
+ assertThat(strValue).isEqualTo("aa,bb");
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
}
@Test
public void cFOperatorOption()
throws InterruptedException, RocksDBException {
- DBOptions opt = new DBOptions();
- String db_path_string =
- dbFolder.getRoot().getAbsolutePath();
-
- opt.setCreateIfMissing(true);
- opt.setCreateMissingColumnFamilies(true);
- StringAppendOperator stringAppendOperator = new StringAppendOperator();
-
- List cfDescr =
- new ArrayList<>();
- List columnFamilyHandleList =
- new ArrayList<>();
- cfDescr.add(new ColumnFamilyDescriptor("default",
- new ColumnFamilyOptions().setMergeOperator(
- stringAppendOperator)));
- cfDescr.add(new ColumnFamilyDescriptor("new_cf",
- new ColumnFamilyOptions().setMergeOperator(
- stringAppendOperator)));
- RocksDB db = RocksDB.open(opt, db_path_string,
- cfDescr, columnFamilyHandleList);
- // writing aa under key
- db.put(columnFamilyHandleList.get(1),
- "cfkey".getBytes(), "aa".getBytes());
- // merge bb under key
- db.merge(columnFamilyHandleList.get(1),
- "cfkey".getBytes(), "bb".getBytes());
- byte[] value = db.get(columnFamilyHandleList.get(1), "cfkey".getBytes());
- String strValue = new String(value);
-
- // Test also with createColumnFamily
- ColumnFamilyHandle columnFamilyHandle = db.createColumnFamily(
- new ColumnFamilyDescriptor("new_cf2",
- new ColumnFamilyOptions().setMergeOperator(
- new StringAppendOperator())));
- // writing xx under cfkey2
- db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes());
- // merge yy under cfkey2
- db.merge(columnFamilyHandle, "cfkey2".getBytes(), "yy".getBytes());
- value = db.get(columnFamilyHandle, "cfkey2".getBytes());
- String strValueTmpCf = new String(value);
-
- columnFamilyHandle.dispose();
- db.close();
- opt.dispose();
- assertThat(strValue).isEqualTo("aa,bb");
- assertThat(strValueTmpCf).isEqualTo("xx,yy");
+ RocksDB db = null;
+ DBOptions opt = null;
+ ColumnFamilyHandle columnFamilyHandle = null;
+ try {
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
+ opt = new DBOptions();
+ opt.setCreateIfMissing(true);
+ opt.setCreateMissingColumnFamilies(true);
+ StringAppendOperator stringAppendOperator = new StringAppendOperator();
+
+ List cfDescriptors =
+ new ArrayList<>();
+ List columnFamilyHandleList =
+ new ArrayList<>();
+ cfDescriptors.add(new ColumnFamilyDescriptor("default",
+ new ColumnFamilyOptions().setMergeOperator(
+ stringAppendOperator)));
+ cfDescriptors.add(new ColumnFamilyDescriptor("new_cf",
+ new ColumnFamilyOptions().setMergeOperator(
+ stringAppendOperator)));
+ db = RocksDB.open(opt, db_path_string,
+ cfDescriptors, columnFamilyHandleList);
+
+ // writing aa under key
+ db.put(columnFamilyHandleList.get(1),
+ "cfkey".getBytes(), "aa".getBytes());
+ // merge bb under key
+ db.merge(columnFamilyHandleList.get(1),
+ "cfkey".getBytes(), "bb".getBytes());
+ byte[] value = db.get(columnFamilyHandleList.get(1), "cfkey".getBytes());
+ String strValue = new String(value);
+
+ // Test also with createColumnFamily
+ columnFamilyHandle = db.createColumnFamily(
+ new ColumnFamilyDescriptor("new_cf2"));
+ // writing xx under cfkey2
+ db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes());
+ // merge yy under cfkey2
+ db.merge(columnFamilyHandle, "cfkey2".getBytes(), "yy".getBytes());
+ value = db.get(columnFamilyHandle, "cfkey2".getBytes());
+ String strValueTmpCf = new String(value);
+
+ columnFamilyHandle.dispose();
+ assertThat(strValue).isEqualTo("aa,bb");
+ assertThat(strValueTmpCf).isEqualTo("xx,yy");
+ } finally {
+ if (columnFamilyHandle != null) {
+ columnFamilyHandle.dispose();
+ }
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
}
@Test
public void operatorGcBehaviour()
throws RocksDBException {
- String db_path_string =
- dbFolder.getRoot().getAbsolutePath();
- Options opt = new Options();
- opt.setCreateIfMissing(true);
- StringAppendOperator stringAppendOperator = new StringAppendOperator();
- opt.setMergeOperator(stringAppendOperator);
- RocksDB db = RocksDB.open(opt, db_path_string);
- db.close();
- opt.dispose();
- System.gc();
- System.runFinalization();
- // test reuse
- opt = new Options();
- opt.setMergeOperator(stringAppendOperator);
- db = RocksDB.open(opt, db_path_string);
- db.close();
- opt.dispose();
- System.gc();
- System.runFinalization();
- // test param init
- opt = new Options();
- opt.setMergeOperator(new StringAppendOperator());
- db = RocksDB.open(opt, db_path_string);
- db.close();
- opt.dispose();
- System.gc();
- System.runFinalization();
- // test replace one with another merge operator instance
- opt = new Options();
- opt.setMergeOperator(stringAppendOperator);
- StringAppendOperator newStringAppendOperator = new StringAppendOperator();
- opt.setMergeOperator(newStringAppendOperator);
- db = RocksDB.open(opt, db_path_string);
- db.close();
- opt.dispose();
+ Options opt = null;
+ RocksDB db = null;
+ try {
+ String db_path_string =
+ dbFolder.getRoot().getAbsolutePath();
+ opt = new Options();
+ opt.setCreateIfMissing(true);
+ StringAppendOperator stringAppendOperator = new StringAppendOperator();
+ opt.setMergeOperator(stringAppendOperator);
+ db = RocksDB.open(opt, db_path_string);
+ db.close();
+ opt.dispose();
+ System.gc();
+ System.runFinalization();
+ // test reuse
+ opt = new Options();
+ opt.setMergeOperator(stringAppendOperator);
+ db = RocksDB.open(opt, db_path_string);
+ db.close();
+ opt.dispose();
+ System.gc();
+ System.runFinalization();
+ // test param init
+ opt = new Options();
+ opt.setMergeOperator(new StringAppendOperator());
+ db = RocksDB.open(opt, db_path_string);
+ db.close();
+ opt.dispose();
+ System.gc();
+ System.runFinalization();
+ // test replace one with another merge operator instance
+ opt = new Options();
+ opt.setMergeOperator(stringAppendOperator);
+ StringAppendOperator newStringAppendOperator = new StringAppendOperator();
+ opt.setMergeOperator(newStringAppendOperator);
+ db = RocksDB.open(opt, db_path_string);
+ db.close();
+ opt.dispose();
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/OptionsTest.java b/java/org/rocksdb/test/OptionsTest.java
index f8fbd7bcc..24dd5081c 100644
--- a/java/org/rocksdb/test/OptionsTest.java
+++ b/java/org/rocksdb/test/OptionsTest.java
@@ -21,281 +21,350 @@ public class OptionsTest {
@Test
public void options() throws RocksDBException {
- Options opt = new Options();
- Random rand = PlatformRandomHelper.
- getPlatformSpecificRandomFactory();
-
- DBOptionsTest.testDBOptions(opt);
-
- { // WriteBufferSize test
- long longValue = rand.nextLong();
- opt.setWriteBufferSize(longValue);
- assert(opt.writeBufferSize() == longValue);
- }
-
- { // MaxWriteBufferNumber test
- int intValue = rand.nextInt();
- opt.setMaxWriteBufferNumber(intValue);
- assert(opt.maxWriteBufferNumber() == intValue);
- }
-
- { // MinWriteBufferNumberToMerge test
- int intValue = rand.nextInt();
- opt.setMinWriteBufferNumberToMerge(intValue);
- assert(opt.minWriteBufferNumberToMerge() == intValue);
- }
-
- { // NumLevels test
- int intValue = rand.nextInt();
- opt.setNumLevels(intValue);
- assert(opt.numLevels() == intValue);
- }
-
- { // LevelFileNumCompactionTrigger test
- int intValue = rand.nextInt();
- opt.setLevelZeroFileNumCompactionTrigger(intValue);
- assert(opt.levelZeroFileNumCompactionTrigger() == intValue);
- }
-
- { // LevelSlowdownWritesTrigger test
- int intValue = rand.nextInt();
- opt.setLevelZeroSlowdownWritesTrigger(intValue);
- assert(opt.levelZeroSlowdownWritesTrigger() == intValue);
- }
-
- { // LevelStopWritesTrigger test
- int intValue = rand.nextInt();
- opt.setLevelZeroStopWritesTrigger(intValue);
- assert(opt.levelZeroStopWritesTrigger() == intValue);
- }
-
- { // MaxMemCompactionLevel test
- int intValue = rand.nextInt();
- opt.setMaxMemCompactionLevel(intValue);
- assert(opt.maxMemCompactionLevel() == intValue);
- }
-
- { // TargetFileSizeBase test
- long longValue = rand.nextLong();
- opt.setTargetFileSizeBase(longValue);
- assert(opt.targetFileSizeBase() == longValue);
- }
-
- { // TargetFileSizeMultiplier test
- int intValue = rand.nextInt();
- opt.setTargetFileSizeMultiplier(intValue);
- assert(opt.targetFileSizeMultiplier() == intValue);
- }
-
- { // MaxBytesForLevelBase test
- long longValue = rand.nextLong();
- opt.setMaxBytesForLevelBase(longValue);
- assert(opt.maxBytesForLevelBase() == longValue);
- }
-
- { // MaxBytesForLevelMultiplier test
- int intValue = rand.nextInt();
- opt.setMaxBytesForLevelMultiplier(intValue);
- assert(opt.maxBytesForLevelMultiplier() == intValue);
- }
-
- { // ExpandedCompactionFactor test
- int intValue = rand.nextInt();
- opt.setExpandedCompactionFactor(intValue);
- assert(opt.expandedCompactionFactor() == intValue);
- }
-
- { // SourceCompactionFactor test
- int intValue = rand.nextInt();
- opt.setSourceCompactionFactor(intValue);
- assert(opt.sourceCompactionFactor() == intValue);
- }
-
- { // MaxGrandparentOverlapFactor test
- int intValue = rand.nextInt();
- opt.setMaxGrandparentOverlapFactor(intValue);
- assert(opt.maxGrandparentOverlapFactor() == intValue);
- }
-
- { // SoftRateLimit test
- double doubleValue = rand.nextDouble();
- opt.setSoftRateLimit(doubleValue);
- assert(opt.softRateLimit() == doubleValue);
- }
-
- { // HardRateLimit test
- double doubleValue = rand.nextDouble();
- opt.setHardRateLimit(doubleValue);
- assert(opt.hardRateLimit() == doubleValue);
- }
-
- { // RateLimitDelayMaxMilliseconds test
- int intValue = rand.nextInt();
- opt.setRateLimitDelayMaxMilliseconds(intValue);
- assert(opt.rateLimitDelayMaxMilliseconds() == intValue);
- }
-
- { // ArenaBlockSize test
- long longValue = rand.nextLong();
- opt.setArenaBlockSize(longValue);
- assert(opt.arenaBlockSize() == longValue);
- }
-
- { // DisableAutoCompactions test
- boolean boolValue = rand.nextBoolean();
- opt.setDisableAutoCompactions(boolValue);
- assert(opt.disableAutoCompactions() == boolValue);
- }
-
- { // PurgeRedundantKvsWhileFlush test
- boolean boolValue = rand.nextBoolean();
- opt.setPurgeRedundantKvsWhileFlush(boolValue);
- assert(opt.purgeRedundantKvsWhileFlush() == boolValue);
- }
-
- { // VerifyChecksumsInCompaction test
- boolean boolValue = rand.nextBoolean();
- opt.setVerifyChecksumsInCompaction(boolValue);
- assert(opt.verifyChecksumsInCompaction() == boolValue);
- }
-
- { // FilterDeletes test
- boolean boolValue = rand.nextBoolean();
- opt.setFilterDeletes(boolValue);
- assert(opt.filterDeletes() == boolValue);
- }
-
- { // MaxSequentialSkipInIterations test
- long longValue = rand.nextLong();
- opt.setMaxSequentialSkipInIterations(longValue);
- assert(opt.maxSequentialSkipInIterations() == longValue);
- }
-
- { // InplaceUpdateSupport test
- boolean boolValue = rand.nextBoolean();
- opt.setInplaceUpdateSupport(boolValue);
- assert(opt.inplaceUpdateSupport() == boolValue);
- }
-
- { // InplaceUpdateNumLocks test
- long longValue = rand.nextLong();
- opt.setInplaceUpdateNumLocks(longValue);
- assert(opt.inplaceUpdateNumLocks() == longValue);
- }
-
- { // MemtablePrefixBloomBits test
- int intValue = rand.nextInt();
- opt.setMemtablePrefixBloomBits(intValue);
- assert(opt.memtablePrefixBloomBits() == intValue);
- }
-
- { // MemtablePrefixBloomProbes test
- int intValue = rand.nextInt();
- opt.setMemtablePrefixBloomProbes(intValue);
- assert(opt.memtablePrefixBloomProbes() == intValue);
- }
-
- { // BloomLocality test
- int intValue = rand.nextInt();
- opt.setBloomLocality(intValue);
- assert(opt.bloomLocality() == intValue);
- }
-
- { // MaxSuccessiveMerges test
- long longValue = rand.nextLong();
- opt.setMaxSuccessiveMerges(longValue);
- assert(opt.maxSuccessiveMerges() == longValue);
+ Options opt = null;
+ try {
+ opt = new Options();
+ Random rand = PlatformRandomHelper.
+ getPlatformSpecificRandomFactory();
+ DBOptionsTest.testDBOptions(opt);
+
+ { // WriteBufferSize test
+ long longValue = rand.nextLong();
+ opt.setWriteBufferSize(longValue);
+ assert (opt.writeBufferSize() == longValue);
+ }
+
+ { // MaxWriteBufferNumber test
+ int intValue = rand.nextInt();
+ opt.setMaxWriteBufferNumber(intValue);
+ assert (opt.maxWriteBufferNumber() == intValue);
+ }
+
+ { // MinWriteBufferNumberToMerge test
+ int intValue = rand.nextInt();
+ opt.setMinWriteBufferNumberToMerge(intValue);
+ assert (opt.minWriteBufferNumberToMerge() == intValue);
+ }
+
+ { // NumLevels test
+ int intValue = rand.nextInt();
+ opt.setNumLevels(intValue);
+ assert (opt.numLevels() == intValue);
+ }
+
+ { // LevelFileNumCompactionTrigger test
+ int intValue = rand.nextInt();
+ opt.setLevelZeroFileNumCompactionTrigger(intValue);
+ assert (opt.levelZeroFileNumCompactionTrigger() == intValue);
+ }
+
+ { // LevelSlowdownWritesTrigger test
+ int intValue = rand.nextInt();
+ opt.setLevelZeroSlowdownWritesTrigger(intValue);
+ assert (opt.levelZeroSlowdownWritesTrigger() == intValue);
+ }
+
+ { // LevelStopWritesTrigger test
+ int intValue = rand.nextInt();
+ opt.setLevelZeroStopWritesTrigger(intValue);
+ assert (opt.levelZeroStopWritesTrigger() == intValue);
+ }
+
+ { // MaxMemCompactionLevel test
+ int intValue = rand.nextInt();
+ opt.setMaxMemCompactionLevel(intValue);
+ assert (opt.maxMemCompactionLevel() == intValue);
+ }
+
+ { // TargetFileSizeBase test
+ long longValue = rand.nextLong();
+ opt.setTargetFileSizeBase(longValue);
+ assert (opt.targetFileSizeBase() == longValue);
+ }
+
+ { // TargetFileSizeMultiplier test
+ int intValue = rand.nextInt();
+ opt.setTargetFileSizeMultiplier(intValue);
+ assert (opt.targetFileSizeMultiplier() == intValue);
+ }
+
+ { // MaxBytesForLevelBase test
+ long longValue = rand.nextLong();
+ opt.setMaxBytesForLevelBase(longValue);
+ assert (opt.maxBytesForLevelBase() == longValue);
+ }
+
+ { // MaxBytesForLevelMultiplier test
+ int intValue = rand.nextInt();
+ opt.setMaxBytesForLevelMultiplier(intValue);
+ assert (opt.maxBytesForLevelMultiplier() == intValue);
+ }
+
+ { // ExpandedCompactionFactor test
+ int intValue = rand.nextInt();
+ opt.setExpandedCompactionFactor(intValue);
+ assert (opt.expandedCompactionFactor() == intValue);
+ }
+
+ { // SourceCompactionFactor test
+ int intValue = rand.nextInt();
+ opt.setSourceCompactionFactor(intValue);
+ assert (opt.sourceCompactionFactor() == intValue);
+ }
+
+ { // MaxGrandparentOverlapFactor test
+ int intValue = rand.nextInt();
+ opt.setMaxGrandparentOverlapFactor(intValue);
+ assert (opt.maxGrandparentOverlapFactor() == intValue);
+ }
+
+ { // SoftRateLimit test
+ double doubleValue = rand.nextDouble();
+ opt.setSoftRateLimit(doubleValue);
+ assert (opt.softRateLimit() == doubleValue);
+ }
+
+ { // HardRateLimit test
+ double doubleValue = rand.nextDouble();
+ opt.setHardRateLimit(doubleValue);
+ assert (opt.hardRateLimit() == doubleValue);
+ }
+
+ { // RateLimitDelayMaxMilliseconds test
+ int intValue = rand.nextInt();
+ opt.setRateLimitDelayMaxMilliseconds(intValue);
+ assert (opt.rateLimitDelayMaxMilliseconds() == intValue);
+ }
+
+ { // ArenaBlockSize test
+ long longValue = rand.nextLong();
+ opt.setArenaBlockSize(longValue);
+ assert (opt.arenaBlockSize() == longValue);
+ }
+
+ { // DisableAutoCompactions test
+ boolean boolValue = rand.nextBoolean();
+ opt.setDisableAutoCompactions(boolValue);
+ assert (opt.disableAutoCompactions() == boolValue);
+ }
+
+ { // PurgeRedundantKvsWhileFlush test
+ boolean boolValue = rand.nextBoolean();
+ opt.setPurgeRedundantKvsWhileFlush(boolValue);
+ assert (opt.purgeRedundantKvsWhileFlush() == boolValue);
+ }
+
+ { // VerifyChecksumsInCompaction test
+ boolean boolValue = rand.nextBoolean();
+ opt.setVerifyChecksumsInCompaction(boolValue);
+ assert (opt.verifyChecksumsInCompaction() == boolValue);
+ }
+
+ { // FilterDeletes test
+ boolean boolValue = rand.nextBoolean();
+ opt.setFilterDeletes(boolValue);
+ assert (opt.filterDeletes() == boolValue);
+ }
+
+ { // MaxSequentialSkipInIterations test
+ long longValue = rand.nextLong();
+ opt.setMaxSequentialSkipInIterations(longValue);
+ assert (opt.maxSequentialSkipInIterations() == longValue);
+ }
+
+ { // InplaceUpdateSupport test
+ boolean boolValue = rand.nextBoolean();
+ opt.setInplaceUpdateSupport(boolValue);
+ assert (opt.inplaceUpdateSupport() == boolValue);
+ }
+
+ { // InplaceUpdateNumLocks test
+ long longValue = rand.nextLong();
+ opt.setInplaceUpdateNumLocks(longValue);
+ assert (opt.inplaceUpdateNumLocks() == longValue);
+ }
+
+ { // MemtablePrefixBloomBits test
+ int intValue = rand.nextInt();
+ opt.setMemtablePrefixBloomBits(intValue);
+ assert (opt.memtablePrefixBloomBits() == intValue);
+ }
+
+ { // MemtablePrefixBloomProbes test
+ int intValue = rand.nextInt();
+ opt.setMemtablePrefixBloomProbes(intValue);
+ assert (opt.memtablePrefixBloomProbes() == intValue);
+ }
+
+ { // BloomLocality test
+ int intValue = rand.nextInt();
+ opt.setBloomLocality(intValue);
+ assert (opt.bloomLocality() == intValue);
+ }
+
+ { // MaxSuccessiveMerges test
+ long longValue = rand.nextLong();
+ opt.setMaxSuccessiveMerges(longValue);
+ assert (opt.maxSuccessiveMerges() == longValue);
+ }
+
+ { // MinPartialMergeOperands test
+ int intValue = rand.nextInt();
+ opt.setMinPartialMergeOperands(intValue);
+ assert (opt.minPartialMergeOperands() == intValue);
+ }
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MinPartialMergeOperands test
- int intValue = rand.nextInt();
- opt.setMinPartialMergeOperands(intValue);
- assert(opt.minPartialMergeOperands() == intValue);
+ @Test
+ public void rocksEnv() {
+ Options options = null;
+ try {
+ options = new Options();
+ RocksEnv rocksEnv = RocksEnv.getDefault();
+ options.setEnv(rocksEnv);
+ assertThat(options.getEnv()).isSameAs(rocksEnv);
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
}
-
- opt.dispose();
}
@Test
public void linkageOfPrepMethods() {
- Options options = new Options();
- options.optimizeUniversalStyleCompaction();
- options.optimizeUniversalStyleCompaction(4000);
- options.optimizeLevelStyleCompaction();
- options.optimizeLevelStyleCompaction(3000);
- options.optimizeForPointLookup(10);
- options.prepareForBulkLoad();
+ Options options = null;
+ try {
+ options = new Options();
+ options.optimizeUniversalStyleCompaction();
+ options.optimizeUniversalStyleCompaction(4000);
+ options.optimizeLevelStyleCompaction();
+ options.optimizeLevelStyleCompaction(3000);
+ options.optimizeForPointLookup(10);
+ options.prepareForBulkLoad();
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test
public void compressionTypes() {
- Options options = new Options();
- for(CompressionType compressionType :
- CompressionType.values()) {
- options.setCompressionType(compressionType);
- assertThat(options.compressionType()).
- isEqualTo(compressionType);
+ Options options = null;
+ try {
+ options = new Options();
+ for (CompressionType compressionType :
+ CompressionType.values()) {
+ options.setCompressionType(compressionType);
+ assertThat(options.compressionType()).
+ isEqualTo(compressionType);
+ }
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
}
- options.dispose();
}
@Test
public void compactionStyles() {
- Options options = new Options();
- for (CompactionStyle compactionStyle :
- CompactionStyle.values()) {
- options.setCompactionStyle(compactionStyle);
- assertThat(options.compactionStyle()).
- isEqualTo(compactionStyle);
+ Options options = null;
+ try {
+ options = new Options();
+ for (CompactionStyle compactionStyle :
+ CompactionStyle.values()) {
+ options.setCompactionStyle(compactionStyle);
+ assertThat(options.compactionStyle()).
+ isEqualTo(compactionStyle);
+ }
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
}
- options.dispose();
}
@Test
public void rateLimiterConfig() {
- Options options = new Options();
- RateLimiterConfig rateLimiterConfig =
- new GenericRateLimiterConfig(1000, 0, 1);
- options.setRateLimiterConfig(rateLimiterConfig);
- options.dispose();
- // Test with parameter initialization
- Options anotherOptions = new Options();
- anotherOptions.setRateLimiterConfig(
- new GenericRateLimiterConfig(1000));
- anotherOptions.dispose();
+ Options options = null;
+ Options anotherOptions = null;
+ RateLimiterConfig rateLimiterConfig;
+ try {
+ options = new Options();
+ rateLimiterConfig = new GenericRateLimiterConfig(1000, 0, 1);
+ options.setRateLimiterConfig(rateLimiterConfig);
+ // Test with parameter initialization
+ anotherOptions = new Options();
+ anotherOptions.setRateLimiterConfig(
+ new GenericRateLimiterConfig(1000));
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ if (anotherOptions != null) {
+ anotherOptions.dispose();
+ }
+ }
}
@Test
public void shouldSetTestPrefixExtractor() {
- Options options = new Options();
- options.useFixedLengthPrefixExtractor(100);
- options.useFixedLengthPrefixExtractor(10);
- options.dispose();
+ Options options = null;
+ try {
+ options = new Options();
+ options.useFixedLengthPrefixExtractor(100);
+ options.useFixedLengthPrefixExtractor(10);
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test
public void shouldTestMemTableFactoryName()
throws RocksDBException {
- Options options = new Options();
- options.setMemTableConfig(new VectorMemTableConfig());
- assertThat(options.memTableFactoryName()).
- isEqualTo("VectorRepFactory");
- options.setMemTableConfig(
- new HashLinkedListMemTableConfig());
- assertThat(options.memTableFactoryName()).
- isEqualTo("HashLinkedListRepFactory");
- options.dispose();
+ Options options = null;
+ try {
+ options = new Options();
+ options.setMemTableConfig(new VectorMemTableConfig());
+ assertThat(options.memTableFactoryName()).
+ isEqualTo("VectorRepFactory");
+ options.setMemTableConfig(
+ new HashLinkedListMemTableConfig());
+ assertThat(options.memTableFactoryName()).
+ isEqualTo("HashLinkedListRepFactory");
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test
public void statistics() {
- Options options = new Options();
- Statistics statistics = options.createStatistics().
- statisticsPtr();
- assertThat(statistics).isNotNull();
-
- Options anotherOptions = new Options();
- statistics = anotherOptions.statisticsPtr();
- assertThat(statistics).isNotNull();
+ Options options = null;
+ Options anotherOptions = null;
+ try {
+ options = new Options();
+ Statistics statistics = options.createStatistics().
+ statisticsPtr();
+ assertThat(statistics).isNotNull();
+ anotherOptions = new Options();
+ statistics = anotherOptions.statisticsPtr();
+ assertThat(statistics).isNotNull();
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ if (anotherOptions != null) {
+ anotherOptions.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/ReadOnlyTest.java b/java/org/rocksdb/test/ReadOnlyTest.java
index 1151f93dc..bf6bb5eb5 100644
--- a/java/org/rocksdb/test/ReadOnlyTest.java
+++ b/java/org/rocksdb/test/ReadOnlyTest.java
@@ -26,203 +26,308 @@ public class ReadOnlyTest {
@Test
public void readOnlyOpen() throws RocksDBException {
- RocksDB db, db2, db3;
+ RocksDB db = null;
+ RocksDB db2 = null;
+ RocksDB db3 = null;
+ Options options = null;
List columnFamilyHandleList =
new ArrayList<>();
List readOnlyColumnFamilyHandleList =
new ArrayList<>();
List readOnlyColumnFamilyHandleList2 =
new ArrayList<>();
-
- Options options = new Options();
- options.setCreateIfMissing(true);
-
- db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.put("key".getBytes(), "value".getBytes());
- db2 = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath());
- assertThat("value").
- isEqualTo(new String(db2.get("key".getBytes())));
- db.close();
- db2.close();
-
- List cfDescriptors = new ArrayList<>();
- cfDescriptors.add(
- new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
- new ColumnFamilyOptions()));
-
- db = RocksDB.open(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors, columnFamilyHandleList);
- columnFamilyHandleList.add(db.createColumnFamily(
- new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
- columnFamilyHandleList.add(db.createColumnFamily(
- new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions())));
- db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
- "value2".getBytes());
-
- db2 = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
- readOnlyColumnFamilyHandleList);
- assertThat(db2.get("key2".getBytes())).isNull();
- assertThat(db2.get(readOnlyColumnFamilyHandleList.get(0), "key2".getBytes())).
- isNull();
-
- cfDescriptors.clear();
- cfDescriptors.add(
- new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
- new ColumnFamilyOptions()));
- cfDescriptors.add(
- new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions()));
- db3 = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
- readOnlyColumnFamilyHandleList2);
- assertThat(new String(db3.get(readOnlyColumnFamilyHandleList2.get(1),
- "key2".getBytes()))).isEqualTo("value2");
- db.close();
- db2.close();
- db3.close();
- options.dispose();
+ try {
+ options = new Options();
+ options.setCreateIfMissing(true);
+
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.put("key".getBytes(), "value".getBytes());
+ db2 = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath());
+ assertThat("value").
+ isEqualTo(new String(db2.get("key".getBytes())));
+ db.close();
+ db2.close();
+
+ List cfDescriptors = new ArrayList<>();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+
+ db = RocksDB.open(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors, columnFamilyHandleList);
+ columnFamilyHandleList.add(db.createColumnFamily(
+ new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
+ columnFamilyHandleList.add(db.createColumnFamily(
+ new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions())));
+ db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
+ "value2".getBytes());
+
+ db2 = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+ assertThat(db2.get("key2".getBytes())).isNull();
+ assertThat(db2.get(readOnlyColumnFamilyHandleList.get(0), "key2".getBytes())).
+ isNull();
+ cfDescriptors.clear();
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
+ new ColumnFamilyOptions()));
+ cfDescriptors.add(
+ new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions()));
+ db3 = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors, readOnlyColumnFamilyHandleList2);
+ assertThat(new String(db3.get(readOnlyColumnFamilyHandleList2.get(1),
+ "key2".getBytes()))).isEqualTo("value2");
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (db2 != null) {
+ db2.close();
+ }
+ if (db3 != null) {
+ db3.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test(expected = RocksDBException.class)
public void failToWriteInReadOnly() throws RocksDBException {
- List cfDescriptors = new ArrayList<>();
- cfDescriptors.add(
- new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
- new ColumnFamilyOptions()));
- List readOnlyColumnFamilyHandleList =
- new ArrayList<>();
- Options options = new Options();
- options.setCreateIfMissing(true);
-
- RocksDB db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.close();
- RocksDB rDb = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
- readOnlyColumnFamilyHandleList);
- // test that put fails in readonly mode
- rDb.put("key".getBytes(), "value".getBytes());
+ RocksDB db = null;
+ RocksDB rDb = null;
+ Options options = null;
+ 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);
+
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+ rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ // test that put fails in readonly mode
+ rDb.put("key".getBytes(), "value".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (rDb != null) {
+ rDb.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test(expected = RocksDBException.class)
public void failToCFWriteInReadOnly() throws RocksDBException {
- List cfDescriptors = new ArrayList<>();
- cfDescriptors.add(
- new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
- new ColumnFamilyOptions()));
- List readOnlyColumnFamilyHandleList =
- new ArrayList<>();
-
- Options options = new Options();
- options.setCreateIfMissing(true);
-
- RocksDB db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.close();
- RocksDB rDb = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
- readOnlyColumnFamilyHandleList);
-
- rDb.put(readOnlyColumnFamilyHandleList.get(0),
- "key".getBytes(), "value".getBytes());
+ RocksDB db = null;
+ RocksDB rDb = null;
+ Options options = null;
+ 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);
+
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+ rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ rDb.put(readOnlyColumnFamilyHandleList.get(0),
+ "key".getBytes(), "value".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (rDb != null) {
+ rDb.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test(expected = RocksDBException.class)
public void failToRemoveInReadOnly() throws RocksDBException {
- List cfDescriptors = new ArrayList<>();
- cfDescriptors.add(
- new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
- new ColumnFamilyOptions()));
- List readOnlyColumnFamilyHandleList =
- new ArrayList<>();
-
- Options options = new Options();
- options.setCreateIfMissing(true);
-
- RocksDB db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.close();
- RocksDB rDb = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
- readOnlyColumnFamilyHandleList);
-
- rDb.remove("key".getBytes());
+ RocksDB db = null;
+ RocksDB rDb = null;
+ Options options = null;
+ 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);
+
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+ rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ rDb.remove("key".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (rDb != null) {
+ rDb.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test(expected = RocksDBException.class)
public void failToCFRemoveInReadOnly() throws RocksDBException {
- List cfDescriptors = new ArrayList<>();
- cfDescriptors.add(
- new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
- new ColumnFamilyOptions()));
- List readOnlyColumnFamilyHandleList =
- new ArrayList<>();
-
- Options options = new Options();
- options.setCreateIfMissing(true);
-
- RocksDB db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.close();
-
- RocksDB rDb = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
- readOnlyColumnFamilyHandleList);
-
- rDb.remove(readOnlyColumnFamilyHandleList.get(0),
- "key".getBytes());
+ RocksDB db = null;
+ RocksDB rDb = null;
+ Options options = null;
+ 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);
+
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+
+ rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ rDb.remove(readOnlyColumnFamilyHandleList.get(0),
+ "key".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (rDb != null) {
+ rDb.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test(expected = RocksDBException.class)
public void failToWriteBatchReadOnly() throws RocksDBException {
- List cfDescriptors = new ArrayList<>();
- cfDescriptors.add(
- new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
- new ColumnFamilyOptions()));
- List readOnlyColumnFamilyHandleList =
- new ArrayList<>();
-
- Options options = new Options();
- options.setCreateIfMissing(true);
-
- RocksDB db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.close();
-
- RocksDB rDb = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
- readOnlyColumnFamilyHandleList);
-
- WriteBatch wb = new WriteBatch();
- wb.put("key".getBytes(), "value".getBytes());
- rDb.write(new WriteOptions(), wb);
+ RocksDB db = null;
+ RocksDB rDb = null;
+ Options options = null;
+ 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);
+
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+
+ rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ WriteBatch wb = new WriteBatch();
+ wb.put("key".getBytes(), "value".getBytes());
+ rDb.write(new WriteOptions(), wb);
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (rDb != null) {
+ rDb.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test(expected = RocksDBException.class)
public void failToCFWriteBatchReadOnly() throws RocksDBException {
- List cfDescriptors = new ArrayList<>();
- cfDescriptors.add(
- new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
- new ColumnFamilyOptions()));
- List readOnlyColumnFamilyHandleList =
- new ArrayList<>();
-
- Options options = new Options();
- options.setCreateIfMissing(true);
-
- RocksDB db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.close();
-
- RocksDB rDb = RocksDB.openReadOnly(
- dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
- readOnlyColumnFamilyHandleList);
-
- WriteBatch wb = new WriteBatch();
- wb.put(readOnlyColumnFamilyHandleList.get(0),
- "key".getBytes(), "value".getBytes());
- rDb.write(new WriteOptions(), wb);
+ RocksDB db = null;
+ RocksDB rDb = null;
+ Options options = null;
+ WriteBatch wb = null;
+ 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);
+
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.close();
+
+ rDb = RocksDB.openReadOnly(
+ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
+ readOnlyColumnFamilyHandleList);
+
+ wb = new WriteBatch();
+ wb.put(readOnlyColumnFamilyHandleList.get(0),
+ "key".getBytes(), "value".getBytes());
+ rDb.write(new WriteOptions(), wb);
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (rDb != null) {
+ rDb.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ if (wb != null) {
+ wb.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/ReadOptionsTest.java b/java/org/rocksdb/test/ReadOptionsTest.java
index 5b58fe5e9..80ea765c5 100644
--- a/java/org/rocksdb/test/ReadOptionsTest.java
+++ b/java/org/rocksdb/test/ReadOptionsTest.java
@@ -25,32 +25,66 @@ public class ReadOptionsTest {
public ExpectedException exception = ExpectedException.none();
@Test
- public void readOptions() {
- ReadOptions opt = new ReadOptions();
- Random rand = new Random();
- { // VerifyChecksums test
+ public void verifyChecksum(){
+ ReadOptions opt = null;
+ try {
+ opt = new ReadOptions();
+ Random rand = new Random();
boolean boolValue = rand.nextBoolean();
opt.setVerifyChecksums(boolValue);
assertThat(opt.verifyChecksums()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // FillCache test
+ @Test
+ public void fillCache(){
+ ReadOptions opt = null;
+ try {
+ opt = new ReadOptions();
+ Random rand = new Random();
boolean boolValue = rand.nextBoolean();
opt.setFillCache(boolValue);
assertThat(opt.fillCache()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // Tailing test
+ @Test
+ public void tailing(){
+ ReadOptions opt = null;
+ try {
+ opt = new ReadOptions();
+ Random rand = new Random();
boolean boolValue = rand.nextBoolean();
opt.setTailing(boolValue);
assertThat(opt.tailing()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // Snapshot null test
+ @Test
+ public void snapshot(){
+ ReadOptions opt = null;
+ try {
+ opt = new ReadOptions();
+ Random rand = new Random();
opt.setSnapshot(null);
assertThat(opt.snapshot()).isNull();
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
- opt.dispose();
}
@Test
diff --git a/java/org/rocksdb/test/RocksEnvTest.java b/java/org/rocksdb/test/RocksEnvTest.java
new file mode 100644
index 000000000..f55e9042e
--- /dev/null
+++ b/java/org/rocksdb/test/RocksEnvTest.java
@@ -0,0 +1,39 @@
+// Copyright (c) 2014, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+
+package org.rocksdb.test;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.rocksdb.RocksEnv;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RocksEnvTest {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Test
+ public void rocksEnv(){
+ RocksEnv rocksEnv = RocksEnv.getDefault();
+ rocksEnv.setBackgroundThreads(5);
+ // default rocksenv will always return zero for flush pool
+ // no matter what was set via setBackgroundThreads
+ assertThat(rocksEnv.getThreadPoolQueueLen(RocksEnv.FLUSH_POOL)).
+ isEqualTo(0);
+ rocksEnv.setBackgroundThreads(5, RocksEnv.FLUSH_POOL);
+ // default rocksenv will always return zero for flush pool
+ // no matter what was set via setBackgroundThreads
+ assertThat(rocksEnv.getThreadPoolQueueLen(RocksEnv.FLUSH_POOL)).
+ isEqualTo(0);
+ rocksEnv.setBackgroundThreads(5, RocksEnv.COMPACTION_POOL);
+ // default rocksenv will always return zero for compaction pool
+ // no matter what was set via setBackgroundThreads
+ assertThat(rocksEnv.getThreadPoolQueueLen(RocksEnv.COMPACTION_POOL)).
+ isEqualTo(0);
+ }
+}
diff --git a/java/org/rocksdb/test/RocksIteratorTest.java b/java/org/rocksdb/test/RocksIteratorTest.java
index 961b7c789..448e8f397 100644
--- a/java/org/rocksdb/test/RocksIteratorTest.java
+++ b/java/org/rocksdb/test/RocksIteratorTest.java
@@ -26,61 +26,83 @@ public class RocksIteratorTest {
@Test
public void rocksIterator() throws RocksDBException {
- RocksDB db;
- Options options = new Options();
- options.setCreateIfMissing(true)
- .setCreateMissingColumnFamilies(true);
- db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.put("key1".getBytes(), "value1".getBytes());
- db.put("key2".getBytes(), "value2".getBytes());
+ RocksDB db = null;
+ Options options = null;
+ RocksIterator iterator = null;
+ try {
+ options = new Options();
+ options.setCreateIfMissing(true)
+ .setCreateMissingColumnFamilies(true);
+ db = RocksDB.open(options,
+ dbFolder.getRoot().getAbsolutePath());
+ db.put("key1".getBytes(), "value1".getBytes());
+ db.put("key2".getBytes(), "value2".getBytes());
- RocksIterator iterator = db.newIterator();
+ iterator = db.newIterator();
- iterator.seekToFirst();
- assertThat(iterator.isValid()).isTrue();
- assertThat(iterator.key()).isEqualTo("key1".getBytes());
- assertThat(iterator.value()).isEqualTo("value1".getBytes());
- iterator.next();
- assertThat(iterator.isValid()).isTrue();
- assertThat(iterator.key()).isEqualTo("key2".getBytes());
- assertThat(iterator.value()).isEqualTo("value2".getBytes());
- iterator.next();
- assertThat(iterator.isValid()).isFalse();
- iterator.seekToLast();
- iterator.prev();
- assertThat(iterator.isValid()).isTrue();
- assertThat(iterator.key()).isEqualTo("key1".getBytes());
- assertThat(iterator.value()).isEqualTo("value1".getBytes());
- iterator.seekToFirst();
- iterator.seekToLast();
- assertThat(iterator.isValid()).isTrue();
- assertThat(iterator.key()).isEqualTo("key2".getBytes());
- assertThat(iterator.value()).isEqualTo("value2".getBytes());
- iterator.status();
+ iterator.seekToFirst();
+ assertThat(iterator.isValid()).isTrue();
+ assertThat(iterator.key()).isEqualTo("key1".getBytes());
+ assertThat(iterator.value()).isEqualTo("value1".getBytes());
+ iterator.next();
+ assertThat(iterator.isValid()).isTrue();
+ assertThat(iterator.key()).isEqualTo("key2".getBytes());
+ assertThat(iterator.value()).isEqualTo("value2".getBytes());
+ iterator.next();
+ assertThat(iterator.isValid()).isFalse();
+ iterator.seekToLast();
+ iterator.prev();
+ assertThat(iterator.isValid()).isTrue();
+ assertThat(iterator.key()).isEqualTo("key1".getBytes());
+ assertThat(iterator.value()).isEqualTo("value1".getBytes());
+ iterator.seekToFirst();
+ iterator.seekToLast();
+ assertThat(iterator.isValid()).isTrue();
+ assertThat(iterator.key()).isEqualTo("key2".getBytes());
+ assertThat(iterator.value()).isEqualTo("value2".getBytes());
+ iterator.status();
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ if (iterator != null) {
+ iterator.dispose();
+ }
+ }
}
@Test
public void rocksIteratorGc()
throws RocksDBException {
- RocksDB db;
- Options options = new Options();
- options.setCreateIfMissing(true)
- .setCreateMissingColumnFamilies(true);
- db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath());
- db.put("key".getBytes(), "value".getBytes());
- RocksIterator iter = db.newIterator();
- RocksIterator iter2 = db.newIterator();
- RocksIterator iter3 = db.newIterator();
- iter = null;
- db.close();
- db = null;
- iter2 = null;
- System.gc();
- System.runFinalization();
- iter3.dispose();
- System.gc();
- System.runFinalization();
+ 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) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/SnapshotTest.java b/java/org/rocksdb/test/SnapshotTest.java
index 7140a1fcb..1b45c517e 100644
--- a/java/org/rocksdb/test/SnapshotTest.java
+++ b/java/org/rocksdb/test/SnapshotTest.java
@@ -27,58 +27,71 @@ public class SnapshotTest {
@Test
public void snapshots() throws RocksDBException {
- RocksDB db;
- Options options = new Options();
- options.setCreateIfMissing(true);
+ RocksDB db = null;
+ Options options = null;
+ ReadOptions readOptions = null;
+ try {
- db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
- db.put("key".getBytes(), "value".getBytes());
- // Get new Snapshot of database
- Snapshot snapshot = db.getSnapshot();
- ReadOptions readOptions = new ReadOptions();
- // set snapshot in ReadOptions
- readOptions.setSnapshot(snapshot);
- // retrieve key value pair
- assertThat(new String(db.get("key".getBytes()))).
- isEqualTo("value");
- // retrieve key value pair created before
- // the snapshot was made
- assertThat(new String(db.get(readOptions,
- "key".getBytes()))).isEqualTo("value");
- // add new key/value pair
- db.put("newkey".getBytes(), "newvalue".getBytes());
- // using no snapshot the latest db entries
- // will be taken into account
- assertThat(new String(db.get("newkey".getBytes()))).
- isEqualTo("newvalue");
- // snapshopot was created before newkey
- assertThat(db.get(readOptions, "newkey".getBytes())).
- isNull();
- // Retrieve snapshot from read options
- Snapshot sameSnapshot = readOptions.snapshot();
- readOptions.setSnapshot(sameSnapshot);
- // results must be the same with new Snapshot
- // instance using the same native pointer
- assertThat(new String(db.get(readOptions,
- "key".getBytes()))).isEqualTo("value");
- // update key value pair to newvalue
- db.put("key".getBytes(), "newvalue".getBytes());
- // read with previously created snapshot will
- // read previous version of key value pair
- assertThat(new String(db.get(readOptions,
- "key".getBytes()))).isEqualTo("value");
- // read for newkey using the snapshot must be
- // null
- assertThat(db.get(readOptions, "newkey".getBytes())).
- isNull();
- // setting null to snapshot in ReadOptions leads
- // to no Snapshot being used.
- readOptions.setSnapshot(null);
- assertThat(new String(db.get(readOptions,
- "newkey".getBytes()))).isEqualTo("newvalue");
- // release Snapshot
- db.releaseSnapshot(snapshot);
- // Close database
- db.close();
+ options = new Options();
+ options.setCreateIfMissing(true);
+
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
+ db.put("key".getBytes(), "value".getBytes());
+ // Get new Snapshot of database
+ Snapshot snapshot = db.getSnapshot();
+ readOptions = new ReadOptions();
+ // set snapshot in ReadOptions
+ readOptions.setSnapshot(snapshot);
+ // retrieve key value pair
+ assertThat(new String(db.get("key".getBytes()))).
+ isEqualTo("value");
+ // retrieve key value pair created before
+ // the snapshot was made
+ assertThat(new String(db.get(readOptions,
+ "key".getBytes()))).isEqualTo("value");
+ // add new key/value pair
+ db.put("newkey".getBytes(), "newvalue".getBytes());
+ // using no snapshot the latest db entries
+ // will be taken into account
+ assertThat(new String(db.get("newkey".getBytes()))).
+ isEqualTo("newvalue");
+ // snapshopot was created before newkey
+ assertThat(db.get(readOptions, "newkey".getBytes())).
+ isNull();
+ // Retrieve snapshot from read options
+ Snapshot sameSnapshot = readOptions.snapshot();
+ readOptions.setSnapshot(sameSnapshot);
+ // results must be the same with new Snapshot
+ // instance using the same native pointer
+ assertThat(new String(db.get(readOptions,
+ "key".getBytes()))).isEqualTo("value");
+ // update key value pair to newvalue
+ db.put("key".getBytes(), "newvalue".getBytes());
+ // read with previously created snapshot will
+ // read previous version of key value pair
+ assertThat(new String(db.get(readOptions,
+ "key".getBytes()))).isEqualTo("value");
+ // read for newkey using the snapshot must be
+ // null
+ assertThat(db.get(readOptions, "newkey".getBytes())).
+ isNull();
+ // setting null to snapshot in ReadOptions leads
+ // to no Snapshot being used.
+ readOptions.setSnapshot(null);
+ assertThat(new String(db.get(readOptions,
+ "newkey".getBytes()))).isEqualTo("newvalue");
+ // release Snapshot
+ db.releaseSnapshot(snapshot);
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ if (readOptions != null) {
+ readOptions.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/StatisticsCollectorTest.java b/java/org/rocksdb/test/StatisticsCollectorTest.java
index 57842af10..ba84857ba 100644
--- a/java/org/rocksdb/test/StatisticsCollectorTest.java
+++ b/java/org/rocksdb/test/StatisticsCollectorTest.java
@@ -27,27 +27,35 @@ public class StatisticsCollectorTest {
@Test
public void statisticsCollector()
throws InterruptedException, RocksDBException {
- Options opt = new Options().createStatistics().setCreateIfMissing(true);
- Statistics stats = opt.statisticsPtr();
-
- RocksDB db = RocksDB.open(opt,
- dbFolder.getRoot().getAbsolutePath());
-
- StatsCallbackMock callback = new StatsCallbackMock();
- StatsCollectorInput statsInput = new StatsCollectorInput(stats, callback);
-
- StatisticsCollector statsCollector = new StatisticsCollector(
- Collections.singletonList(statsInput), 100);
- statsCollector.start();
-
- Thread.sleep(1000);
-
- assertThat(callback.tickerCallbackCount).isGreaterThan(0);
- assertThat(callback.histCallbackCount).isGreaterThan(0);
-
- statsCollector.shutDown(1000);
-
- db.close();
- opt.dispose();
+ Options opt = null;
+ RocksDB db = null;
+ try {
+ opt = new Options().createStatistics().setCreateIfMissing(true);
+ Statistics stats = opt.statisticsPtr();
+
+ db = RocksDB.open(opt,
+ dbFolder.getRoot().getAbsolutePath());
+
+ StatsCallbackMock callback = new StatsCallbackMock();
+ StatsCollectorInput statsInput = new StatsCollectorInput(stats, callback);
+
+ StatisticsCollector statsCollector = new StatisticsCollector(
+ Collections.singletonList(statsInput), 100);
+ statsCollector.start();
+
+ Thread.sleep(1000);
+
+ assertThat(callback.tickerCallbackCount).isGreaterThan(0);
+ assertThat(callback.histCallbackCount).isGreaterThan(0);
+
+ statsCollector.shutDown(1000);
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
}
}
diff --git a/java/rocksjni/backupablejni.cc b/java/rocksjni/backupablejni.cc
index 41390c5bc..609cbd73e 100644
--- a/java/rocksjni/backupablejni.cc
+++ b/java/rocksjni/backupablejni.cc
@@ -124,7 +124,7 @@ void Java_org_rocksdb_BackupableDBOptions_newBackupableDBOptions(
* Signature: (J)Ljava/lang/String;
*/
jstring Java_org_rocksdb_BackupableDBOptions_backupDir(
- JNIEnv* env, jobject jopt, jlong jhandle, jstring jpath) {
+ JNIEnv* env, jobject jopt, jlong jhandle) {
auto bopt = reinterpret_cast(jhandle);
return env->NewStringUTF(bopt->backup_dir.c_str());
}
diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc
index 109930cdc..d725cc305 100644
--- a/java/rocksjni/options.cc
+++ b/java/rocksjni/options.cc
@@ -274,6 +274,17 @@ void Java_org_rocksdb_Options_setParanoidChecks(
static_cast(paranoid_checks);
}
+/*
+ * Class: org_rocksdb_Options
+ * Method: setEnv
+ * Signature: (JJ)V
+ */
+void Java_org_rocksdb_Options_setEnv(
+ JNIEnv* env, jobject jobj, jlong jhandle, jlong jenv) {
+ reinterpret_cast(jhandle)->env =
+ reinterpret_cast(jenv);
+}
+
/*
* Class: org_rocksdb_Options
* Method: setMaxTotalWalSize
From 74057d6d2d9fd288c0bb454cad786055714c3b32 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Fri, 7 Nov 2014 23:31:38 +0100
Subject: [PATCH 08/12] [RocksJava] Improved tests within RocksJava
---
java/Makefile | 1 +
java/org/rocksdb/RocksDB.java | 1 +
java/org/rocksdb/RocksEnv.java | 3 +-
.../test/BlockBasedTableConfigTest.java | 108 +++-
java/org/rocksdb/test/DBOptionsTest.java | 379 ++++++++++++--
java/org/rocksdb/test/EnvironmentTest.java | 20 +-
java/org/rocksdb/test/OptionsTest.java | 488 +++++++++++++++++-
.../rocksdb/test/PlainTableConfigTest.java | 54 +-
java/org/rocksdb/test/ReadOptionsTest.java | 10 +-
java/org/rocksdb/test/RocksDBTest.java | 282 ++++++++++
java/org/rocksdb/test/SizeUnitTest.java | 28 +
11 files changed, 1302 insertions(+), 72 deletions(-)
create mode 100644 java/org/rocksdb/test/RocksDBTest.java
create mode 100644 java/org/rocksdb/test/SizeUnitTest.java
diff --git a/java/Makefile b/java/Makefile
index 3c7b8bb1a..99664c6ef 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -66,6 +66,7 @@ JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
org.rocksdb.test.PlainTableConfigTest\
org.rocksdb.test.ReadOnlyTest\
org.rocksdb.test.ReadOptionsTest\
+ org.rocksdb.test.RocksDBTest\
org.rocksdb.test.RocksEnvTest\
org.rocksdb.test.RocksIteratorTest\
org.rocksdb.test.SnapshotTest\
diff --git a/java/org/rocksdb/RocksDB.java b/java/org/rocksdb/RocksDB.java
index 730c1940d..5fcfd2ff4 100644
--- a/java/org/rocksdb/RocksDB.java
+++ b/java/org/rocksdb/RocksDB.java
@@ -103,6 +103,7 @@ public class RocksDB extends RocksObject {
// This allows to use the rocksjni default Options instead of
// the c++ one.
Options options = new Options();
+ options.setCreateIfMissing(true);
return open(options, path);
}
diff --git a/java/org/rocksdb/RocksEnv.java b/java/org/rocksdb/RocksEnv.java
index 5bbf4fb3d..bb19eb732 100644
--- a/java/org/rocksdb/RocksEnv.java
+++ b/java/org/rocksdb/RocksEnv.java
@@ -18,6 +18,7 @@ public class RocksEnv extends RocksObject {
static {
default_env_ = new RocksEnv(getDefaultEnvInternal());
+
}
private static native long getDefaultEnvInternal();
@@ -101,7 +102,7 @@ public class RocksEnv extends RocksObject {
* {@link RocksObject} must implement to release their associated C++
* resource.
*/
- protected void disposeInternal() {
+ @Override protected void disposeInternal() {
disposeInternal(nativeHandle_);
}
private native void disposeInternal(long handle);
diff --git a/java/org/rocksdb/test/BlockBasedTableConfigTest.java b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
index 143a3fa14..241429542 100644
--- a/java/org/rocksdb/test/BlockBasedTableConfigTest.java
+++ b/java/org/rocksdb/test/BlockBasedTableConfigTest.java
@@ -18,65 +18,145 @@ public class BlockBasedTableConfigTest {
new RocksMemoryResource();
@Test
- public void blockBasedTableConfig() {
- BlockBasedTableConfig blockBasedTableConfig =
- new BlockBasedTableConfig();
+ public void noBlockCache() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setNoBlockCache(true);
assertThat(blockBasedTableConfig.noBlockCache()).isTrue();
+ }
+
+ @Test
+ public void blockCacheSize() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setBlockCacheSize(8 * 1024);
assertThat(blockBasedTableConfig.blockCacheSize()).
isEqualTo(8 * 1024);
+ }
+
+ @Test
+ public void blockSizeDeviation() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setBlockSizeDeviation(12);
assertThat(blockBasedTableConfig.blockSizeDeviation()).
isEqualTo(12);
+ }
+
+ @Test
+ public void blockRestartInterval() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setBlockRestartInterval(15);
assertThat(blockBasedTableConfig.blockRestartInterval()).
isEqualTo(15);
+ }
+
+ @Test
+ public void wholeKeyFiltering() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setWholeKeyFiltering(false);
assertThat(blockBasedTableConfig.wholeKeyFiltering()).
isFalse();
+ }
+
+ @Test
+ public void cacheIndexAndFilterBlocks() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setCacheIndexAndFilterBlocks(true);
assertThat(blockBasedTableConfig.cacheIndexAndFilterBlocks()).
isTrue();
+
+ }
+
+ @Test
+ public void hashIndexAllowCollision() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setHashIndexAllowCollision(false);
assertThat(blockBasedTableConfig.hashIndexAllowCollision()).
isFalse();
+ }
+
+ @Test
+ public void blockCacheCompressedSize() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setBlockCacheCompressedSize(40);
assertThat(blockBasedTableConfig.blockCacheCompressedSize()).
isEqualTo(40);
+ }
+
+ @Test
+ public void checksumType() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setChecksumType(ChecksumType.kNoChecksum);
blockBasedTableConfig.setChecksumType(ChecksumType.kxxHash);
assertThat(blockBasedTableConfig.checksumType().equals(
ChecksumType.kxxHash));
+ }
+
+ @Test
+ public void indexType() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
+ assertThat(IndexType.values().length).isEqualTo(2);
blockBasedTableConfig.setIndexType(IndexType.kHashSearch);
assertThat(blockBasedTableConfig.indexType().equals(
IndexType.kHashSearch));
+ assertThat(IndexType.valueOf("kBinarySearch")).isNotNull();
+ blockBasedTableConfig.setIndexType(IndexType.valueOf("kBinarySearch"));
+ assertThat(blockBasedTableConfig.indexType().equals(
+ IndexType.kBinarySearch));
+ }
+
+ @Test
+ public void blockCacheCompressedNumShardBits() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setBlockCacheCompressedNumShardBits(4);
assertThat(blockBasedTableConfig.blockCacheCompressedNumShardBits()).
isEqualTo(4);
+ }
+
+ @Test
+ public void cacheNumShardBits() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setCacheNumShardBits(5);
assertThat(blockBasedTableConfig.cacheNumShardBits()).
isEqualTo(5);
+ }
+
+ @Test
+ public void blockSize() {
+ BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
blockBasedTableConfig.setBlockSize(10);
assertThat(blockBasedTableConfig.blockSize()).isEqualTo(10);
}
+
@Test
public void blockBasedTableWithFilter() {
- Options options = new Options();
- options.setTableFormatConfig(
- new BlockBasedTableConfig().setFilter(
- new BloomFilter(10)));
- assertThat(options.tableFactoryName()).
- isEqualTo("BlockBasedTable");
+ Options options = null;
+ try {
+ options = new Options();
+ options.setTableFormatConfig(
+ new BlockBasedTableConfig().setFilter(
+ new BloomFilter(10)));
+ assertThat(options.tableFactoryName()).
+ isEqualTo("BlockBasedTable");
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
@Test
public void blockBasedTableWithoutFilter() {
- Options options = new Options();
- options.setTableFormatConfig(
- new BlockBasedTableConfig().setFilter(null));
- assertThat(options.tableFactoryName()).
- isEqualTo("BlockBasedTable");
+ Options options = null;
+ try {
+ options = new Options();
+ options.setTableFormatConfig(
+ new BlockBasedTableConfig().setFilter(null));
+ assertThat(options.tableFactoryName()).
+ isEqualTo("BlockBasedTable");
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/DBOptionsTest.java b/java/org/rocksdb/test/DBOptionsTest.java
index 529a9b09b..9a15658e7 100644
--- a/java/org/rocksdb/test/DBOptionsTest.java
+++ b/java/org/rocksdb/test/DBOptionsTest.java
@@ -19,227 +19,508 @@ public class DBOptionsTest {
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
- @Test
- public void dbOptions() throws RocksDBException {
- testDBOptions(new DBOptions());
- }
+ public static final Random rand = PlatformRandomHelper.
+ getPlatformSpecificRandomFactory();
- static void testDBOptions(DBOptionsInterface opt) throws RocksDBException {
- Random rand = PlatformRandomHelper.
- getPlatformSpecificRandomFactory();
- { // CreateIfMissing test
+ @Test
+ public void createIfMissing() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setCreateIfMissing(boolValue);
assertThat(opt.createIfMissing()).
isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // CreateMissingColumnFamilies test
+ @Test
+ public void createMissingColumnFamilies() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setCreateMissingColumnFamilies(boolValue);
assertThat(opt.createMissingColumnFamilies()).
isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // ErrorIfExists test
+ @Test
+ public void errorIfExists() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setErrorIfExists(boolValue);
assertThat(opt.errorIfExists()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // ParanoidChecks test
+ @Test
+ public void paranoidChecks() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setParanoidChecks(boolValue);
assertThat(opt.paranoidChecks()).
isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- {
- // MaxTotalWalSize test
+ @Test
+ public void maxTotalWalSize() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setMaxTotalWalSize(longValue);
assertThat(opt.maxTotalWalSize()).
isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxOpenFiles test
+ @Test
+ public void maxOpenFiles() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
int intValue = rand.nextInt();
opt.setMaxOpenFiles(intValue);
assertThat(opt.maxOpenFiles()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // DisableDataSync test
+ @Test
+ public void disableDataSync() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setDisableDataSync(boolValue);
assertThat(opt.disableDataSync()).
isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // UseFsync test
+ @Test
+ public void useFsync() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setUseFsync(boolValue);
assertThat(opt.useFsync()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // DbLogDir test
+ @Test
+ public void dbLogDir() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
String str = "path/to/DbLogDir";
opt.setDbLogDir(str);
assertThat(opt.dbLogDir()).isEqualTo(str);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // WalDir test
+ @Test
+ public void walDir() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
String str = "path/to/WalDir";
opt.setWalDir(str);
assertThat(opt.walDir()).isEqualTo(str);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // DeleteObsoleteFilesPeriodMicros test
+ @Test
+ public void deleteObsoleteFilesPeriodMicros() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setDeleteObsoleteFilesPeriodMicros(longValue);
assertThat(opt.deleteObsoleteFilesPeriodMicros()).
isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxBackgroundCompactions test
+ @Test
+ public void maxBackgroundCompactions() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
int intValue = rand.nextInt();
opt.setMaxBackgroundCompactions(intValue);
assertThat(opt.maxBackgroundCompactions()).
isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxBackgroundFlushes test
+ @Test
+ public void maxBackgroundFlushes() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
int intValue = rand.nextInt();
opt.setMaxBackgroundFlushes(intValue);
assertThat(opt.maxBackgroundFlushes()).
isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxLogFileSize test
+ @Test
+ public void maxLogFileSize() throws RocksDBException {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setMaxLogFileSize(longValue);
assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // LogFileTimeToRoll test
+ @Test
+ public void logFileTimeToRoll() throws RocksDBException {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setLogFileTimeToRoll(longValue);
assertThat(opt.logFileTimeToRoll()).
isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // KeepLogFileNum test
+ @Test
+ public void keepLogFileNum() throws RocksDBException {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setKeepLogFileNum(longValue);
assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxManifestFileSize test
+ @Test
+ public void maxManifestFileSize() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setMaxManifestFileSize(longValue);
assertThat(opt.maxManifestFileSize()).
isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // TableCacheNumshardbits test
+ @Test
+ public void tableCacheNumshardbits() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
int intValue = rand.nextInt();
opt.setTableCacheNumshardbits(intValue);
assertThat(opt.tableCacheNumshardbits()).
isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // TableCacheRemoveScanCountLimit test
+ @Test
+ public void tableCacheRemoveScanCountLimit() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
int intValue = rand.nextInt();
opt.setTableCacheRemoveScanCountLimit(intValue);
assertThat(opt.tableCacheRemoveScanCountLimit()).
isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // WalSizeLimitMB test
+ @Test
+ public void walSizeLimitMB() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setWalSizeLimitMB(longValue);
assertThat(opt.walSizeLimitMB()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // WalTtlSeconds test
+ @Test
+ public void walTtlSeconds() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setWalTtlSeconds(longValue);
assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // ManifestPreallocationSize test
+ @Test
+ public void manifestPreallocationSize() throws RocksDBException {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setManifestPreallocationSize(longValue);
assertThat(opt.manifestPreallocationSize()).
isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // AllowOsBuffer test
+ @Test
+ public void allowOsBuffer() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setAllowOsBuffer(boolValue);
assertThat(opt.allowOsBuffer()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // AllowMmapReads test
+ @Test
+ public void allowMmapReads() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setAllowMmapReads(boolValue);
assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // AllowMmapWrites test
+ @Test
+ public void allowMmapWrites() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setAllowMmapWrites(boolValue);
assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // IsFdCloseOnExec test
+ @Test
+ public void isFdCloseOnExec() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setIsFdCloseOnExec(boolValue);
assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // SkipLogErrorOnRecovery test
+ @Test
+ public void skipLogErrorOnRecovery() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setSkipLogErrorOnRecovery(boolValue);
assertThat(opt.skipLogErrorOnRecovery()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // StatsDumpPeriodSec test
+ @Test
+ public void statsDumpPeriodSec() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
int intValue = rand.nextInt();
opt.setStatsDumpPeriodSec(intValue);
assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // AdviseRandomOnOpen test
+ @Test
+ public void adviseRandomOnOpen() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setAdviseRandomOnOpen(boolValue);
assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // UseAdaptiveMutex test
+ @Test
+ public void useAdaptiveMutex() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
boolean boolValue = rand.nextBoolean();
opt.setUseAdaptiveMutex(boolValue);
assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // BytesPerSync test
+ @Test
+ public void bytesPerSync() {
+ DBOptions opt = null;
+ try {
+ opt = new DBOptions();
long longValue = rand.nextLong();
opt.setBytesPerSync(longValue);
assertThat(opt.bytesPerSync()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
}
@Test
public void rateLimiterConfig() {
- DBOptions options = new DBOptions();
- RateLimiterConfig rateLimiterConfig =
- new GenericRateLimiterConfig(1000, 0, 1);
- options.setRateLimiterConfig(rateLimiterConfig);
- options.dispose();
- // Test with parameter initialization
- DBOptions anotherOptions = new DBOptions();
- anotherOptions.setRateLimiterConfig(
- new GenericRateLimiterConfig(1000));
- anotherOptions.dispose();
+ DBOptions options = null;
+ DBOptions anotherOptions = null;
+ try {
+ options = new DBOptions();
+ RateLimiterConfig rateLimiterConfig =
+ new GenericRateLimiterConfig(1000, 0, 1);
+ options.setRateLimiterConfig(rateLimiterConfig);
+ // Test with parameter initialization
+ anotherOptions = new DBOptions();
+ anotherOptions.setRateLimiterConfig(
+ new GenericRateLimiterConfig(1000));
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ if (anotherOptions != null) {
+ anotherOptions.dispose();
+ }
+ }
}
@Test
diff --git a/java/org/rocksdb/test/EnvironmentTest.java b/java/org/rocksdb/test/EnvironmentTest.java
index c6542afed..b5af069da 100644
--- a/java/org/rocksdb/test/EnvironmentTest.java
+++ b/java/org/rocksdb/test/EnvironmentTest.java
@@ -1,3 +1,7 @@
+// Copyright (c) 2014, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
package org.rocksdb.test;
import org.junit.Test;
@@ -17,6 +21,7 @@ public class EnvironmentTest {
@Test
public void mac32() {
setEnvironmentClassFields("mac", "32");
+ assertThat(Environment.isWindows()).isFalse();
assertThat(Environment.getJniLibraryExtension()).
isEqualTo(".jnilib");
assertThat(Environment.getJniLibraryName("rocksdb")).
@@ -28,6 +33,7 @@ public class EnvironmentTest {
@Test
public void mac64() {
setEnvironmentClassFields("mac", "64");
+ assertThat(Environment.isWindows()).isFalse();
assertThat(Environment.getJniLibraryExtension()).
isEqualTo(".jnilib");
assertThat(Environment.getJniLibraryName("rocksdb")).
@@ -40,6 +46,7 @@ public class EnvironmentTest {
public void nix32() {
// Linux
setEnvironmentClassFields("Linux", "32");
+ assertThat(Environment.isWindows()).isFalse();
assertThat(Environment.getJniLibraryExtension()).
isEqualTo(".so");
assertThat(Environment.getJniLibraryName("rocksdb")).
@@ -48,6 +55,7 @@ public class EnvironmentTest {
isEqualTo("librocksdbjni.so");
// UNIX
setEnvironmentClassFields("Unix", "32");
+ assertThat(Environment.isWindows()).isFalse();
assertThat(Environment.getJniLibraryExtension()).
isEqualTo(".so");
assertThat(Environment.getJniLibraryName("rocksdb")).
@@ -56,6 +64,7 @@ public class EnvironmentTest {
isEqualTo("librocksdbjni.so");
// AIX
setEnvironmentClassFields("aix", "32");
+ assertThat(Environment.isWindows()).isFalse();
assertThat(Environment.getJniLibraryExtension()).
isEqualTo(".so");
assertThat(Environment.getJniLibraryName("rocksdb")).
@@ -67,6 +76,7 @@ public class EnvironmentTest {
@Test
public void nix64() {
setEnvironmentClassFields("Linux", "x64");
+ assertThat(Environment.isWindows()).isFalse();
assertThat(Environment.getJniLibraryExtension()).
isEqualTo(".so");
assertThat(Environment.getJniLibraryName("rocksdb")).
@@ -75,6 +85,7 @@ public class EnvironmentTest {
isEqualTo("librocksdbjni.so");
// UNIX
setEnvironmentClassFields("Unix", "x64");
+ assertThat(Environment.isWindows()).isFalse();
assertThat(Environment.getJniLibraryExtension()).
isEqualTo(".so");
assertThat(Environment.getJniLibraryName("rocksdb")).
@@ -83,6 +94,7 @@ public class EnvironmentTest {
isEqualTo("librocksdbjni.so");
// AIX
setEnvironmentClassFields("aix", "x64");
+ assertThat(Environment.isWindows()).isFalse();
assertThat(Environment.getJniLibraryExtension()).
isEqualTo(".so");
assertThat(Environment.getJniLibraryName("rocksdb")).
@@ -91,8 +103,14 @@ public class EnvironmentTest {
isEqualTo("librocksdbjni.so");
}
+ @Test
+ public void detectWindows(){
+ setEnvironmentClassFields("win", "x64");
+ assertThat(Environment.isWindows()).isTrue();
+ }
+
@Test(expected = UnsupportedOperationException.class)
- public void failLinuxJniLibraryName(){
+ public void failWinJniLibraryName(){
setEnvironmentClassFields("win", "x64");
Environment.getJniLibraryName("rocksdb");
}
diff --git a/java/org/rocksdb/test/OptionsTest.java b/java/org/rocksdb/test/OptionsTest.java
index 24dd5081c..a7241e822 100644
--- a/java/org/rocksdb/test/OptionsTest.java
+++ b/java/org/rocksdb/test/OptionsTest.java
@@ -19,14 +19,14 @@ public class OptionsTest {
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
+ public static final Random rand = PlatformRandomHelper.
+ getPlatformSpecificRandomFactory();
+
@Test
public void options() throws RocksDBException {
Options opt = null;
try {
opt = new Options();
- Random rand = PlatformRandomHelper.
- getPlatformSpecificRandomFactory();
- DBOptionsTest.testDBOptions(opt);
{ // WriteBufferSize test
long longValue = rand.nextLong();
@@ -220,6 +220,484 @@ public class OptionsTest {
}
}
+ @Test
+ public void createIfMissing() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setCreateIfMissing(boolValue);
+ assertThat(opt.createIfMissing()).
+ isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void createMissingColumnFamilies() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setCreateMissingColumnFamilies(boolValue);
+ assertThat(opt.createMissingColumnFamilies()).
+ isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void errorIfExists() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setErrorIfExists(boolValue);
+ assertThat(opt.errorIfExists()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void paranoidChecks() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setParanoidChecks(boolValue);
+ assertThat(opt.paranoidChecks()).
+ isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void maxTotalWalSize() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setMaxTotalWalSize(longValue);
+ assertThat(opt.maxTotalWalSize()).
+ isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void maxOpenFiles() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMaxOpenFiles(intValue);
+ assertThat(opt.maxOpenFiles()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void disableDataSync() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setDisableDataSync(boolValue);
+ assertThat(opt.disableDataSync()).
+ isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void useFsync() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setUseFsync(boolValue);
+ assertThat(opt.useFsync()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void dbLogDir() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ String str = "path/to/DbLogDir";
+ opt.setDbLogDir(str);
+ assertThat(opt.dbLogDir()).isEqualTo(str);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void walDir() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ String str = "path/to/WalDir";
+ opt.setWalDir(str);
+ assertThat(opt.walDir()).isEqualTo(str);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void deleteObsoleteFilesPeriodMicros() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setDeleteObsoleteFilesPeriodMicros(longValue);
+ assertThat(opt.deleteObsoleteFilesPeriodMicros()).
+ isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void maxBackgroundCompactions() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMaxBackgroundCompactions(intValue);
+ assertThat(opt.maxBackgroundCompactions()).
+ isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void maxBackgroundFlushes() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMaxBackgroundFlushes(intValue);
+ assertThat(opt.maxBackgroundFlushes()).
+ isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void maxLogFileSize() throws RocksDBException {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setMaxLogFileSize(longValue);
+ assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void logFileTimeToRoll() throws RocksDBException {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setLogFileTimeToRoll(longValue);
+ assertThat(opt.logFileTimeToRoll()).
+ isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void keepLogFileNum() throws RocksDBException {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setKeepLogFileNum(longValue);
+ assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void maxManifestFileSize() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setMaxManifestFileSize(longValue);
+ assertThat(opt.maxManifestFileSize()).
+ isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void tableCacheNumshardbits() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setTableCacheNumshardbits(intValue);
+ assertThat(opt.tableCacheNumshardbits()).
+ isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void tableCacheRemoveScanCountLimit() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setTableCacheRemoveScanCountLimit(intValue);
+ assertThat(opt.tableCacheRemoveScanCountLimit()).
+ isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void walSizeLimitMB() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setWalSizeLimitMB(longValue);
+ assertThat(opt.walSizeLimitMB()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void walTtlSeconds() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setWalTtlSeconds(longValue);
+ assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void manifestPreallocationSize() throws RocksDBException {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setManifestPreallocationSize(longValue);
+ assertThat(opt.manifestPreallocationSize()).
+ isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void allowOsBuffer() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setAllowOsBuffer(boolValue);
+ assertThat(opt.allowOsBuffer()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void allowMmapReads() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setAllowMmapReads(boolValue);
+ assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void allowMmapWrites() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setAllowMmapWrites(boolValue);
+ assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void isFdCloseOnExec() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setIsFdCloseOnExec(boolValue);
+ assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void skipLogErrorOnRecovery() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setSkipLogErrorOnRecovery(boolValue);
+ assertThat(opt.skipLogErrorOnRecovery()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void statsDumpPeriodSec() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setStatsDumpPeriodSec(intValue);
+ assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void adviseRandomOnOpen() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setAdviseRandomOnOpen(boolValue);
+ assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void useAdaptiveMutex() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setUseAdaptiveMutex(boolValue);
+ assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void bytesPerSync() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setBytesPerSync(longValue);
+ assertThat(opt.bytesPerSync()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
@Test
public void rocksEnv() {
Options options = null;
@@ -263,6 +741,8 @@ public class OptionsTest {
options.setCompressionType(compressionType);
assertThat(options.compressionType()).
isEqualTo(compressionType);
+ assertThat(CompressionType.valueOf("NO_COMPRESSION")).
+ isEqualTo(CompressionType.NO_COMPRESSION);
}
} finally {
if (options != null) {
@@ -281,6 +761,8 @@ public class OptionsTest {
options.setCompactionStyle(compactionStyle);
assertThat(options.compactionStyle()).
isEqualTo(compactionStyle);
+ assertThat(CompactionStyle.valueOf("FIFO")).
+ isEqualTo(CompactionStyle.FIFO);
}
} finally {
if (options != null) {
diff --git a/java/org/rocksdb/test/PlainTableConfigTest.java b/java/org/rocksdb/test/PlainTableConfigTest.java
index abd2cda12..72347e7d4 100644
--- a/java/org/rocksdb/test/PlainTableConfigTest.java
+++ b/java/org/rocksdb/test/PlainTableConfigTest.java
@@ -8,6 +8,7 @@ package org.rocksdb.test;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.EncodingType;
+import org.rocksdb.Options;
import org.rocksdb.PlainTableConfig;
import static org.assertj.core.api.Assertions.assertThat;
@@ -19,30 +20,79 @@ public class PlainTableConfigTest {
new RocksMemoryResource();
@Test
- public void plainTableConfig() {
+ public void keySize() {
PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setKeySize(5);
assertThat(plainTableConfig.keySize()).
isEqualTo(5);
+ }
+
+ @Test
+ public void bloomBitsPerKey() {
+ PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setBloomBitsPerKey(11);
assertThat(plainTableConfig.bloomBitsPerKey()).
isEqualTo(11);
+ }
+
+ @Test
+ public void hashTableRatio() {
+ PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setHashTableRatio(0.95);
assertThat(plainTableConfig.hashTableRatio()).
isEqualTo(0.95);
+ }
+
+ @Test
+ public void indexSparseness() {
+ PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setIndexSparseness(18);
assertThat(plainTableConfig.indexSparseness()).
isEqualTo(18);
+ }
+
+ @Test
+ public void hugePageTlbSize() {
+ PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setHugePageTlbSize(1);
assertThat(plainTableConfig.hugePageTlbSize()).
isEqualTo(1);
+ }
+
+ @Test
+ public void encodingType() {
+ PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setEncodingType(EncodingType.kPrefix);
assertThat(plainTableConfig.encodingType()).isEqualTo(
EncodingType.kPrefix);
+ }
+
+ @Test
+ public void fullScanMode() {
+ PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setFullScanMode(true);
- assertThat(plainTableConfig.fullScanMode()).isTrue();
+ assertThat(plainTableConfig.fullScanMode()).isTrue(); }
+
+ @Test
+ public void storeIndexInFile() {
+ PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setStoreIndexInFile(true);
assertThat(plainTableConfig.storeIndexInFile()).
isTrue();
}
+
+ @Test
+ public void plainTableConfig() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ PlainTableConfig plainTableConfig = new PlainTableConfig();
+ opt.setTableFormatConfig(plainTableConfig);
+ assertThat(opt.tableFactoryName()).isEqualTo("PlainTable");
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
}
diff --git a/java/org/rocksdb/test/ReadOptionsTest.java b/java/org/rocksdb/test/ReadOptionsTest.java
index 80ea765c5..2cf1584a1 100644
--- a/java/org/rocksdb/test/ReadOptionsTest.java
+++ b/java/org/rocksdb/test/ReadOptionsTest.java
@@ -77,7 +77,6 @@ public class ReadOptionsTest {
ReadOptions opt = null;
try {
opt = new ReadOptions();
- Random rand = new Random();
opt.setSnapshot(null);
assertThat(opt.snapshot()).isNull();
} finally {
@@ -88,12 +87,19 @@ public class ReadOptionsTest {
}
@Test
- public void failVerifyChecksumUninitialized(){
+ public void failSetVerifyChecksumUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setVerifyChecksums(true);
}
+ @Test
+ public void failVerifyChecksumUninitialized(){
+ ReadOptions readOptions = setupUninitializedReadOptions(
+ exception);
+ readOptions.verifyChecksums();
+ }
+
@Test
public void failSetFillCacheUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
diff --git a/java/org/rocksdb/test/RocksDBTest.java b/java/org/rocksdb/test/RocksDBTest.java
new file mode 100644
index 000000000..4f51e8b97
--- /dev/null
+++ b/java/org/rocksdb/test/RocksDBTest.java
@@ -0,0 +1,282 @@
+// Copyright (c) 2014, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+package org.rocksdb.test;
+
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.rocksdb.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RocksDBTest {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @Test
+ public void open() throws RocksDBException {
+ RocksDB db = null;
+ Options opt = null;
+ try {
+ db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
+ db.close();
+ opt = new Options();
+ opt.setCreateIfMissing(true);
+ db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void put() throws RocksDBException {
+ RocksDB db = null;
+ WriteOptions opt = null;
+ try {
+ db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
+ db.put("key1".getBytes(), "value".getBytes());
+ opt = new WriteOptions();
+ db.put(opt, "key2".getBytes(), "12345678".getBytes());
+ assertThat(db.get("key1".getBytes())).isEqualTo(
+ "value".getBytes());
+ assertThat(db.get("key2".getBytes())).isEqualTo(
+ "12345678".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void write() throws RocksDBException {
+ RocksDB db = null;
+ Options options = null;
+ WriteBatch wb1 = null;
+ WriteBatch wb2 = null;
+ WriteOptions opts = null;
+ try {
+ options = new Options().
+ setMergeOperator(new StringAppendOperator()).
+ setCreateIfMissing(true);
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
+ opts = new WriteOptions();
+ wb1 = new WriteBatch();
+ wb1.put("key1".getBytes(), "aa".getBytes());
+ wb1.merge("key1".getBytes(), "bb".getBytes());
+ wb2 = new WriteBatch();
+ wb2.put("key2".getBytes(), "xx".getBytes());
+ wb2.merge("key2".getBytes(), "yy".getBytes());
+ db.write(opts, wb1);
+ db.write(opts, wb2);
+ assertThat(db.get("key1".getBytes())).isEqualTo(
+ "aa,bb".getBytes());
+ assertThat(db.get("key2".getBytes())).isEqualTo(
+ "xx,yy".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (wb1 != null) {
+ wb1.dispose();
+ }
+ if (wb2 != null) {
+ wb2.dispose();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ if (opts != null) {
+ opts.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void getWithOutValue() throws RocksDBException {
+ RocksDB db = null;
+ try {
+ db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
+ db.put("key1".getBytes(), "value".getBytes());
+ db.put("key2".getBytes(), "12345678".getBytes());
+ byte[] outValue = new byte[5];
+ // not found value
+ int getResult = db.get("keyNotFound".getBytes(), outValue);
+ assertThat(getResult).isEqualTo(RocksDB.NOT_FOUND);
+ // found value which fits in outValue
+ getResult = db.get("key1".getBytes(), outValue);
+ assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
+ assertThat(outValue).isEqualTo("value".getBytes());
+ // found value which fits partially
+ getResult = db.get("key2".getBytes(), outValue);
+ assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
+ assertThat(outValue).isEqualTo("12345".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ }
+ }
+
+ @Test
+ public void getWithOutValueReadOptions() throws RocksDBException {
+ RocksDB db = null;
+ ReadOptions rOpt = null;
+ try {
+ db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
+ rOpt = new ReadOptions();
+ db.put("key1".getBytes(), "value".getBytes());
+ db.put("key2".getBytes(), "12345678".getBytes());
+ byte[] outValue = new byte[5];
+ // not found value
+ int getResult = db.get(rOpt, "keyNotFound".getBytes(),
+ outValue);
+ assertThat(getResult).isEqualTo(RocksDB.NOT_FOUND);
+ // found value which fits in outValue
+ getResult = db.get(rOpt, "key1".getBytes(), outValue);
+ assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
+ assertThat(outValue).isEqualTo("value".getBytes());
+ // found value which fits partially
+ getResult = db.get(rOpt, "key2".getBytes(), outValue);
+ assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
+ assertThat(outValue).isEqualTo("12345".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (rOpt != null) {
+ rOpt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void multiGet() throws RocksDBException {
+ RocksDB db = null;
+ ReadOptions rOpt = null;
+ try {
+ db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
+ rOpt = new ReadOptions();
+ db.put("key1".getBytes(), "value".getBytes());
+ db.put("key2".getBytes(), "12345678".getBytes());
+ List lookupKeys = new ArrayList() {{
+ add("key1".getBytes());
+ add("key2".getBytes());
+ }};
+ Map results = db.multiGet(lookupKeys);
+ assertThat(results).isNotNull();
+ assertThat(results.values()).isNotNull();
+ assertThat(results.values()).
+ contains("value".getBytes(), "12345678".getBytes());
+ // test same method with ReadOptions
+ results = db.multiGet(rOpt, lookupKeys);
+ assertThat(results).isNotNull();
+ assertThat(results.values()).isNotNull();
+ assertThat(results.values()).
+ contains("value".getBytes(), "12345678".getBytes());
+
+ // remove existing key
+ lookupKeys.remove("key2".getBytes());
+ // add non existing key
+ lookupKeys.add("key3".getBytes());
+ results = db.multiGet(lookupKeys);
+ assertThat(results).isNotNull();
+ assertThat(results.values()).isNotNull();
+ assertThat(results.values()).
+ contains("value".getBytes());
+ // test same call with readOptions
+ results = db.multiGet(rOpt, lookupKeys);
+ assertThat(results).isNotNull();
+ assertThat(results.values()).isNotNull();
+ assertThat(results.values()).
+ contains("value".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (rOpt != null) {
+ rOpt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void merge() throws RocksDBException {
+ RocksDB db = null;
+ Options opt = null;
+ WriteOptions wOpt;
+ try {
+ opt = new Options().
+ setCreateIfMissing(true).
+ setMergeOperator(new StringAppendOperator());
+ wOpt = new WriteOptions();
+ db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath());
+ db.put("key1".getBytes(), "value".getBytes());
+ assertThat(db.get("key1".getBytes())).isEqualTo(
+ "value".getBytes());
+ // merge key1 with another value portion
+ db.merge("key1".getBytes(), "value2".getBytes());
+ assertThat(db.get("key1".getBytes())).isEqualTo(
+ "value,value2".getBytes());
+ // merge key1 with another value portion
+ db.merge(wOpt, "key1".getBytes(), "value3".getBytes());
+ assertThat(db.get("key1".getBytes())).isEqualTo(
+ "value,value2,value3".getBytes());
+ // merge on non existent key shall insert the value
+ db.merge(wOpt, "key2".getBytes(), "xxxx".getBytes());
+ assertThat(db.get("key2".getBytes())).isEqualTo(
+ "xxxx".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void remove() throws RocksDBException {
+ RocksDB db = null;
+ WriteOptions wOpt;
+ try {
+ wOpt = new WriteOptions();
+ db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
+ db.put("key1".getBytes(), "value".getBytes());
+ db.put("key2".getBytes(), "12345678".getBytes());
+ assertThat(db.get("key1".getBytes())).isEqualTo(
+ "value".getBytes());
+ assertThat(db.get("key2".getBytes())).isEqualTo(
+ "12345678".getBytes());
+ db.remove("key1".getBytes());
+ db.remove(wOpt, "key2".getBytes());
+ assertThat(db.get("key1".getBytes())).isNull();
+ assertThat(db.get("key2".getBytes())).isNull();
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ }
+ }
+}
diff --git a/java/org/rocksdb/test/SizeUnitTest.java b/java/org/rocksdb/test/SizeUnitTest.java
new file mode 100644
index 000000000..16f636267
--- /dev/null
+++ b/java/org/rocksdb/test/SizeUnitTest.java
@@ -0,0 +1,28 @@
+// Copyright (c) 2014, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+package org.rocksdb.test;
+
+import org.junit.Test;
+import org.rocksdb.util.SizeUnit;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SizeUnitTest {
+
+ public static final long COMPUTATION_UNIT = 1024L;
+
+ @Test
+ public void sizeUnit() {
+ assertThat(SizeUnit.KB).isEqualTo(COMPUTATION_UNIT);
+ assertThat(SizeUnit.MB).isEqualTo(
+ SizeUnit.KB * COMPUTATION_UNIT);
+ assertThat(SizeUnit.GB).isEqualTo(
+ SizeUnit.MB * COMPUTATION_UNIT);
+ assertThat(SizeUnit.TB).isEqualTo(
+ SizeUnit.GB * COMPUTATION_UNIT);
+ assertThat(SizeUnit.PB).isEqualTo(
+ SizeUnit.TB * COMPUTATION_UNIT);
+ }
+}
From b6abab8b77608aa0dc0016ed02cfd09c7ccea55f Mon Sep 17 00:00:00 2001
From: fyrz
Date: Tue, 11 Nov 2014 08:49:00 +0100
Subject: [PATCH 09/12] [RocksJava] Merged & rebased to HEAD
---
java/org/rocksdb/test/KeyMayExistTest.java | 50 +++----------------
.../rocksdb/test/WriteBatchHandlerTest.java | 15 ++++--
2 files changed, 18 insertions(+), 47 deletions(-)
diff --git a/java/org/rocksdb/test/KeyMayExistTest.java b/java/org/rocksdb/test/KeyMayExistTest.java
index c0613bf53..64f15e68d 100644
--- a/java/org/rocksdb/test/KeyMayExistTest.java
+++ b/java/org/rocksdb/test/KeyMayExistTest.java
@@ -26,46 +26,22 @@ public class KeyMayExistTest {
@Test
public void keyMayExist() throws RocksDBException {
-<<<<<<< HEAD
- RocksDB db;
- DBOptions 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("default"));
- cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
- db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath(),
- cfDescriptors, columnFamilyHandleList);
- assertThat(columnFamilyHandleList.size()).
- isEqualTo(2);
- db.put("key".getBytes(), "value".getBytes());
- // Test without column family
- StringBuffer retValue = new StringBuffer();
- boolean exists = db.keyMayExist("key".getBytes(), retValue);
- assertThat(exists).isTrue();
- assertThat(retValue.toString()).
- isEqualTo("value");
-=======
RocksDB db = null;
- Options options = null;
+ DBOptions options = null;
try {
- options = new Options();
+ options = new DBOptions();
options.setCreateIfMissing(true)
.setCreateMissingColumnFamilies(true);
// open database using cf names
- List cfNames = new ArrayList<>();
+ List cfDescriptors =
+ new ArrayList();
List columnFamilyHandleList =
new ArrayList<>();
- cfNames.add("default");
- cfNames.add("new_cf");
+ cfDescriptors.add(new ColumnFamilyDescriptor("default"));
+ cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath(),
- cfNames, columnFamilyHandleList);
+ cfDescriptors, columnFamilyHandleList);
assertThat(columnFamilyHandleList.size()).
isEqualTo(2);
db.put("key".getBytes(), "value".getBytes());
@@ -75,7 +51,6 @@ public class KeyMayExistTest {
assertThat(exists).isTrue();
assertThat(retValue.toString()).
isEqualTo("value");
->>>>>>> [RocksJava] Integrated review comments from D28209
// Test without column family but with readOptions
retValue = new StringBuffer();
@@ -93,16 +68,6 @@ public class KeyMayExistTest {
assertThat(retValue.toString()).
isEqualTo("value");
-<<<<<<< HEAD
- // Test with column family and readOptions
- retValue = new StringBuffer();
- exists = db.keyMayExist(new ReadOptions(),
- columnFamilyHandleList.get(0), "key".getBytes(),
- retValue);
- assertThat(exists).isTrue();
- assertThat(retValue.toString()).
- isEqualTo("value");
-=======
// Test with column family and readOptions
retValue = new StringBuffer();
exists = db.keyMayExist(new ReadOptions(),
@@ -111,7 +76,6 @@ public class KeyMayExistTest {
assertThat(exists).isTrue();
assertThat(retValue.toString()).
isEqualTo("value");
->>>>>>> [RocksJava] Integrated review comments from D28209
// KeyMayExist in CF1 must return false
assertThat(db.keyMayExist(columnFamilyHandleList.get(1),
diff --git a/java/org/rocksdb/test/WriteBatchHandlerTest.java b/java/org/rocksdb/test/WriteBatchHandlerTest.java
index ccf9b164a..1debc2bda 100644
--- a/java/org/rocksdb/test/WriteBatchHandlerTest.java
+++ b/java/org/rocksdb/test/WriteBatchHandlerTest.java
@@ -13,13 +13,20 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.rocksdb.WriteOptions;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
public class WriteBatchHandlerTest {
- static {
- RocksDB.loadLibrary();
- }
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
- public static void main(final String[] args) throws IOException, RocksDBException {
+ @Test
+ public void writeBatchHandler() throws IOException, RocksDBException {
// setup test data
final List>> testEvents = new ArrayList<>();
From cd82beb0cbee9d62820f2e5a12034dd5540b7702 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Tue, 11 Nov 2014 18:59:04 +0100
Subject: [PATCH 10/12] [RocksJava] Merged in latest changes.
---
java/Makefile | 6 +++---
java/org/rocksdb/test/FlushTest.java | 19 +++++++++++++------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/java/Makefile b/java/Makefile
index 99664c6ef..0f4d42244 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -34,7 +34,7 @@ NATIVE_JAVA_CLASSES = org.rocksdb.AbstractComparator\
org.rocksdb.WriteBatch.Handler\
org.rocksdb.test.WriteBatchInternal\
org.rocksdb.test.WriteBatchTest\
- org.rocksdb.WriteOptions\
+ org.rocksdb.WriteOptions\
ROCKSDB_MAJOR = $(shell egrep "ROCKSDB_MAJOR.[0-9]" ../include/rocksdb/version.h | cut -d ' ' -f 3)
ROCKSDB_MINOR = $(shell egrep "ROCKSDB_MINOR.[0-9]" ../include/rocksdb/version.h | cut -d ' ' -f 3)
@@ -92,8 +92,9 @@ clean:
javadocs:
mkdir -p javadoc; javadoc -d javadoc -sourcepath . -subpackages org -exclude org.rocksdb.test
-java: javadocs
+java: javadocs resolve_test_deps
javac org/rocksdb/util/*.java org/rocksdb/*.java
+ javac -cp $(JAVA_TESTCLASSPATH) org/rocksdb/test/*.java
@cp ../HISTORY.md ./HISTORY-CPP.md
@rm -f ./HISTORY-CPP.md
javah -d $(NATIVE_INCLUDE) -jni $(NATIVE_JAVA_CLASSES)
@@ -121,7 +122,6 @@ resolve_test_deps:
test -s "$(JAVA_ASSERTJ_JAR)" || curl -k -L -o "$(JAVA_ASSERTJ_JAR)" http://central.maven.org/maven2/org/assertj/assertj-core/1.7.0/assertj-core-1.7.0.jar
test: java resolve_test_deps
- javac -cp $(JAVA_TESTCLASSPATH) org/rocksdb/test/*.java
java -ea -Djava.library.path=.:../ -cp "$(JAVA_TESTCLASSPATH)" org.rocksdb.test.RocksJunitRunner $(JAVA_TESTS)
db_bench: java
diff --git a/java/org/rocksdb/test/FlushTest.java b/java/org/rocksdb/test/FlushTest.java
index 1742be67f..3e47668b7 100644
--- a/java/org/rocksdb/test/FlushTest.java
+++ b/java/org/rocksdb/test/FlushTest.java
@@ -4,16 +4,23 @@
// of patent rights can be found in the PATENTS file in the same directory.
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
public class FlushTest {
- static final String db_path = "/tmp/rocksdbjni_flush_test";
- static {
- RocksDB.loadLibrary();
- }
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
- public static void main(String[] args) {
+ @Test
+ public void flush() {
RocksDB db = null;
Options options = new Options();
WriteOptions wOpt = new WriteOptions();
@@ -26,7 +33,7 @@ public class FlushTest {
options.setMinWriteBufferNumberToMerge(10);
flushOptions.setWaitForFlush(true);
wOpt.setDisableWAL(true);
- db = RocksDB.open(options, db_path);
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
db.put(wOpt, "key1".getBytes(), "value1".getBytes());
db.put(wOpt, "key2".getBytes(), "value2".getBytes());
From e46450da6d8fcff4121ec31bd03a11277b9b6d23 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Thu, 13 Nov 2014 22:27:58 +0100
Subject: [PATCH 11/12] [RocksJava] Rebased + integrated CF tests
---
java/Makefile | 5 +-
.../rocksdb/test/AbstractComparatorTest.java | 5 +-
.../rocksdb/test/ColumnFamilyOptionsTest.java | 545 +++++++++++++---
java/org/rocksdb/test/ColumnFamilyTest.java | 610 +++++++++++++-----
java/org/rocksdb/test/FlushTest.java | 119 ++--
java/org/rocksdb/test/KeyMayExistTest.java | 2 +-
java/org/rocksdb/test/MergeTest.java | 5 +-
java/org/rocksdb/test/MixedOptionsTest.java | 23 +-
java/org/rocksdb/test/OptionsTest.java | 521 +++++++++++----
.../rocksdb/test/WriteBatchHandlerTest.java | 4 +-
10 files changed, 1375 insertions(+), 464 deletions(-)
diff --git a/java/Makefile b/java/Makefile
index 0f4d42244..b87fea16d 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -47,8 +47,7 @@ ifeq ($(PLATFORM), OS_MACOSX)
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar
endif
-JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
- org.rocksdb.test.BackupableDBTest\
+JAVA_TESTS = org.rocksdb.test.BackupableDBTest\
org.rocksdb.test.BlockBasedTableConfigTest\
org.rocksdb.test.ColumnFamilyOptionsTest\
org.rocksdb.test.ColumnFamilyTest\
@@ -71,7 +70,7 @@ JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
org.rocksdb.test.RocksIteratorTest\
org.rocksdb.test.SnapshotTest\
org.rocksdb.test.StatisticsCollectorTest\
- org.rocksdb.test.WirteBatchHandlerTest\
+ org.rocksdb.test.WriteBatchHandlerTest\
org.rocksdb.test.WriteBatchTest\
org.rocksdb.test.WriteOptionsTest\
diff --git a/java/org/rocksdb/test/AbstractComparatorTest.java b/java/org/rocksdb/test/AbstractComparatorTest.java
index 339615b45..e3e2f8849 100644
--- a/java/org/rocksdb/test/AbstractComparatorTest.java
+++ b/java/org/rocksdb/test/AbstractComparatorTest.java
@@ -12,6 +12,7 @@ import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Random;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.rocksdb.test.Types.byteToInt;
import static org.rocksdb.test.Types.intToByte;
@@ -75,13 +76,13 @@ public abstract class AbstractComparatorTest {
int count = 0;
for (it.seekToFirst(); it.isValid(); it.next()) {
final int thisKey = byteToInt(it.key());
- assert(thisKey > lastKey);
+ assertThat(thisKey).isGreaterThan(lastKey);
lastKey = thisKey;
count++;
}
db.close();
- assert(count == ITERATIONS);
+ assertThat(count).isEqualTo(ITERATIONS);
} catch (final RocksDBException e) {
System.err.format("[ERROR]: %s%n", e);
diff --git a/java/org/rocksdb/test/ColumnFamilyOptionsTest.java b/java/org/rocksdb/test/ColumnFamilyOptionsTest.java
index 95289a301..7fcfee14c 100644
--- a/java/org/rocksdb/test/ColumnFamilyOptionsTest.java
+++ b/java/org/rocksdb/test/ColumnFamilyOptionsTest.java
@@ -5,225 +5,584 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.rocksdb.*;
import java.util.Random;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class ColumnFamilyOptionsTest {
- static {
- RocksDB.loadLibrary();
- }
- public static void testCFOptions(ColumnFamilyOptionsInterface opt) {
- Random rand = PlatformRandomHelper.
- getPlatformSpecificRandomFactory();
- { // WriteBufferSize test
- try {
- long longValue = rand.nextLong();
- opt.setWriteBufferSize(longValue);
- assert(opt.writeBufferSize() == longValue);
- } catch (RocksDBException e) {
- assert(false);
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ public static final Random rand = PlatformRandomHelper.
+ getPlatformSpecificRandomFactory();
+
+ @Test
+ public void writeBufferSize() throws RocksDBException {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
+ long longValue = rand.nextLong();
+ opt.setWriteBufferSize(longValue);
+ assertThat(opt.writeBufferSize()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
}
+ }
- { // MaxWriteBufferNumber test
+ @Test
+ public void maxWriteBufferNumber() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setMaxWriteBufferNumber(intValue);
- assert(opt.maxWriteBufferNumber() == intValue);
+ assertThat(opt.maxWriteBufferNumber()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MinWriteBufferNumberToMerge test
+ @Test
+ public void minWriteBufferNumberToMerge() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setMinWriteBufferNumberToMerge(intValue);
- assert(opt.minWriteBufferNumberToMerge() == intValue);
+ assertThat(opt.minWriteBufferNumberToMerge()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // NumLevels test
+ @Test
+ public void numLevels() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setNumLevels(intValue);
- assert(opt.numLevels() == intValue);
+ assertThat(opt.numLevels()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // LevelFileNumCompactionTrigger test
+ @Test
+ public void levelZeroFileNumCompactionTrigger() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setLevelZeroFileNumCompactionTrigger(intValue);
- assert(opt.levelZeroFileNumCompactionTrigger() == intValue);
+ assertThat(opt.levelZeroFileNumCompactionTrigger()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // LevelSlowdownWritesTrigger test
+ @Test
+ public void levelZeroSlowdownWritesTrigger() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setLevelZeroSlowdownWritesTrigger(intValue);
- assert(opt.levelZeroSlowdownWritesTrigger() == intValue);
+ assertThat(opt.levelZeroSlowdownWritesTrigger()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // LevelStopWritesTrigger test
+ @Test
+ public void levelZeroStopWritesTrigger() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setLevelZeroStopWritesTrigger(intValue);
- assert(opt.levelZeroStopWritesTrigger() == intValue);
+ assertThat(opt.levelZeroStopWritesTrigger()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxMemCompactionLevel test
+ @Test
+ public void maxMemCompactionLevel() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setMaxMemCompactionLevel(intValue);
- assert(opt.maxMemCompactionLevel() == intValue);
+ assertThat(opt.maxMemCompactionLevel()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // TargetFileSizeBase test
+ @Test
+ public void targetFileSizeBase() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
long longValue = rand.nextLong();
opt.setTargetFileSizeBase(longValue);
- assert(opt.targetFileSizeBase() == longValue);
+ assertThat(opt.targetFileSizeBase()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // TargetFileSizeMultiplier test
+ @Test
+ public void targetFileSizeMultiplier() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setTargetFileSizeMultiplier(intValue);
- assert(opt.targetFileSizeMultiplier() == intValue);
+ assertThat(opt.targetFileSizeMultiplier()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxBytesForLevelBase test
+ @Test
+ public void maxBytesForLevelBase() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
long longValue = rand.nextLong();
opt.setMaxBytesForLevelBase(longValue);
- assert(opt.maxBytesForLevelBase() == longValue);
+ assertThat(opt.maxBytesForLevelBase()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxBytesForLevelMultiplier test
+ @Test
+ public void maxBytesForLevelMultiplier() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setMaxBytesForLevelMultiplier(intValue);
- assert(opt.maxBytesForLevelMultiplier() == intValue);
+ assertThat(opt.maxBytesForLevelMultiplier()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // ExpandedCompactionFactor test
+ @Test
+ public void expandedCompactionFactor() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setExpandedCompactionFactor(intValue);
- assert(opt.expandedCompactionFactor() == intValue);
+ assertThat(opt.expandedCompactionFactor()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // SourceCompactionFactor test
+ @Test
+ public void sourceCompactionFactor() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setSourceCompactionFactor(intValue);
- assert(opt.sourceCompactionFactor() == intValue);
+ assertThat(opt.sourceCompactionFactor()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxGrandparentOverlapFactor test
+ @Test
+ public void maxGrandparentOverlapFactor() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setMaxGrandparentOverlapFactor(intValue);
- assert(opt.maxGrandparentOverlapFactor() == intValue);
+ assertThat(opt.maxGrandparentOverlapFactor()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // SoftRateLimit test
+ @Test
+ public void softRateLimit() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
double doubleValue = rand.nextDouble();
opt.setSoftRateLimit(doubleValue);
- assert(opt.softRateLimit() == doubleValue);
+ assertThat(opt.softRateLimit()).isEqualTo(doubleValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // HardRateLimit test
+ @Test
+ public void hardRateLimit() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
double doubleValue = rand.nextDouble();
opt.setHardRateLimit(doubleValue);
- assert(opt.hardRateLimit() == doubleValue);
+ assertThat(opt.hardRateLimit()).isEqualTo(doubleValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // RateLimitDelayMaxMilliseconds test
+ @Test
+ public void rateLimitDelayMaxMilliseconds() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setRateLimitDelayMaxMilliseconds(intValue);
- assert(opt.rateLimitDelayMaxMilliseconds() == intValue);
+ assertThat(opt.rateLimitDelayMaxMilliseconds()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // ArenaBlockSize test
- try {
- long longValue = rand.nextLong();
- opt.setArenaBlockSize(longValue);
- assert(opt.arenaBlockSize() == longValue);
- } catch (RocksDBException e) {
- assert(false);
+ @Test
+ public void arenaBlockSize() throws RocksDBException {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
+ long longValue = rand.nextLong();
+ opt.setArenaBlockSize(longValue);
+ assertThat(opt.arenaBlockSize()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
}
+ }
- { // DisableAutoCompactions test
+ @Test
+ public void disableAutoCompactions() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean();
opt.setDisableAutoCompactions(boolValue);
- assert(opt.disableAutoCompactions() == boolValue);
+ assertThat(opt.disableAutoCompactions()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // PurgeRedundantKvsWhileFlush test
+ @Test
+ public void purgeRedundantKvsWhileFlush() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean();
opt.setPurgeRedundantKvsWhileFlush(boolValue);
- assert(opt.purgeRedundantKvsWhileFlush() == boolValue);
+ assertThat(opt.purgeRedundantKvsWhileFlush()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // VerifyChecksumsInCompaction test
+ @Test
+ public void verifyChecksumsInCompaction() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean();
opt.setVerifyChecksumsInCompaction(boolValue);
- assert(opt.verifyChecksumsInCompaction() == boolValue);
+ assertThat(opt.verifyChecksumsInCompaction()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // FilterDeletes test
+ @Test
+ public void filterDeletes() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean();
opt.setFilterDeletes(boolValue);
- assert(opt.filterDeletes() == boolValue);
+ assertThat(opt.filterDeletes()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxSequentialSkipInIterations test
+ @Test
+ public void maxSequentialSkipInIterations() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
long longValue = rand.nextLong();
opt.setMaxSequentialSkipInIterations(longValue);
- assert(opt.maxSequentialSkipInIterations() == longValue);
+ assertThat(opt.maxSequentialSkipInIterations()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // InplaceUpdateSupport test
+ @Test
+ public void inplaceUpdateSupport() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean();
opt.setInplaceUpdateSupport(boolValue);
- assert(opt.inplaceUpdateSupport() == boolValue);
+ assertThat(opt.inplaceUpdateSupport()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // InplaceUpdateNumLocks test
- try {
- long longValue = rand.nextLong();
- opt.setInplaceUpdateNumLocks(longValue);
- assert(opt.inplaceUpdateNumLocks() == longValue);
- } catch (RocksDBException e) {
- assert(false);
+ @Test
+ public void inplaceUpdateNumLocks() throws RocksDBException {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
+ long longValue = rand.nextLong();
+ opt.setInplaceUpdateNumLocks(longValue);
+ assertThat(opt.inplaceUpdateNumLocks()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
}
+ }
- { // MemtablePrefixBloomBits test
+ @Test
+ public void memtablePrefixBloomBits() {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
int intValue = rand.nextInt();
opt.setMemtablePrefixBloomBits(intValue);
- assert(opt.memtablePrefixBloomBits() == intValue);
+ assertThat(opt.memtablePrefixBloomBits()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MemtablePrefixBloomProbes test
+ @Test
+ public void memtablePrefixBloomProbes() {
+ ColumnFamilyOptions opt = null;
+ try {
int intValue = rand.nextInt();
+ opt = new ColumnFamilyOptions();
opt.setMemtablePrefixBloomProbes(intValue);
- assert(opt.memtablePrefixBloomProbes() == intValue);
+ assertThat(opt.memtablePrefixBloomProbes()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // BloomLocality test
+ @Test
+ public void bloomLocality() {
+ ColumnFamilyOptions opt = null;
+ try {
int intValue = rand.nextInt();
+ opt = new ColumnFamilyOptions();
opt.setBloomLocality(intValue);
- assert(opt.bloomLocality() == intValue);
+ assertThat(opt.bloomLocality()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- { // MaxSuccessiveMerges test
- try {
- long longValue = rand.nextLong();
- opt.setMaxSuccessiveMerges(longValue);
- assert(opt.maxSuccessiveMerges() == longValue);
- } catch (RocksDBException e){
- assert(false);
+ @Test
+ public void maxSuccessiveMerges() throws RocksDBException {
+ ColumnFamilyOptions opt = null;
+ try {
+ long longValue = rand.nextLong();
+ opt = new ColumnFamilyOptions();
+ opt.setMaxSuccessiveMerges(longValue);
+ assertThat(opt.maxSuccessiveMerges()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
}
+ }
- { // MinPartialMergeOperands test
+ @Test
+ public void minPartialMergeOperands() {
+ ColumnFamilyOptions opt = null;
+ try {
int intValue = rand.nextInt();
+ opt = new ColumnFamilyOptions();
opt.setMinPartialMergeOperands(intValue);
- assert(opt.minPartialMergeOperands() == intValue);
+ assertThat(opt.minPartialMergeOperands()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void memTable() throws RocksDBException {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
+ opt.setMemTableConfig(new HashLinkedListMemTableConfig());
+ assertThat(opt.memTableFactoryName()).
+ isEqualTo("HashLinkedListRepFactory");
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void comparator() throws RocksDBException {
+ ColumnFamilyOptions opt = null;
+ try {
+ opt = new ColumnFamilyOptions();
+ opt.setComparator(BuiltinComparator.BYTEWISE_COMPARATOR);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void linkageOfPrepMethods() {
+ ColumnFamilyOptions options = null;
+ try {
+ options = new ColumnFamilyOptions();
+ options.optimizeUniversalStyleCompaction();
+ options.optimizeUniversalStyleCompaction(4000);
+ options.optimizeLevelStyleCompaction();
+ options.optimizeLevelStyleCompaction(3000);
+ options.optimizeForPointLookup(10);
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void shouldSetTestPrefixExtractor() {
+ ColumnFamilyOptions options = null;
+ try {
+ options = new ColumnFamilyOptions();
+ options.useFixedLengthPrefixExtractor(100);
+ options.useFixedLengthPrefixExtractor(10);
+ } finally {
+ if (options != null) {
+ options.dispose();
+ }
}
}
- public static void main(String[] args) {
- ColumnFamilyOptions opt = new ColumnFamilyOptions();
- testCFOptions(opt);
- opt.dispose();
- System.out.println("Passed DBOptionsTest");
+ @Test
+ public void compressionTypes() {
+ ColumnFamilyOptions ColumnFamilyOptions = null;
+ try {
+ ColumnFamilyOptions = new ColumnFamilyOptions();
+ for (CompressionType compressionType :
+ CompressionType.values()) {
+ ColumnFamilyOptions.setCompressionType(compressionType);
+ assertThat(ColumnFamilyOptions.compressionType()).
+ isEqualTo(compressionType);
+ assertThat(CompressionType.valueOf("NO_COMPRESSION")).
+ isEqualTo(CompressionType.NO_COMPRESSION);
+ }
+ } finally {
+ if (ColumnFamilyOptions != null) {
+ ColumnFamilyOptions.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void compactionStyles() {
+ ColumnFamilyOptions ColumnFamilyOptions = null;
+ try {
+ ColumnFamilyOptions = new ColumnFamilyOptions();
+ for (CompactionStyle compactionStyle :
+ CompactionStyle.values()) {
+ ColumnFamilyOptions.setCompactionStyle(compactionStyle);
+ assertThat(ColumnFamilyOptions.compactionStyle()).
+ isEqualTo(compactionStyle);
+ assertThat(CompactionStyle.valueOf("FIFO")).
+ isEqualTo(CompactionStyle.FIFO);
+ }
+ } finally {
+ if (ColumnFamilyOptions != null) {
+ ColumnFamilyOptions.dispose();
+ }
+ }
}
}
diff --git a/java/org/rocksdb/test/ColumnFamilyTest.java b/java/org/rocksdb/test/ColumnFamilyTest.java
index fc5b4ba6e..4c2ac8536 100644
--- a/java/org/rocksdb/test/ColumnFamilyTest.java
+++ b/java/org/rocksdb/test/ColumnFamilyTest.java
@@ -16,6 +16,8 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.rocksdb.*;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class ColumnFamilyTest {
@ClassRule
@@ -26,71 +28,85 @@ public class ColumnFamilyTest {
public TemporaryFolder dbFolder = new TemporaryFolder();
@Test
- public void columnFamilies() {
- String db_path = dbFolder.getRoot().getAbsolutePath();
+ public void listColumnFamilies() throws RocksDBException {
RocksDB db = null;
- Options options = new Options();
- options.setCreateIfMissing(true);
+ Options options = null;
+ try {
+ options = new Options();
+ options.setCreateIfMissing(true);
- DBOptions dbOptions = new DBOptions();
- dbOptions.setCreateIfMissing(true);
+ DBOptions dbOptions = new DBOptions();
+ dbOptions.setCreateIfMissing(true);
- try {
- db = RocksDB.open(options, db_path);
- } catch (RocksDBException e) {
- assert(false);
- }
- // Test listColumnFamilies
- List columnFamilyNames;
- try {
- columnFamilyNames = RocksDB.listColumnFamilies(options, db_path);
- if (columnFamilyNames != null && columnFamilyNames.size() > 0) {
- assert(columnFamilyNames.size() == 1);
- assert(new String(columnFamilyNames.get(0)).equals("default"));
- } else {
- assert(false);
- }
- } catch (RocksDBException e) {
- assert(false);
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
+ // Test listColumnFamilies
+ List columnFamilyNames;
+ columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath());
+ assertThat(columnFamilyNames).isNotNull();
+ assertThat(columnFamilyNames.size()).isGreaterThan(0);
+ assertThat(columnFamilyNames.size()).isEqualTo(1);
+ assertThat(new String(columnFamilyNames.get(0))).isEqualTo("default");
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
}
+ }
- // Test createColumnFamily
+ @Test
+ public void createColumnFamily() throws RocksDBException {
+ RocksDB db = null;
+ Options options = 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",
new ColumnFamilyOptions()));
- } catch (RocksDBException e) {
- assert(false);
- }
-
- if (db != null) {
db.close();
+ List columnFamilyNames;
+ columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath());
+ assertThat(columnFamilyNames).isNotNull();
+ assertThat(columnFamilyNames.size()).isGreaterThan(0);
+ assertThat(columnFamilyNames.size()).isEqualTo(2);
+ assertThat(new String(columnFamilyNames.get(0))).isEqualTo("default");
+ assertThat(new String(columnFamilyNames.get(1))).isEqualTo("new_cf");
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
}
+ }
- // Test listColumnFamilies after create "new_cf"
+ @Test
+ public void openWithColumnFamilies() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
try {
- columnFamilyNames = RocksDB.listColumnFamilies(options, db_path);
- if (columnFamilyNames != null && columnFamilyNames.size() > 0) {
- assert(columnFamilyNames.size() == 2);
- assert(new String(columnFamilyNames.get(0)).equals("default"));
- assert(new String(columnFamilyNames.get(1)).equals("new_cf"));
- } else {
- assert(false);
- }
- } catch (RocksDBException e) {
- assert(false);
- }
-
- // Test open database with column family names
- List cfNames =
- new ArrayList<>();
- List columnFamilyHandleList =
- new ArrayList<>();
- cfNames.add(new ColumnFamilyDescriptor("default"));
- cfNames.add(new ColumnFamilyDescriptor("new_cf"));
+ 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"));
- try {
- db = RocksDB.open(dbOptions, db_path, cfNames, columnFamilyHandleList);
- assert(columnFamilyHandleList.size() == 2);
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
+ assertThat(columnFamilyHandleList.size()).isEqualTo(2);
db.put("dfkey1".getBytes(), "dfvalue".getBytes());
db.put(columnFamilyHandleList.get(0), "dfkey2".getBytes(),
"dfvalue".getBytes());
@@ -99,57 +115,118 @@ public class ColumnFamilyTest {
String retVal = new String(db.get(columnFamilyHandleList.get(1),
"newcfkey1".getBytes()));
- assert(retVal.equals("newcfvalue"));
- assert( (db.get(columnFamilyHandleList.get(1),
- "dfkey1".getBytes())) == null);
+ assertThat(retVal).isEqualTo("newcfvalue");
+ assertThat((db.get(columnFamilyHandleList.get(1),
+ "dfkey1".getBytes()))).isNull();
db.remove(columnFamilyHandleList.get(1), "newcfkey1".getBytes());
- assert( (db.get(columnFamilyHandleList.get(1),
- "newcfkey1".getBytes())) == null);
- db.remove("dfkey2".getBytes());
- assert( (db.get(columnFamilyHandleList.get(0),
- "dfkey2".getBytes())) == null);
- } catch (RocksDBException e) {
- assert(false);
+ assertThat((db.get(columnFamilyHandleList.get(1),
+ "newcfkey1".getBytes()))).isNull();
+ db.remove(columnFamilyHandleList.get(0), new WriteOptions(),
+ "dfkey2".getBytes());
+ assertThat(db.get(columnFamilyHandleList.get(0), new ReadOptions(),
+ "dfkey2".getBytes())).isNull();
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void getWithOutValueAndCf() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
+ 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);
+ db.put(columnFamilyHandleList.get(0), new WriteOptions(), "key1".getBytes(), "value".getBytes());
+ db.put("key2".getBytes(), "12345678".getBytes());
+ byte[] outValue = new byte[5];
+ // not found value
+ int getResult = db.get("keyNotFound".getBytes(), outValue);
+ assertThat(getResult).isEqualTo(RocksDB.NOT_FOUND);
+ // found value which fits in outValue
+ getResult = db.get(columnFamilyHandleList.get(0), "key1".getBytes(), outValue);
+ assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
+ assertThat(outValue).isEqualTo("value".getBytes());
+ // found value which fits partially
+ getResult = db.get(columnFamilyHandleList.get(0), new ReadOptions(),
+ "key2".getBytes(), outValue);
+ assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
+ assertThat(outValue).isEqualTo("12345".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
}
+ }
- // Test create write to and drop ColumnFamily
+ @Test
+ public void createWriteDropColumnFamily() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions opt = null;
ColumnFamilyHandle tmpColumnFamilyHandle = null;
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"));
+
+ db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
tmpColumnFamilyHandle = db.createColumnFamily(
new ColumnFamilyDescriptor("tmpCF", new ColumnFamilyOptions()));
db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes());
db.dropColumnFamily(tmpColumnFamilyHandle);
tmpColumnFamilyHandle.dispose();
- } catch (Exception e) {
- assert(false);
- }
-
- // Put to disposed column family tmpColumnFamilyHandle must fail
- try {
- db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes());
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
+ } finally {
+ if (tmpColumnFamilyHandle != null) {
+ tmpColumnFamilyHandle.dispose();
+ }
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- // Remove to disposed column family tmpColumnFamilyHandle must fail
+ @Test
+ public void writeBatch() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions opt = null;
try {
- db.remove(tmpColumnFamilyHandle, "key".getBytes());
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
- }
+ 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"));
- // Get on a disposed column family tmpColumnFamilyHandle must fail
- try {
- db.get(tmpColumnFamilyHandle, "key".getBytes());
- assert(false);
- } catch (RocksDBException e) {
- assert(true);
- }
+ db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
- // Test WriteBatch
- try {
WriteBatch writeBatch = new WriteBatch();
WriteOptions writeOpt = new WriteOptions();
writeBatch.put("key".getBytes(), "value".getBytes());
@@ -161,135 +238,324 @@ public class ColumnFamilyTest {
writeBatch.remove(columnFamilyHandleList.get(1), "xyz".getBytes());
db.write(writeOpt, writeBatch);
writeBatch.dispose();
- assert(db.get(columnFamilyHandleList.get(1),
+ assertThat(db.get(columnFamilyHandleList.get(1),
"xyz".getBytes()) == null);
- assert(new String(db.get(columnFamilyHandleList.get(1),
- "newcfkey".getBytes())).equals("value"));
- assert(new String(db.get(columnFamilyHandleList.get(1),
- "newcfkey2".getBytes())).equals("value2"));
- assert(new String(db.get("key".getBytes())).equals("value"));
- } catch (Exception e) {
- e.printStackTrace();
- assert(false);
+ assertThat(new String(db.get(columnFamilyHandleList.get(1),
+ "newcfkey".getBytes()))).isEqualTo("value");
+ assertThat(new String(db.get(columnFamilyHandleList.get(1),
+ "newcfkey2".getBytes()))).isEqualTo("value2");
+ assertThat(new String(db.get("key".getBytes()))).isEqualTo("value");
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (opt != null) {
+ opt.dispose();
+ }
}
+ }
- // Test iterator on column family
+ @Test
+ public void iteratorOnColumnFamily() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
+ RocksIterator rocksIterator = null;
try {
- RocksIterator rocksIterator = db.newIterator(
+ 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"));
+
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
+ db.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(),
+ "value".getBytes());
+ db.put(columnFamilyHandleList.get(1), "newcfkey2".getBytes(),
+ "value2".getBytes());
+ rocksIterator = db.newIterator(
columnFamilyHandleList.get(1));
rocksIterator.seekToFirst();
- Map refMap = new HashMap();
+ Map refMap = new HashMap<>();
refMap.put("newcfkey", "value");
refMap.put("newcfkey2", "value2");
int i = 0;
- while(rocksIterator.isValid()) {
+ while (rocksIterator.isValid()) {
i++;
- refMap.get(new String(rocksIterator.key())).equals(
- new String(rocksIterator.value()));
+ assertThat(refMap.get(new String(rocksIterator.key()))).
+ isEqualTo(new String(rocksIterator.value()));
rocksIterator.next();
}
- assert(i == 2);
+ assertThat(i).isEqualTo(2);
rocksIterator.dispose();
- } catch(Exception e) {
- assert(false);
+ } finally {
+ if (rocksIterator != null) {
+ rocksIterator.dispose();
+ }
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
}
+ }
- // Test property handling on column families
+ @Test
+ public void multiGet() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
try {
- assert(db.getProperty("rocksdb.estimate-num-keys") != null);
- assert(db.getProperty("rocksdb.stats") != null);
- assert(db.getProperty(columnFamilyHandleList.get(0),
- "rocksdb.sstables") != null);
- assert(db.getProperty(columnFamilyHandleList.get(1),
- "rocksdb.estimate-num-keys") != null);
- assert(db.getProperty(columnFamilyHandleList.get(1),
- "rocksdb.stats") != null);
- assert(db.getProperty(columnFamilyHandleList.get(1),
- "rocksdb.sstables") != null);
- } catch(Exception e) {
- assert(false);
- }
+ 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"));
- // MultiGet test
- List cfCustomList = new ArrayList();
- try {
- List keys = new ArrayList();
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfDescriptors, columnFamilyHandleList);
+ db.put(columnFamilyHandleList.get(0), "key".getBytes(), "value".getBytes());
+ db.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(), "value".getBytes());
+
+ List keys = new ArrayList<>();
keys.add("key".getBytes());
keys.add("newcfkey".getBytes());
- Map retValues = db.multiGet(columnFamilyHandleList,keys);
- assert(retValues.size() == 2);
- assert(new String(retValues.get(keys.get(0)))
- .equals("value"));
- assert(new String(retValues.get(keys.get(1)))
- .equals("value"));
-
- cfCustomList.add(columnFamilyHandleList.get(0));
- cfCustomList.add(columnFamilyHandleList.get(0));
- retValues = db.multiGet(cfCustomList, keys);
- assert(retValues.size() == 1);
- assert(new String(retValues.get(keys.get(0)))
- .equals("value"));
- } catch (RocksDBException e) {
- assert(false);
+ Map retValues = db.multiGet(columnFamilyHandleList, keys);
+ assertThat(retValues.size()).isEqualTo(2);
+ assertThat(new String(retValues.get(keys.get(0))))
+ .isEqualTo("value");
+ assertThat(new String(retValues.get(keys.get(1))))
+ .isEqualTo("value");
+ retValues = db.multiGet(new ReadOptions(), columnFamilyHandleList, keys);
+ assertThat(retValues.size()).isEqualTo(2);
+ assertThat(new String(retValues.get(keys.get(0))))
+ .isEqualTo("value");
+ assertThat(new String(retValues.get(keys.get(1))))
+ .isEqualTo("value");
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
}
+ }
+
- // Test multiget without correct number of column
- // families
+ @Test
+ public void properties() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
try {
- List keys = new ArrayList();
- keys.add("key".getBytes());
- keys.add("newcfkey".getBytes());
- cfCustomList.remove(1);
- db.multiGet(cfCustomList, keys);
- assert(false);
- } catch (RocksDBException e) {
- assert(false);
- } catch (IllegalArgumentException e) {
- assert(true);
+ 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"));
+
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
+ assertThat(db.getProperty("rocksdb.estimate-num-keys")).
+ isNotNull();
+ assertThat(db.getProperty("rocksdb.stats")).isNotNull();
+ assertThat(db.getProperty(columnFamilyHandleList.get(0),
+ "rocksdb.sstables")).isNotNull();
+ assertThat(db.getProperty(columnFamilyHandleList.get(1),
+ "rocksdb.estimate-num-keys")).isNotNull();
+ assertThat(db.getProperty(columnFamilyHandleList.get(1),
+ "rocksdb.stats")).isNotNull();
+ assertThat(db.getProperty(columnFamilyHandleList.get(1),
+ "rocksdb.sstables")).isNotNull();
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
}
+ }
+
+ @Test
+ public void iterators() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
try {
- // iterate over default key/value pairs
+ 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"));
+
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
List iterators =
db.newIterators(columnFamilyHandleList);
- assert(iterators.size() == 2);
+ assertThat(iterators.size()).isEqualTo(2);
RocksIterator iter = iterators.get(0);
iter.seekToFirst();
- Map defRefMap = new HashMap();
+ Map defRefMap = new HashMap<>();
defRefMap.put("dfkey1", "dfvalue");
defRefMap.put("key", "value");
while (iter.isValid()) {
- defRefMap.get(new String(iter.key())).equals(
- new String(iter.value()));
+ assertThat(defRefMap.get(new String(iter.key()))).
+ isEqualTo(new String(iter.value()));
iter.next();
}
// iterate over new_cf key/value pairs
- Map cfRefMap = new HashMap();
+ Map cfRefMap = new HashMap<>();
cfRefMap.put("newcfkey", "value");
cfRefMap.put("newcfkey2", "value2");
iter = iterators.get(1);
iter.seekToFirst();
while (iter.isValid()) {
- cfRefMap.get(new String(iter.key())).equals(
- new String(iter.value()));
+ assertThat(cfRefMap.get(new String(iter.key()))).
+ isEqualTo(new String(iter.value()));
iter.next();
}
- // free iterators
- for (RocksIterator iterator : iterators) {
- iterator.dispose();
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failPutDisposedCF() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
+ 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"));
+
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
+ db.dropColumnFamily(columnFamilyHandleList.get(1));
+ db.put(columnFamilyHandleList.get(1), "key".getBytes(), "value".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failRemoveDisposedCF() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
+ 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"));
+
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
+ db.dropColumnFamily(columnFamilyHandleList.get(1));
+ db.remove(columnFamilyHandleList.get(1), "key".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failGetDisposedCF() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
+ 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"));
+
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
+ db.dropColumnFamily(columnFamilyHandleList.get(1));
+ db.get(columnFamilyHandleList.get(1), "key".getBytes());
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
}
- assert(true);
- } catch (RocksDBException e) {
- assert(false);
}
+ }
+
+ @Test(expected = RocksDBException.class)
+ public void failMultiGetWithoutCorrectNumberOfCF() throws RocksDBException {
+ RocksDB db = null;
+ DBOptions options = null;
+ 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"));
- // free cf handles before database close
- for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) {
- columnFamilyHandle.dispose();
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
+ cfNames, columnFamilyHandleList);
+ List keys = new ArrayList<>();
+ keys.add("key".getBytes());
+ keys.add("newcfkey".getBytes());
+ List cfCustomList = new ArrayList<>();
+ db.multiGet(cfCustomList, keys);
+
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
}
- // close database
- db.close();
- // be sure to dispose c++ pointers
- options.dispose();
}
+
}
diff --git a/java/org/rocksdb/test/FlushTest.java b/java/org/rocksdb/test/FlushTest.java
index 3e47668b7..9dea7e753 100644
--- a/java/org/rocksdb/test/FlushTest.java
+++ b/java/org/rocksdb/test/FlushTest.java
@@ -1,54 +1,65 @@
-// Copyright (c) 2014, Facebook, Inc. All rights reserved.
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
-package org.rocksdb.test;
-
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.rocksdb.*;
-
-public class FlushTest {
-
- @ClassRule
- public static final RocksMemoryResource rocksMemoryResource =
- new RocksMemoryResource();
-
- @Rule
- public TemporaryFolder dbFolder = new TemporaryFolder();
-
- @Test
- public void flush() {
- RocksDB db = null;
- Options options = new Options();
- WriteOptions wOpt = new WriteOptions();
- FlushOptions flushOptions = new FlushOptions();
-
- try {
- // Setup options
- options.setCreateIfMissing(true);
- options.setMaxWriteBufferNumber(10);
- options.setMinWriteBufferNumberToMerge(10);
- flushOptions.setWaitForFlush(true);
- wOpt.setDisableWAL(true);
- db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
-
- db.put(wOpt, "key1".getBytes(), "value1".getBytes());
- db.put(wOpt, "key2".getBytes(), "value2".getBytes());
- db.put(wOpt, "key3".getBytes(), "value3".getBytes());
- db.put(wOpt, "key4".getBytes(), "value4".getBytes());
- assert(db.getProperty("rocksdb.num-entries-active-mem-table").equals("4"));
- db.flush(flushOptions);
- assert(db.getProperty("rocksdb.num-entries-active-mem-table").equals("0"));
- } catch (RocksDBException e) {
- assert(false);
- }
-
- db.close();
- options.dispose();
- wOpt.dispose();
- flushOptions.dispose();
- }
-}
+// Copyright (c) 2014, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+package org.rocksdb.test;
+
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.rocksdb.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class FlushTest {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Rule
+ public TemporaryFolder dbFolder = new TemporaryFolder();
+
+ @Test
+ public void flush() throws RocksDBException {
+ RocksDB db = null;
+ Options options = null;
+ WriteOptions wOpt = null;
+ FlushOptions flushOptions = null;
+ try {
+ options = new Options();
+ // Setup options
+ options.setCreateIfMissing(true);
+ options.setMaxWriteBufferNumber(10);
+ options.setMinWriteBufferNumberToMerge(10);
+ wOpt = new WriteOptions();
+ flushOptions = new FlushOptions();
+ flushOptions.setWaitForFlush(true);
+ wOpt.setDisableWAL(true);
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
+ db.put(wOpt, "key1".getBytes(), "value1".getBytes());
+ db.put(wOpt, "key2".getBytes(), "value2".getBytes());
+ db.put(wOpt, "key3".getBytes(), "value3".getBytes());
+ db.put(wOpt, "key4".getBytes(), "value4".getBytes());
+ assertThat(db.getProperty("rocksdb.num-entries-active-mem-table")).isEqualTo("4");
+ db.flush(flushOptions);
+ assertThat(db.getProperty("rocksdb.num-entries-active-mem-table")).
+ isEqualTo("0");
+ } finally {
+ if (flushOptions != null) {
+ flushOptions.dispose();
+ }
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ if (wOpt != null) {
+ wOpt.dispose();
+ }
+
+ }
+ }
+}
diff --git a/java/org/rocksdb/test/KeyMayExistTest.java b/java/org/rocksdb/test/KeyMayExistTest.java
index 64f15e68d..4fe45e4c0 100644
--- a/java/org/rocksdb/test/KeyMayExistTest.java
+++ b/java/org/rocksdb/test/KeyMayExistTest.java
@@ -34,7 +34,7 @@ public class KeyMayExistTest {
.setCreateMissingColumnFamilies(true);
// open database using cf names
List cfDescriptors =
- new ArrayList();
+ new ArrayList<>();
List columnFamilyHandleList =
new ArrayList<>();
cfDescriptors.add(new ColumnFamilyDescriptor("default"));
diff --git a/java/org/rocksdb/test/MergeTest.java b/java/org/rocksdb/test/MergeTest.java
index 962674716..3ebd55975 100644
--- a/java/org/rocksdb/test/MergeTest.java
+++ b/java/org/rocksdb/test/MergeTest.java
@@ -177,11 +177,12 @@ public class MergeTest {
// Test also with createColumnFamily
columnFamilyHandle = db.createColumnFamily(
- new ColumnFamilyDescriptor("new_cf2"));
+ new ColumnFamilyDescriptor("new_cf2",
+ new ColumnFamilyOptions().setMergeOperator(stringAppendOperator)));
// writing xx under cfkey2
db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes());
// merge yy under cfkey2
- db.merge(columnFamilyHandle, "cfkey2".getBytes(), "yy".getBytes());
+ db.merge(columnFamilyHandle, new WriteOptions(), "cfkey2".getBytes(), "yy".getBytes());
value = db.get(columnFamilyHandle, "cfkey2".getBytes());
String strValueTmpCf = new String(value);
diff --git a/java/org/rocksdb/test/MixedOptionsTest.java b/java/org/rocksdb/test/MixedOptionsTest.java
index edaa2c318..0f15e668c 100644
--- a/java/org/rocksdb/test/MixedOptionsTest.java
+++ b/java/org/rocksdb/test/MixedOptionsTest.java
@@ -5,26 +5,33 @@
package org.rocksdb.test;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.rocksdb.*;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class MixedOptionsTest {
- static {
- RocksDB.loadLibrary();
- }
- public static void main(String[] args) {
+
+ @ClassRule
+ public static final RocksMemoryResource rocksMemoryResource =
+ new RocksMemoryResource();
+
+ @Test
+ public void mixedOptionsTest(){
// Set a table factory and check the names
ColumnFamilyOptions cfOptions = new ColumnFamilyOptions();
cfOptions.setTableFormatConfig(new BlockBasedTableConfig().
setFilter(new BloomFilter()));
- assert(cfOptions.tableFactoryName().equals(
- "BlockBasedTable"));
+ assertThat(cfOptions.tableFactoryName()).isEqualTo(
+ "BlockBasedTable");
cfOptions.setTableFormatConfig(new PlainTableConfig());
- assert(cfOptions.tableFactoryName().equals("PlainTable"));
+ assertThat(cfOptions.tableFactoryName()).isEqualTo("PlainTable");
// Initialize a dbOptions object from cf options and
// db options
DBOptions dbOptions = new DBOptions();
Options options = new Options(dbOptions, cfOptions);
- assert(options.tableFactoryName().equals("PlainTable"));
+ assertThat(options.tableFactoryName()).isEqualTo("PlainTable");
// Free instances
options.dispose();
options = null;
diff --git a/java/org/rocksdb/test/OptionsTest.java b/java/org/rocksdb/test/OptionsTest.java
index a7241e822..3425502d8 100644
--- a/java/org/rocksdb/test/OptionsTest.java
+++ b/java/org/rocksdb/test/OptionsTest.java
@@ -23,196 +23,463 @@ public class OptionsTest {
getPlatformSpecificRandomFactory();
@Test
- public void options() throws RocksDBException {
+ public void writeBufferSize() throws RocksDBException {
Options opt = null;
try {
opt = new Options();
-
- { // WriteBufferSize test
- long longValue = rand.nextLong();
- opt.setWriteBufferSize(longValue);
- assert (opt.writeBufferSize() == longValue);
+ long longValue = rand.nextLong();
+ opt.setWriteBufferSize(longValue);
+ assertThat(opt.writeBufferSize()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MaxWriteBufferNumber test
- int intValue = rand.nextInt();
- opt.setMaxWriteBufferNumber(intValue);
- assert (opt.maxWriteBufferNumber() == intValue);
+ @Test
+ public void maxWriteBufferNumber() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMaxWriteBufferNumber(intValue);
+ assertThat(opt.maxWriteBufferNumber()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MinWriteBufferNumberToMerge test
- int intValue = rand.nextInt();
- opt.setMinWriteBufferNumberToMerge(intValue);
- assert (opt.minWriteBufferNumberToMerge() == intValue);
+ @Test
+ public void minWriteBufferNumberToMerge() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMinWriteBufferNumberToMerge(intValue);
+ assertThat(opt.minWriteBufferNumberToMerge()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // NumLevels test
- int intValue = rand.nextInt();
- opt.setNumLevels(intValue);
- assert (opt.numLevels() == intValue);
+ @Test
+ public void numLevels() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setNumLevels(intValue);
+ assertThat(opt.numLevels()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // LevelFileNumCompactionTrigger test
- int intValue = rand.nextInt();
- opt.setLevelZeroFileNumCompactionTrigger(intValue);
- assert (opt.levelZeroFileNumCompactionTrigger() == intValue);
+ @Test
+ public void levelZeroFileNumCompactionTrigger() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setLevelZeroFileNumCompactionTrigger(intValue);
+ assertThat(opt.levelZeroFileNumCompactionTrigger()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // LevelSlowdownWritesTrigger test
- int intValue = rand.nextInt();
- opt.setLevelZeroSlowdownWritesTrigger(intValue);
- assert (opt.levelZeroSlowdownWritesTrigger() == intValue);
+ @Test
+ public void levelZeroSlowdownWritesTrigger() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setLevelZeroSlowdownWritesTrigger(intValue);
+ assertThat(opt.levelZeroSlowdownWritesTrigger()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // LevelStopWritesTrigger test
- int intValue = rand.nextInt();
- opt.setLevelZeroStopWritesTrigger(intValue);
- assert (opt.levelZeroStopWritesTrigger() == intValue);
+ @Test
+ public void levelZeroStopWritesTrigger() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setLevelZeroStopWritesTrigger(intValue);
+ assertThat(opt.levelZeroStopWritesTrigger()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MaxMemCompactionLevel test
- int intValue = rand.nextInt();
- opt.setMaxMemCompactionLevel(intValue);
- assert (opt.maxMemCompactionLevel() == intValue);
+ @Test
+ public void maxMemCompactionLevel() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMaxMemCompactionLevel(intValue);
+ assertThat(opt.maxMemCompactionLevel()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // TargetFileSizeBase test
- long longValue = rand.nextLong();
- opt.setTargetFileSizeBase(longValue);
- assert (opt.targetFileSizeBase() == longValue);
+ @Test
+ public void targetFileSizeBase() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setTargetFileSizeBase(longValue);
+ assertThat(opt.targetFileSizeBase()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // TargetFileSizeMultiplier test
- int intValue = rand.nextInt();
- opt.setTargetFileSizeMultiplier(intValue);
- assert (opt.targetFileSizeMultiplier() == intValue);
+ @Test
+ public void targetFileSizeMultiplier() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setTargetFileSizeMultiplier(intValue);
+ assertThat(opt.targetFileSizeMultiplier()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MaxBytesForLevelBase test
- long longValue = rand.nextLong();
- opt.setMaxBytesForLevelBase(longValue);
- assert (opt.maxBytesForLevelBase() == longValue);
+ @Test
+ public void maxBytesForLevelBase() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setMaxBytesForLevelBase(longValue);
+ assertThat(opt.maxBytesForLevelBase()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MaxBytesForLevelMultiplier test
- int intValue = rand.nextInt();
- opt.setMaxBytesForLevelMultiplier(intValue);
- assert (opt.maxBytesForLevelMultiplier() == intValue);
+ @Test
+ public void maxBytesForLevelMultiplier() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMaxBytesForLevelMultiplier(intValue);
+ assertThat(opt.maxBytesForLevelMultiplier()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // ExpandedCompactionFactor test
- int intValue = rand.nextInt();
- opt.setExpandedCompactionFactor(intValue);
- assert (opt.expandedCompactionFactor() == intValue);
+ @Test
+ public void expandedCompactionFactor() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setExpandedCompactionFactor(intValue);
+ assertThat(opt.expandedCompactionFactor()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // SourceCompactionFactor test
- int intValue = rand.nextInt();
- opt.setSourceCompactionFactor(intValue);
- assert (opt.sourceCompactionFactor() == intValue);
+ @Test
+ public void sourceCompactionFactor() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setSourceCompactionFactor(intValue);
+ assertThat(opt.sourceCompactionFactor()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MaxGrandparentOverlapFactor test
- int intValue = rand.nextInt();
- opt.setMaxGrandparentOverlapFactor(intValue);
- assert (opt.maxGrandparentOverlapFactor() == intValue);
+ @Test
+ public void maxGrandparentOverlapFactor() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMaxGrandparentOverlapFactor(intValue);
+ assertThat(opt.maxGrandparentOverlapFactor()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // SoftRateLimit test
- double doubleValue = rand.nextDouble();
- opt.setSoftRateLimit(doubleValue);
- assert (opt.softRateLimit() == doubleValue);
+ @Test
+ public void softRateLimit() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ double doubleValue = rand.nextDouble();
+ opt.setSoftRateLimit(doubleValue);
+ assertThat(opt.softRateLimit()).isEqualTo(doubleValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // HardRateLimit test
- double doubleValue = rand.nextDouble();
- opt.setHardRateLimit(doubleValue);
- assert (opt.hardRateLimit() == doubleValue);
+ @Test
+ public void hardRateLimit() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ double doubleValue = rand.nextDouble();
+ opt.setHardRateLimit(doubleValue);
+ assertThat(opt.hardRateLimit()).isEqualTo(doubleValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // RateLimitDelayMaxMilliseconds test
- int intValue = rand.nextInt();
- opt.setRateLimitDelayMaxMilliseconds(intValue);
- assert (opt.rateLimitDelayMaxMilliseconds() == intValue);
+ @Test
+ public void rateLimitDelayMaxMilliseconds() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setRateLimitDelayMaxMilliseconds(intValue);
+ assertThat(opt.rateLimitDelayMaxMilliseconds()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // ArenaBlockSize test
- long longValue = rand.nextLong();
- opt.setArenaBlockSize(longValue);
- assert (opt.arenaBlockSize() == longValue);
+ @Test
+ public void arenaBlockSize() throws RocksDBException {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setArenaBlockSize(longValue);
+ assertThat(opt.arenaBlockSize()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // DisableAutoCompactions test
- boolean boolValue = rand.nextBoolean();
- opt.setDisableAutoCompactions(boolValue);
- assert (opt.disableAutoCompactions() == boolValue);
+ @Test
+ public void disableAutoCompactions() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setDisableAutoCompactions(boolValue);
+ assertThat(opt.disableAutoCompactions()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // PurgeRedundantKvsWhileFlush test
- boolean boolValue = rand.nextBoolean();
- opt.setPurgeRedundantKvsWhileFlush(boolValue);
- assert (opt.purgeRedundantKvsWhileFlush() == boolValue);
+ @Test
+ public void purgeRedundantKvsWhileFlush() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setPurgeRedundantKvsWhileFlush(boolValue);
+ assertThat(opt.purgeRedundantKvsWhileFlush()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // VerifyChecksumsInCompaction test
- boolean boolValue = rand.nextBoolean();
- opt.setVerifyChecksumsInCompaction(boolValue);
- assert (opt.verifyChecksumsInCompaction() == boolValue);
+ @Test
+ public void verifyChecksumsInCompaction() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setVerifyChecksumsInCompaction(boolValue);
+ assertThat(opt.verifyChecksumsInCompaction()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // FilterDeletes test
- boolean boolValue = rand.nextBoolean();
- opt.setFilterDeletes(boolValue);
- assert (opt.filterDeletes() == boolValue);
+ @Test
+ public void filterDeletes() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setFilterDeletes(boolValue);
+ assertThat(opt.filterDeletes()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MaxSequentialSkipInIterations test
- long longValue = rand.nextLong();
- opt.setMaxSequentialSkipInIterations(longValue);
- assert (opt.maxSequentialSkipInIterations() == longValue);
+ @Test
+ public void maxSequentialSkipInIterations() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setMaxSequentialSkipInIterations(longValue);
+ assertThat(opt.maxSequentialSkipInIterations()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // InplaceUpdateSupport test
- boolean boolValue = rand.nextBoolean();
- opt.setInplaceUpdateSupport(boolValue);
- assert (opt.inplaceUpdateSupport() == boolValue);
+ @Test
+ public void inplaceUpdateSupport() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ boolean boolValue = rand.nextBoolean();
+ opt.setInplaceUpdateSupport(boolValue);
+ assertThat(opt.inplaceUpdateSupport()).isEqualTo(boolValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // InplaceUpdateNumLocks test
- long longValue = rand.nextLong();
- opt.setInplaceUpdateNumLocks(longValue);
- assert (opt.inplaceUpdateNumLocks() == longValue);
+ @Test
+ public void inplaceUpdateNumLocks() throws RocksDBException {
+ Options opt = null;
+ try {
+ opt = new Options();
+ long longValue = rand.nextLong();
+ opt.setInplaceUpdateNumLocks(longValue);
+ assertThat(opt.inplaceUpdateNumLocks()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MemtablePrefixBloomBits test
- int intValue = rand.nextInt();
- opt.setMemtablePrefixBloomBits(intValue);
- assert (opt.memtablePrefixBloomBits() == intValue);
+ @Test
+ public void memtablePrefixBloomBits() {
+ Options opt = null;
+ try {
+ opt = new Options();
+ int intValue = rand.nextInt();
+ opt.setMemtablePrefixBloomBits(intValue);
+ assertThat(opt.memtablePrefixBloomBits()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MemtablePrefixBloomProbes test
- int intValue = rand.nextInt();
- opt.setMemtablePrefixBloomProbes(intValue);
- assert (opt.memtablePrefixBloomProbes() == intValue);
+ @Test
+ public void memtablePrefixBloomProbes() {
+ Options opt = null;
+ try {
+ int intValue = rand.nextInt();
+ opt = new Options();
+ opt.setMemtablePrefixBloomProbes(intValue);
+ assertThat(opt.memtablePrefixBloomProbes()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // BloomLocality test
- int intValue = rand.nextInt();
- opt.setBloomLocality(intValue);
- assert (opt.bloomLocality() == intValue);
+ @Test
+ public void bloomLocality() {
+ Options opt = null;
+ try {
+ int intValue = rand.nextInt();
+ opt = new Options();
+ opt.setBloomLocality(intValue);
+ assertThat(opt.bloomLocality()).isEqualTo(intValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MaxSuccessiveMerges test
- long longValue = rand.nextLong();
- opt.setMaxSuccessiveMerges(longValue);
- assert (opt.maxSuccessiveMerges() == longValue);
+ @Test
+ public void maxSuccessiveMerges() throws RocksDBException {
+ Options opt = null;
+ try {
+ long longValue = rand.nextLong();
+ opt = new Options();
+ opt.setMaxSuccessiveMerges(longValue);
+ assertThat(opt.maxSuccessiveMerges()).isEqualTo(longValue);
+ } finally {
+ if (opt != null) {
+ opt.dispose();
}
+ }
+ }
- { // MinPartialMergeOperands test
- int intValue = rand.nextInt();
- opt.setMinPartialMergeOperands(intValue);
- assert (opt.minPartialMergeOperands() == intValue);
- }
+ @Test
+ public void minPartialMergeOperands() {
+ Options opt = null;
+ try {
+ int intValue = rand.nextInt();
+ opt = new Options();
+ opt.setMinPartialMergeOperands(intValue);
+ assertThat(opt.minPartialMergeOperands()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
diff --git a/java/org/rocksdb/test/WriteBatchHandlerTest.java b/java/org/rocksdb/test/WriteBatchHandlerTest.java
index 1debc2bda..5a330e409 100644
--- a/java/org/rocksdb/test/WriteBatchHandlerTest.java
+++ b/java/org/rocksdb/test/WriteBatchHandlerTest.java
@@ -75,10 +75,10 @@ public class WriteBatchHandlerTest {
// compare the results to the test data
final List>> actualEvents = handler.getEvents();
- assert(testEvents.size() == actualEvents.size());
+ assertThat(testEvents.size()).isSameAs(actualEvents.size());
for(int i = 0; i < testEvents.size(); i++) {
- assert(equals(testEvents.get(i), actualEvents.get(i)));
+ assertThat(equals(testEvents.get(i), actualEvents.get(i))).isTrue();
}
System.out.println("Passed WriteBatchHandler Test");
From 3f9c95a51998cd1bd75fdfb78e5d6074fe03b6e0 Mon Sep 17 00:00:00 2001
From: fyrz
Date: Fri, 14 Nov 2014 21:34:24 +0100
Subject: [PATCH 12/12] [RocksJava] Minor lint correction
---
java/org/rocksdb/test/ColumnFamilyTest.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/java/org/rocksdb/test/ColumnFamilyTest.java b/java/org/rocksdb/test/ColumnFamilyTest.java
index 4c2ac8536..0a77240ac 100644
--- a/java/org/rocksdb/test/ColumnFamilyTest.java
+++ b/java/org/rocksdb/test/ColumnFamilyTest.java
@@ -151,7 +151,8 @@ public class ColumnFamilyTest {
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfDescriptors, columnFamilyHandleList);
- db.put(columnFamilyHandleList.get(0), new WriteOptions(), "key1".getBytes(), "value".getBytes());
+ db.put(columnFamilyHandleList.get(0), new WriteOptions(),
+ "key1".getBytes(), "value".getBytes());
db.put("key2".getBytes(), "12345678".getBytes());
byte[] outValue = new byte[5];
// not found value