[RocksJava] Integrated review comments from D28209

main
fyrz 10 years ago
parent a4b28c1ae7
commit 628e39e97d
  1. 11
      java/Makefile
  2. 1
      java/org/rocksdb/Options.java
  3. 34
      java/org/rocksdb/test/BackupableDBTest.java
  4. 37
      java/org/rocksdb/test/ComparatorTest.java
  5. 9
      java/org/rocksdb/test/FilterTest.java
  6. 46
      java/org/rocksdb/test/KeyMayExistTest.java
  7. 53
      java/org/rocksdb/test/MemTableTest.java
  8. 111
      java/org/rocksdb/test/MergeTest.java
  9. 101
      java/org/rocksdb/test/OptionsTest.java
  10. 157
      java/org/rocksdb/test/ReadOnlyTest.java
  11. 48
      java/org/rocksdb/test/ReadOptionsTest.java
  12. 39
      java/org/rocksdb/test/RocksEnvTest.java
  13. 40
      java/org/rocksdb/test/RocksIteratorTest.java
  14. 21
      java/org/rocksdb/test/SnapshotTest.java
  15. 14
      java/org/rocksdb/test/StatisticsCollectorTest.java
  16. 2
      java/rocksjni/backupablejni.cc
  17. 11
      java/rocksjni/options.cc

@ -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

@ -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

@ -29,14 +29,21 @@ public class BackupableDBTest {
@Test
public void backupableDb() throws RocksDBException {
Options opt = new Options();
Options opt = null;
BackupableDBOptions bopt = null;
BackupableDB bdb = null;
RestoreOptions ropt = null;
RestoreBackupableDB rdb = null;
try {
opt = new Options();
opt.setCreateIfMissing(true);
BackupableDBOptions bopt = new BackupableDBOptions(
bopt = new BackupableDBOptions(
backupFolder.getRoot().getAbsolutePath(), false,
true, false, true, 0, 0);
BackupableDB bdb;
assertThat(bopt.backupDir()).isEqualTo(
backupFolder.getRoot().getAbsolutePath());
List<BackupInfo> backupInfos;
List<BackupInfo> restoreInfos;
@ -73,8 +80,8 @@ public class BackupableDBTest {
bdb.close();
// restore from backup
RestoreOptions ropt = new RestoreOptions(false);
RestoreBackupableDB rdb = new RestoreBackupableDB(bopt);
ropt = new RestoreOptions(false);
rdb = new RestoreBackupableDB(bopt);
// getting backup infos from restorable db should
// lead to the same infos as from backupable db
@ -137,9 +144,22 @@ public class BackupableDBTest {
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();
}
}
}
}

@ -54,17 +54,21 @@ public class ComparatorTest {
@Test
public void builtinForwardComparator()
throws RocksDBException {
Options options = new Options();
Options options = null;
RocksDB rocksDB = null;
RocksIterator rocksIterator = null;
try {
options = new Options();
options.setCreateIfMissing(true);
options.setComparator(BuiltinComparator.BYTEWISE_COMPARATOR);
RocksDB rocksDB = RocksDB.open(options,
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();
rocksIterator = rocksDB.newIterator();
// Iterate over keys using a iterator
rocksIterator.seekToFirst();
assertThat(rocksIterator.isValid()).isTrue();
@ -100,26 +104,39 @@ public class ComparatorTest {
"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 options = null;
RocksDB rocksDB = null;
RocksIterator rocksIterator = null;
try {
options = new Options();
options.setCreateIfMissing(true);
options.setComparator(
BuiltinComparator.REVERSE_BYTEWISE_COMPARATOR);
RocksDB rocksDB = RocksDB.open(options,
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();
rocksIterator = rocksDB.newIterator();
// Iterate over keys using a iterator
rocksIterator.seekToFirst();
assertThat(rocksIterator.isValid()).isTrue();
@ -158,10 +175,18 @@ public class ComparatorTest {
"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
public void builtinComparatorEnum(){

@ -17,7 +17,9 @@ public class FilterTest {
@Test
public void filter() {
Options options = new Options();
Options options = null;
try {
options = new Options();
// test table config
options.setTableFormatConfig(new BlockBasedTableConfig().
setFilter(new BloomFilter()));
@ -36,6 +38,11 @@ public class FilterTest {
System.runFinalization();
blockConfig.setFilter(new BloomFilter(10, false));
options.setTableFormatConfig(blockConfig);
} finally {
if (options != null) {
options.dispose();
}
}
}
}

@ -26,6 +26,7 @@ public class KeyMayExistTest {
@Test
public void keyMayExist() throws RocksDBException {
<<<<<<< HEAD
RocksDB db;
DBOptions options = new DBOptions();
options.setCreateIfMissing(true)
@ -49,6 +50,32 @@ 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<String> cfNames = new ArrayList<>();
List<ColumnFamilyHandle> 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();
@ -66,6 +93,7 @@ public class KeyMayExistTest {
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();
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
}
}
}

@ -18,8 +18,10 @@ public class MemTableTest {
new RocksMemoryResource();
@Test
public void memTable() throws RocksDBException {
Options options = new Options();
public void hashSkipListMemTable() throws RocksDBException {
Options options = null;
try {
options = new Options();
// Test HashSkipListMemTableConfig
HashSkipListMemTableConfig memTableConfig =
new HashSkipListMemTableConfig();
@ -39,10 +41,17 @@ public class MemTableTest {
assertThat(memTableConfig.branchingFactor()).
isEqualTo(6);
options.setMemTableConfig(memTableConfig);
} finally {
if (options != null) {
options.dispose();
System.gc();
System.runFinalization();
// Test SkipList
}
}
}
@Test
public void skipListMemTable() throws RocksDBException {
Options options = null;
try {
options = new Options();
SkipListMemTableConfig skipMemTableConfig =
new SkipListMemTableConfig();
@ -53,9 +62,17 @@ public class MemTableTest {
isEqualTo(20);
options.setMemTableConfig(skipMemTableConfig);
options.dispose();
System.gc();
System.runFinalization();
// Test HashLinkedListMemTableConfig
} finally {
if (options != null) {
options.dispose();
}
}
}
@Test
public void hashLinkedListMemTable() throws RocksDBException {
Options options = null;
try {
options = new Options();
HashLinkedListMemTableConfig hashLinkedListMemTableConfig =
new HashLinkedListMemTableConfig();
@ -91,10 +108,17 @@ public class MemTableTest {
thresholdUseSkiplist()).
isEqualTo(29);
options.setMemTableConfig(hashLinkedListMemTableConfig);
} finally {
if (options != null) {
options.dispose();
System.gc();
System.runFinalization();
// test VectorMemTableConfig
}
}
}
@Test
public void vectorMemTable() throws RocksDBException {
Options options = null;
try {
options = new Options();
VectorMemTableConfig vectorMemTableConfig =
new VectorMemTableConfig();
@ -105,7 +129,10 @@ public class MemTableTest {
isEqualTo(123);
options.setMemTableConfig(vectorMemTableConfig);
options.dispose();
System.gc();
System.runFinalization();
} finally {
if (options != null) {
options.dispose();
}
}
}
}

@ -28,13 +28,16 @@ public class MergeTest {
@Test
public void stringOption()
throws InterruptedException, RocksDBException {
RocksDB db = null;
Options opt = null;
try {
String db_path_string =
dbFolder.getRoot().getAbsolutePath();
Options opt = new Options();
opt = new Options();
opt.setCreateIfMissing(true);
opt.setMergeOperatorName("stringappend");
RocksDB db = RocksDB.open(opt, db_path_string);
db = RocksDB.open(opt, db_path_string);
// writing aa under key
db.put("key".getBytes(), "aa".getBytes());
// merge bb under key
@ -42,33 +45,41 @@ public class MergeTest {
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();
assertThat(strValue).isEqualTo("aa,bb");
}
}
}
@Test
public void cFStringOption()
throws InterruptedException, RocksDBException {
DBOptions opt = new DBOptions();
RocksDB db = null;
DBOptions opt = null;
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
try {
String db_path_string =
dbFolder.getRoot().getAbsolutePath();
opt = new DBOptions();
opt.setCreateIfMissing(true);
opt.setCreateMissingColumnFamilies(true);
List<ColumnFamilyDescriptor> cfDescr =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
List<ColumnFamilyDescriptor> cfDescriptors =
new ArrayList<>();
cfDescr.add(new ColumnFamilyDescriptor("default",
cfDescriptors.add(new ColumnFamilyDescriptor("default",
new ColumnFamilyOptions().setMergeOperatorName(
"stringappend")));
cfDescr.add(new ColumnFamilyDescriptor("default",
cfDescriptors.add(new ColumnFamilyDescriptor("default",
new ColumnFamilyOptions().setMergeOperatorName(
"stringappend")));
RocksDB db = RocksDB.open(opt, db_path_string,
cfDescr, columnFamilyHandleList);
db = RocksDB.open(opt, db_path_string,
cfDescriptors, columnFamilyHandleList);
// writing aa under key
db.put(columnFamilyHandleList.get(1),
@ -79,27 +90,35 @@ public class MergeTest {
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();
assertThat(strValue).isEqualTo("aa,bb");
}
}
}
@Test
public void operatorOption()
throws InterruptedException, RocksDBException {
RocksDB db = null;
Options opt = null;
try {
String db_path_string =
dbFolder.getRoot().getAbsolutePath();
Options opt = new Options();
opt = new Options();
opt.setCreateIfMissing(true);
StringAppendOperator stringAppendOperator = new StringAppendOperator();
opt.setMergeOperator(stringAppendOperator);
RocksDB db = RocksDB.open(opt, db_path_string);
db = RocksDB.open(opt, db_path_string);
// Writing aa under key
db.put("key".getBytes(), "aa".getBytes());
@ -109,34 +128,44 @@ public class MergeTest {
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();
assertThat(strValue).isEqualTo("aa,bb");
}
}
}
@Test
public void cFOperatorOption()
throws InterruptedException, RocksDBException {
DBOptions opt = new DBOptions();
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<ColumnFamilyDescriptor> cfDescr =
List<ColumnFamilyDescriptor> cfDescriptors =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfDescr.add(new ColumnFamilyDescriptor("default",
cfDescriptors.add(new ColumnFamilyDescriptor("default",
new ColumnFamilyOptions().setMergeOperator(
stringAppendOperator)));
cfDescr.add(new ColumnFamilyDescriptor("new_cf",
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf",
new ColumnFamilyOptions().setMergeOperator(
stringAppendOperator)));
RocksDB db = RocksDB.open(opt, db_path_string,
cfDescr, columnFamilyHandleList);
db = RocksDB.open(opt, db_path_string,
cfDescriptors, columnFamilyHandleList);
// writing aa under key
db.put(columnFamilyHandleList.get(1),
"cfkey".getBytes(), "aa".getBytes());
@ -147,10 +176,8 @@ public class MergeTest {
String strValue = new String(value);
// Test also with createColumnFamily
ColumnFamilyHandle columnFamilyHandle = db.createColumnFamily(
new ColumnFamilyDescriptor("new_cf2",
new ColumnFamilyOptions().setMergeOperator(
new StringAppendOperator())));
columnFamilyHandle = db.createColumnFamily(
new ColumnFamilyDescriptor("new_cf2"));
// writing xx under cfkey2
db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes());
// merge yy under cfkey2
@ -159,22 +186,34 @@ public class MergeTest {
String strValueTmpCf = new String(value);
columnFamilyHandle.dispose();
db.close();
opt.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 {
Options opt = null;
RocksDB db = null;
try {
String db_path_string =
dbFolder.getRoot().getAbsolutePath();
Options opt = new Options();
opt = new Options();
opt.setCreateIfMissing(true);
StringAppendOperator stringAppendOperator = new StringAppendOperator();
opt.setMergeOperator(stringAppendOperator);
RocksDB db = RocksDB.open(opt, db_path_string);
db = RocksDB.open(opt, db_path_string);
db.close();
opt.dispose();
System.gc();
@ -203,5 +242,13 @@ public class MergeTest {
db = RocksDB.open(opt, db_path_string);
db.close();
opt.dispose();
} finally {
if (db != null) {
db.close();
}
if (opt != null) {
opt.dispose();
}
}
}
}

@ -21,10 +21,11 @@ public class OptionsTest {
@Test
public void options() throws RocksDBException {
Options opt = new Options();
Options opt = null;
try {
opt = new Options();
Random rand = PlatformRandomHelper.
getPlatformSpecificRandomFactory();
DBOptionsTest.testDBOptions(opt);
{ // WriteBufferSize test
@ -212,71 +213,125 @@ public class OptionsTest {
opt.setMinPartialMergeOperands(intValue);
assert (opt.minPartialMergeOperands() == intValue);
}
} finally {
if (opt != null) {
opt.dispose();
}
}
}
@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();
}
}
}
@Test
public void linkageOfPrepMethods() {
Options options = new Options();
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();
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();
}
}
}
@Test
public void compactionStyles() {
Options options = new Options();
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();
}
}
}
@Test
public void rateLimiterConfig() {
Options options = new Options();
RateLimiterConfig rateLimiterConfig =
new GenericRateLimiterConfig(1000, 0, 1);
Options options = null;
Options anotherOptions = null;
RateLimiterConfig rateLimiterConfig;
try {
options = new Options();
rateLimiterConfig = new GenericRateLimiterConfig(1000, 0, 1);
options.setRateLimiterConfig(rateLimiterConfig);
options.dispose();
// Test with parameter initialization
Options anotherOptions = new Options();
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 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 options = null;
try {
options = new Options();
options.setMemTableConfig(new VectorMemTableConfig());
assertThat(options.memTableFactoryName()).
isEqualTo("VectorRepFactory");
@ -284,18 +339,32 @@ public class OptionsTest {
new HashLinkedListMemTableConfig());
assertThat(options.memTableFactoryName()).
isEqualTo("HashLinkedListRepFactory");
} finally {
if (options != null) {
options.dispose();
}
}
}
@Test
public void statistics() {
Options options = new Options();
Options options = null;
Options anotherOptions = null;
try {
options = new Options();
Statistics statistics = options.createStatistics().
statisticsPtr();
assertThat(statistics).isNotNull();
Options anotherOptions = new Options();
anotherOptions = new Options();
statistics = anotherOptions.statisticsPtr();
assertThat(statistics).isNotNull();
} finally {
if (options != null) {
options.dispose();
}
if (anotherOptions != null) {
anotherOptions.dispose();
}
}
}
}

@ -26,15 +26,18 @@ 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<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
new ArrayList<>();
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList2 =
new ArrayList<>();
Options options = new Options();
try {
options = new Options();
options.setCreateIfMissing(true);
db = RocksDB.open(options,
@ -67,7 +70,6 @@ public class ReadOnlyTest {
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,
@ -75,62 +77,105 @@ public class ReadOnlyTest {
cfDescriptors.add(
new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions()));
db3 = RocksDB.openReadOnly(
dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
readOnlyColumnFamilyHandleList2);
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 {
RocksDB db = null;
RocksDB rDb = null;
Options options = null;
try {
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
new ColumnFamilyOptions()));
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
new ArrayList<>();
Options options = new Options();
options = new Options();
options.setCreateIfMissing(true);
RocksDB db = RocksDB.open(options,
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.close();
RocksDB rDb = RocksDB.openReadOnly(
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 {
RocksDB db = null;
RocksDB rDb = null;
Options options = null;
try {
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
new ColumnFamilyOptions()));
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
new ArrayList<>();
Options options = new Options();
options = new Options();
options.setCreateIfMissing(true);
RocksDB db = RocksDB.open(options,
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.close();
RocksDB rDb = RocksDB.openReadOnly(
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 {
RocksDB db = null;
RocksDB rDb = null;
Options options = null;
try {
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
@ -138,21 +183,36 @@ public class ReadOnlyTest {
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
new ArrayList<>();
Options options = new Options();
options = new Options();
options.setCreateIfMissing(true);
RocksDB db = RocksDB.open(options,
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.close();
RocksDB rDb = RocksDB.openReadOnly(
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 {
RocksDB db = null;
RocksDB rDb = null;
Options options = null;
try {
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
@ -160,23 +220,38 @@ public class ReadOnlyTest {
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
new ArrayList<>();
Options options = new Options();
options = new Options();
options.setCreateIfMissing(true);
RocksDB db = RocksDB.open(options,
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.close();
RocksDB rDb = RocksDB.openReadOnly(
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 {
RocksDB db = null;
RocksDB rDb = null;
Options options = null;
try {
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
@ -184,24 +259,40 @@ public class ReadOnlyTest {
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
new ArrayList<>();
Options options = new Options();
options = new Options();
options.setCreateIfMissing(true);
RocksDB db = RocksDB.open(options,
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.close();
RocksDB rDb = RocksDB.openReadOnly(
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 {
RocksDB db = null;
RocksDB rDb = null;
Options options = null;
WriteBatch wb = null;
try {
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
@ -209,20 +300,34 @@ public class ReadOnlyTest {
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
new ArrayList<>();
Options options = new Options();
options = new Options();
options.setCreateIfMissing(true);
RocksDB db = RocksDB.open(options,
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.close();
RocksDB rDb = RocksDB.openReadOnly(
rDb = RocksDB.openReadOnly(
dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
readOnlyColumnFamilyHandleList);
WriteBatch wb = new WriteBatch();
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();
}
}
}
}

@ -25,33 +25,67 @@ public class ReadOptionsTest {
public ExpectedException exception = ExpectedException.none();
@Test
public void readOptions() {
ReadOptions opt = new ReadOptions();
public void verifyChecksum(){
ReadOptions opt = null;
try {
opt = new ReadOptions();
Random rand = new Random();
{ // VerifyChecksums test
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();
}
}
}
@Test
public void failVerifyChecksumUninitialized(){

@ -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);
}
}

@ -26,8 +26,11 @@ public class RocksIteratorTest {
@Test
public void rocksIterator() throws RocksDBException {
RocksDB db;
Options options = new Options();
RocksDB db = null;
Options options = null;
RocksIterator iterator = null;
try {
options = new Options();
options.setCreateIfMissing(true)
.setCreateMissingColumnFamilies(true);
db = RocksDB.open(options,
@ -35,7 +38,7 @@ public class RocksIteratorTest {
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();
@ -58,29 +61,48 @@ public class RocksIteratorTest {
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();
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());
RocksIterator iter = db.newIterator();
RocksIterator iter2 = db.newIterator();
db.newIterator();
db.newIterator();
RocksIterator iter3 = db.newIterator();
iter = null;
db.close();
db = null;
iter2 = null;
System.gc();
System.runFinalization();
iter3.dispose();
System.gc();
System.runFinalization();
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
}
}
}

@ -27,15 +27,19 @@ public class SnapshotTest {
@Test
public void snapshots() throws RocksDBException {
RocksDB db;
Options options = new Options();
RocksDB db = null;
Options options = null;
ReadOptions readOptions = null;
try {
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 readOptions = new ReadOptions();
readOptions = new ReadOptions();
// set snapshot in ReadOptions
readOptions.setSnapshot(snapshot);
// retrieve key value pair
@ -78,7 +82,16 @@ public class SnapshotTest {
"newkey".getBytes()))).isEqualTo("newvalue");
// release Snapshot
db.releaseSnapshot(snapshot);
// Close database
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
if (readOptions != null) {
readOptions.dispose();
}
}
}
}

@ -27,10 +27,13 @@ public class StatisticsCollectorTest {
@Test
public void statisticsCollector()
throws InterruptedException, RocksDBException {
Options opt = new Options().createStatistics().setCreateIfMissing(true);
Options opt = null;
RocksDB db = null;
try {
opt = new Options().createStatistics().setCreateIfMissing(true);
Statistics stats = opt.statisticsPtr();
RocksDB db = RocksDB.open(opt,
db = RocksDB.open(opt,
dbFolder.getRoot().getAbsolutePath());
StatsCallbackMock callback = new StatsCallbackMock();
@ -46,8 +49,13 @@ public class StatisticsCollectorTest {
assertThat(callback.histCallbackCount).isGreaterThan(0);
statsCollector.shutDown(1000);
} finally {
if (db != null) {
db.close();
}
if (opt != null) {
opt.dispose();
}
}
}
}

@ -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<rocksdb::BackupableDBOptions*>(jhandle);
return env->NewStringUTF(bopt->backup_dir.c_str());
}

@ -274,6 +274,17 @@ void Java_org_rocksdb_Options_setParanoidChecks(
static_cast<bool>(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<rocksdb::Options*>(jhandle)->env =
reinterpret_cast<rocksdb::Env*>(jenv);
}
/*
* Class: org_rocksdb_Options
* Method: setMaxTotalWalSize

Loading…
Cancel
Save