[RocksJava] Integrated review comments from adamretter in D28209

main
fyrz 10 years ago
parent b092686959
commit 36f3a0bb8e
  1. 2
      java/Makefile
  2. 86
      java/org/rocksdb/test/BackupableDBTest.java
  3. 12
      java/org/rocksdb/test/BlockBasedTableConfigTest.java
  4. 3
      java/org/rocksdb/test/ColumnFamilyTest.java
  5. 3
      java/org/rocksdb/test/ComparatorOptionsTest.java
  6. 14
      java/org/rocksdb/test/ComparatorTest.java
  7. 152
      java/org/rocksdb/test/DBOptionsTest.java
  8. 4
      java/org/rocksdb/test/DirectComparatorTest.java
  9. 10
      java/org/rocksdb/test/FilterTest.java
  10. 92
      java/org/rocksdb/test/KeyMayExistTest.java
  11. 79
      java/org/rocksdb/test/MemTableTest.java
  12. 32
      java/org/rocksdb/test/MergeTest.java
  13. 289
      java/org/rocksdb/test/OptionsTest.java
  14. 34
      java/org/rocksdb/test/PlainTableConfigTest.java
  15. 243
      java/org/rocksdb/test/ReadOnlyTest.java
  16. 22
      java/org/rocksdb/test/ReadOptionsTest.java
  17. 3
      java/org/rocksdb/test/RocksIteratorTest.java
  18. 65
      java/org/rocksdb/test/RocksJunitRunner.java
  19. 36
      java/org/rocksdb/test/SnapshotTest.java
  20. 4
      java/org/rocksdb/test/StatisticsCollectorTest.java
  21. 14
      java/org/rocksdb/test/WriteBatchTest.java
  22. 8
      java/org/rocksdb/test/WriteOptionsTest.java
  23. 1
      java/rocksjni.pom

@ -120,7 +120,7 @@ resolve_test_deps:
test: java resolve_test_deps test: java resolve_test_deps
javac -cp $(JAVA_TESTCLASSPATH) org/rocksdb/test/*.java 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 db_bench: java
javac org/rocksdb/benchmark/*.java javac org/rocksdb/benchmark/*.java

@ -13,6 +13,8 @@ import org.rocksdb.*;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class BackupableDBTest { public class BackupableDBTest {
@ClassRule @ClassRule
@ -26,7 +28,7 @@ public class BackupableDBTest {
public TemporaryFolder backupFolder = new TemporaryFolder(); public TemporaryFolder backupFolder = new TemporaryFolder();
@Test @Test
public void shouldTestBackupableDb() { public void backupableDb() throws RocksDBException {
Options opt = new Options(); Options opt = new Options();
opt.setCreateIfMissing(true); opt.setCreateIfMissing(true);
@ -34,40 +36,40 @@ public class BackupableDBTest {
BackupableDBOptions bopt = new BackupableDBOptions( BackupableDBOptions bopt = new BackupableDBOptions(
backupFolder.getRoot().getAbsolutePath(), false, backupFolder.getRoot().getAbsolutePath(), false,
true, false, true, 0, 0); true, false, true, 0, 0);
BackupableDB bdb = null; BackupableDB bdb;
List<BackupInfo> backupInfos; List<BackupInfo> backupInfos;
List<BackupInfo> restoreInfos; List<BackupInfo> restoreInfos;
try {
bdb = BackupableDB.open(opt, bopt, bdb = BackupableDB.open(opt, bopt,
dbFolder.getRoot().getAbsolutePath()); dbFolder.getRoot().getAbsolutePath());
bdb.put("abc".getBytes(), "def".getBytes()); bdb.put("abc".getBytes(), "def".getBytes());
bdb.put("ghi".getBytes(), "jkl".getBytes()); bdb.put("ghi".getBytes(), "jkl".getBytes());
backupInfos = bdb.getBackupInfos(); backupInfos = bdb.getBackupInfos();
assert(backupInfos.size() == 0); assertThat(backupInfos.size()).
isEqualTo(0);
bdb.createNewBackup(true); bdb.createNewBackup(true);
backupInfos = bdb.getBackupInfos(); backupInfos = bdb.getBackupInfos();
assert(backupInfos.size() == 1); assertThat(backupInfos.size()).
isEqualTo(1);
// Retrieving backup infos twice shall not // Retrieving backup infos twice shall not
// lead to different results // lead to different results
List<BackupInfo> tmpBackupInfo = bdb.getBackupInfos(); List<BackupInfo> tmpBackupInfo = bdb.getBackupInfos();
assert(tmpBackupInfo.get(0).backupId() == assertThat(tmpBackupInfo.get(0).backupId()).
backupInfos.get(0).backupId()); isEqualTo(backupInfos.get(0).backupId());
assert(tmpBackupInfo.get(0).timestamp() == assertThat(tmpBackupInfo.get(0).timestamp()).
backupInfos.get(0).timestamp()); isEqualTo(backupInfos.get(0).timestamp());
assert(tmpBackupInfo.get(0).size() == assertThat(tmpBackupInfo.get(0).size()).
backupInfos.get(0).size()); isEqualTo(backupInfos.get(0).size());
assert(tmpBackupInfo.get(0).numberFiles() == assertThat(tmpBackupInfo.get(0).numberFiles()).
backupInfos.get(0).numberFiles()); isEqualTo(backupInfos.get(0).numberFiles());
// delete record after backup // delete record after backup
bdb.remove("abc".getBytes()); bdb.remove("abc".getBytes());
byte[] value = bdb.get("abc".getBytes()); byte[] value = bdb.get("abc".getBytes());
assert(value == null); assertThat(value).isNull();
bdb.close(); bdb.close();
// restore from backup // restore from backup
@ -77,15 +79,16 @@ public class BackupableDBTest {
// getting backup infos from restorable db should // getting backup infos from restorable db should
// lead to the same infos as from backupable db // lead to the same infos as from backupable db
restoreInfos = rdb.getBackupInfos(); restoreInfos = rdb.getBackupInfos();
assert(restoreInfos.size() == backupInfos.size()); assertThat(restoreInfos.size()).
assert(restoreInfos.get(0).backupId() == isEqualTo(backupInfos.size());
backupInfos.get(0).backupId()); assertThat(restoreInfos.get(0).backupId()).
assert(restoreInfos.get(0).timestamp() == isEqualTo(backupInfos.get(0).backupId());
backupInfos.get(0).timestamp()); assertThat(restoreInfos.get(0).timestamp()).
assert(restoreInfos.get(0).size() == isEqualTo(backupInfos.get(0).timestamp());
backupInfos.get(0).size()); assertThat(restoreInfos.get(0).size()).
assert(restoreInfos.get(0).numberFiles() == isEqualTo(backupInfos.get(0).size());
backupInfos.get(0).numberFiles()); assertThat(restoreInfos.get(0).numberFiles()).
isEqualTo(backupInfos.get(0).numberFiles());
rdb.restoreDBFromLatestBackup( rdb.restoreDBFromLatestBackup(
dbFolder.getRoot().getAbsolutePath(), dbFolder.getRoot().getAbsolutePath(),
@ -94,7 +97,8 @@ public class BackupableDBTest {
// do nothing because there is only one backup // do nothing because there is only one backup
rdb.purgeOldBackups(1); rdb.purgeOldBackups(1);
restoreInfos = rdb.getBackupInfos(); restoreInfos = rdb.getBackupInfos();
assert(restoreInfos.size() == 1); assertThat(restoreInfos.size()).
isEqualTo(1);
rdb.dispose(); rdb.dispose();
ropt.dispose(); ropt.dispose();
@ -102,40 +106,40 @@ public class BackupableDBTest {
bdb = BackupableDB.open(opt, bopt, bdb = BackupableDB.open(opt, bopt,
dbFolder.getRoot().getAbsolutePath()); dbFolder.getRoot().getAbsolutePath());
value = bdb.get("abc".getBytes()); value = bdb.get("abc".getBytes());
assert(new String(value).equals("def")); assertThat(new String(value)).
isEqualTo("def");
bdb.createNewBackup(false); bdb.createNewBackup(false);
// after new backup there must be two backup infos // after new backup there must be two backup infos
backupInfos = bdb.getBackupInfos(); backupInfos = bdb.getBackupInfos();
assert(backupInfos.size() == 2); assertThat(backupInfos.size()).
isEqualTo(2);
// deleting the backup must be possible using the // deleting the backup must be possible using the
// id provided by backup infos // id provided by backup infos
bdb.deleteBackup(backupInfos.get(1).backupId()); bdb.deleteBackup(backupInfos.get(1).backupId());
// after deletion there should only be one info // after deletion there should only be one info
backupInfos = bdb.getBackupInfos(); backupInfos = bdb.getBackupInfos();
assert(backupInfos.size() == 1); assertThat(backupInfos.size()).
isEqualTo(1);
bdb.createNewBackup(false); bdb.createNewBackup(false);
bdb.createNewBackup(false); bdb.createNewBackup(false);
bdb.createNewBackup(false); bdb.createNewBackup(false);
backupInfos = bdb.getBackupInfos(); backupInfos = bdb.getBackupInfos();
assert(backupInfos.size() == 4); assertThat(backupInfos.size()).
isEqualTo(4);
// purge everything and keep two // purge everything and keep two
bdb.purgeOldBackups(2); bdb.purgeOldBackups(2);
// backup infos need to be two // backup infos need to be two
backupInfos = bdb.getBackupInfos(); backupInfos = bdb.getBackupInfos();
assert(backupInfos.size() == 2); assertThat(backupInfos.size()).
assert(backupInfos.get(0).backupId() == 4); isEqualTo(2);
assert(backupInfos.get(1).backupId() == 5); assertThat(backupInfos.get(0).backupId()).
} catch (RocksDBException e) { isEqualTo(4);
System.err.format("[ERROR]: %s%n", e); assertThat(backupInfos.get(1).backupId()).
e.printStackTrace(); isEqualTo(5);
} finally {
opt.dispose(); opt.dispose();
bopt.dispose(); bopt.dispose();
if (bdb != null) {
bdb.close(); bdb.close();
} }
} }
System.out.println("Passed BackupableDBTest.");
}
}

@ -5,7 +5,6 @@
package org.rocksdb.test; package org.rocksdb.test;
import org.junit.AfterClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.rocksdb.*; import org.rocksdb.*;
@ -18,13 +17,8 @@ public class BlockBasedTableConfigTest {
public static final RocksMemoryResource rocksMemoryResource = public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource(); new RocksMemoryResource();
@AfterClass
public static void printMessage(){
System.out.println("Passed BlockBasedTableConfigTest.");
}
@Test @Test
public void shouldTestBlockBasedTableConfig() { public void blockBasedTableConfig() {
BlockBasedTableConfig blockBasedTableConfig = BlockBasedTableConfig blockBasedTableConfig =
new BlockBasedTableConfig(); new BlockBasedTableConfig();
blockBasedTableConfig.setNoBlockCache(true); blockBasedTableConfig.setNoBlockCache(true);
@ -68,7 +62,7 @@ public class BlockBasedTableConfigTest {
} }
@Test @Test
public void shouldTestBlockBasedTableWithFilter() { public void blockBasedTableWithFilter() {
Options options = new Options(); Options options = new Options();
options.setTableFormatConfig( options.setTableFormatConfig(
new BlockBasedTableConfig().setFilter( new BlockBasedTableConfig().setFilter(
@ -78,7 +72,7 @@ public class BlockBasedTableConfigTest {
} }
@Test @Test
public void shouldTestBlockBasedTableWithoutFilter() { public void blockBasedTableWithoutFilter() {
Options options = new Options(); Options options = new Options();
options.setTableFormatConfig( options.setTableFormatConfig(
new BlockBasedTableConfig().setFilter(null)); new BlockBasedTableConfig().setFilter(null));

@ -26,7 +26,7 @@ public class ColumnFamilyTest {
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@Test @Test
public void shouldTestColumnFamilies() { public void columnFamilies() {
String db_path = dbFolder.getRoot().getAbsolutePath(); String db_path = dbFolder.getRoot().getAbsolutePath();
RocksDB db = null; RocksDB db = null;
Options options = new Options(); Options options = new Options();
@ -291,6 +291,5 @@ public class ColumnFamilyTest {
db.close(); db.close();
// be sure to dispose c++ pointers // be sure to dispose c++ pointers
options.dispose(); options.dispose();
System.out.println("Passed ColumnFamilyTest.");
} }
} }

@ -18,7 +18,7 @@ public class ComparatorOptionsTest {
new RocksMemoryResource(); new RocksMemoryResource();
@Test @Test
public void shouldTestComparatorOptions() { public void comparatorOptions() {
final ComparatorOptions copt = new ComparatorOptions(); final ComparatorOptions copt = new ComparatorOptions();
assertThat(copt).isNotNull(); assertThat(copt).isNotNull();
@ -32,6 +32,5 @@ public class ComparatorOptionsTest {
} }
copt.dispose(); copt.dispose();
System.out.println("Passed ComparatorOptionsTest");
} }
} }

@ -5,7 +5,6 @@
package org.rocksdb.test; package org.rocksdb.test;
import org.junit.AfterClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -26,13 +25,8 @@ public class ComparatorTest {
@Rule @Rule
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@AfterClass
public static void printMessage(){
System.out.println("Passed ComparatorTest.");
}
@Test @Test
public void shouldTestComparator() throws IOException { public void javaComparator() throws IOException {
final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() { final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() {
@Override @Override
@ -58,7 +52,7 @@ public class ComparatorTest {
} }
@Test @Test
public void shouldTestBuiltinForwardComparator() public void builtinForwardComparator()
throws RocksDBException { throws RocksDBException {
Options options = new Options(); Options options = new Options();
options.setCreateIfMissing(true); options.setCreateIfMissing(true);
@ -112,7 +106,7 @@ public class ComparatorTest {
} }
@Test @Test
public void shouldTestBuiltinReverseComparator() public void builtinReverseComparator()
throws RocksDBException { throws RocksDBException {
Options options = new Options(); Options options = new Options();
options.setCreateIfMissing(true); options.setCreateIfMissing(true);
@ -170,7 +164,7 @@ public class ComparatorTest {
} }
@Test @Test
public void shouldTestBuiltinComparatorEnum(){ public void builtinComparatorEnum(){
assertThat(BuiltinComparator.BYTEWISE_COMPARATOR.ordinal()) assertThat(BuiltinComparator.BYTEWISE_COMPARATOR.ordinal())
.isEqualTo(0); .isEqualTo(0);
assertThat( assertThat(

@ -5,224 +5,252 @@
package org.rocksdb.test; package org.rocksdb.test;
import org.rocksdb.DBOptions; import org.junit.ClassRule;
import org.rocksdb.DBOptionsInterface; import org.junit.Test;
import org.rocksdb.RocksDB; import org.rocksdb.*;
import org.rocksdb.RocksDBException;
import java.util.Random; import java.util.Random;
import static org.assertj.core.api.Assertions.assertThat;
public class DBOptionsTest { 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. Random rand = PlatformRandomHelper.
getPlatformSpecificRandomFactory(); getPlatformSpecificRandomFactory();
{ // CreateIfMissing test { // CreateIfMissing test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setCreateIfMissing(boolValue); opt.setCreateIfMissing(boolValue);
assert(opt.createIfMissing() == boolValue); assertThat(opt.createIfMissing()).
isEqualTo(boolValue);
} }
{ // CreateMissingColumnFamilies test { // CreateMissingColumnFamilies test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setCreateMissingColumnFamilies(boolValue); opt.setCreateMissingColumnFamilies(boolValue);
assert(opt.createMissingColumnFamilies() == boolValue); assertThat(opt.createMissingColumnFamilies()).
isEqualTo(boolValue);
} }
{ // ErrorIfExists test { // ErrorIfExists test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setErrorIfExists(boolValue); opt.setErrorIfExists(boolValue);
assert(opt.errorIfExists() == boolValue); assertThat(opt.errorIfExists()).isEqualTo(boolValue);
} }
{ // ParanoidChecks test { // ParanoidChecks test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setParanoidChecks(boolValue); opt.setParanoidChecks(boolValue);
assert(opt.paranoidChecks() == boolValue); assertThat(opt.paranoidChecks()).
isEqualTo(boolValue);
} }
{ {
// MaxTotalWalSize test // MaxTotalWalSize test
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setMaxTotalWalSize(longValue); opt.setMaxTotalWalSize(longValue);
assert(opt.maxTotalWalSize() == longValue); assertThat(opt.maxTotalWalSize()).
isEqualTo(longValue);
} }
{ // MaxOpenFiles test { // MaxOpenFiles test
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMaxOpenFiles(intValue); opt.setMaxOpenFiles(intValue);
assert(opt.maxOpenFiles() == intValue); assertThat(opt.maxOpenFiles()).isEqualTo(intValue);
} }
{ // DisableDataSync test { // DisableDataSync test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setDisableDataSync(boolValue); opt.setDisableDataSync(boolValue);
assert(opt.disableDataSync() == boolValue); assertThat(opt.disableDataSync()).
isEqualTo(boolValue);
} }
{ // UseFsync test { // UseFsync test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setUseFsync(boolValue); opt.setUseFsync(boolValue);
assert(opt.useFsync() == boolValue); assertThat(opt.useFsync()).isEqualTo(boolValue);
} }
{ // DbLogDir test { // DbLogDir test
String str = "path/to/DbLogDir"; String str = "path/to/DbLogDir";
opt.setDbLogDir(str); opt.setDbLogDir(str);
assert(opt.dbLogDir().equals(str)); assertThat(opt.dbLogDir()).isEqualTo(str);
} }
{ // WalDir test { // WalDir test
String str = "path/to/WalDir"; String str = "path/to/WalDir";
opt.setWalDir(str); opt.setWalDir(str);
assert(opt.walDir().equals(str)); assertThat(opt.walDir()).isEqualTo(str);
} }
{ // DeleteObsoleteFilesPeriodMicros test { // DeleteObsoleteFilesPeriodMicros test
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setDeleteObsoleteFilesPeriodMicros(longValue); opt.setDeleteObsoleteFilesPeriodMicros(longValue);
assert(opt.deleteObsoleteFilesPeriodMicros() == longValue); assertThat(opt.deleteObsoleteFilesPeriodMicros()).
isEqualTo(longValue);
} }
{ // MaxBackgroundCompactions test { // MaxBackgroundCompactions test
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMaxBackgroundCompactions(intValue); opt.setMaxBackgroundCompactions(intValue);
assert(opt.maxBackgroundCompactions() == intValue); assertThat(opt.maxBackgroundCompactions()).
isEqualTo(intValue);
} }
{ // MaxBackgroundFlushes test { // MaxBackgroundFlushes test
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMaxBackgroundFlushes(intValue); opt.setMaxBackgroundFlushes(intValue);
assert(opt.maxBackgroundFlushes() == intValue); assertThat(opt.maxBackgroundFlushes()).
isEqualTo(intValue);
} }
{ // MaxLogFileSize test { // MaxLogFileSize test
try {
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setMaxLogFileSize(longValue); opt.setMaxLogFileSize(longValue);
assert(opt.maxLogFileSize() == longValue); assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
} catch (RocksDBException e) {
System.out.println(e.getMessage());
assert(false);
}
} }
{ // LogFileTimeToRoll test { // LogFileTimeToRoll test
try {
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setLogFileTimeToRoll(longValue); opt.setLogFileTimeToRoll(longValue);
assert(opt.logFileTimeToRoll() == longValue); assertThat(opt.logFileTimeToRoll()).
} catch (RocksDBException e) { isEqualTo(longValue);
assert(false);
}
} }
{ // KeepLogFileNum test { // KeepLogFileNum test
try {
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setKeepLogFileNum(longValue); opt.setKeepLogFileNum(longValue);
assert(opt.keepLogFileNum() == longValue); assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
} catch (RocksDBException e) {
assert(false);
}
} }
{ // MaxManifestFileSize test { // MaxManifestFileSize test
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setMaxManifestFileSize(longValue); opt.setMaxManifestFileSize(longValue);
assert(opt.maxManifestFileSize() == longValue); assertThat(opt.maxManifestFileSize()).
isEqualTo(longValue);
} }
{ // TableCacheNumshardbits test { // TableCacheNumshardbits test
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setTableCacheNumshardbits(intValue); opt.setTableCacheNumshardbits(intValue);
assert(opt.tableCacheNumshardbits() == intValue); assertThat(opt.tableCacheNumshardbits()).
isEqualTo(intValue);
} }
{ // TableCacheRemoveScanCountLimit test { // TableCacheRemoveScanCountLimit test
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setTableCacheRemoveScanCountLimit(intValue); 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 { // WalTtlSeconds test
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setWalTtlSeconds(longValue); opt.setWalTtlSeconds(longValue);
assert(opt.walTtlSeconds() == longValue); assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
} }
{ // ManifestPreallocationSize test { // ManifestPreallocationSize test
try {
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setManifestPreallocationSize(longValue); opt.setManifestPreallocationSize(longValue);
assert(opt.manifestPreallocationSize() == longValue); assertThat(opt.manifestPreallocationSize()).
} catch (RocksDBException e) { isEqualTo(longValue);
assert(false);
}
} }
{ // AllowOsBuffer test { // AllowOsBuffer test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setAllowOsBuffer(boolValue); opt.setAllowOsBuffer(boolValue);
assert(opt.allowOsBuffer() == boolValue); assertThat(opt.allowOsBuffer()).isEqualTo(boolValue);
} }
{ // AllowMmapReads test { // AllowMmapReads test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setAllowMmapReads(boolValue); opt.setAllowMmapReads(boolValue);
assert(opt.allowMmapReads() == boolValue); assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
} }
{ // AllowMmapWrites test { // AllowMmapWrites test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setAllowMmapWrites(boolValue); opt.setAllowMmapWrites(boolValue);
assert(opt.allowMmapWrites() == boolValue); assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
} }
{ // IsFdCloseOnExec test { // IsFdCloseOnExec test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setIsFdCloseOnExec(boolValue); opt.setIsFdCloseOnExec(boolValue);
assert(opt.isFdCloseOnExec() == boolValue); assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
} }
{ // SkipLogErrorOnRecovery test { // SkipLogErrorOnRecovery test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setSkipLogErrorOnRecovery(boolValue); opt.setSkipLogErrorOnRecovery(boolValue);
assert(opt.skipLogErrorOnRecovery() == boolValue); assertThat(opt.skipLogErrorOnRecovery()).isEqualTo(boolValue);
} }
{ // StatsDumpPeriodSec test { // StatsDumpPeriodSec test
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setStatsDumpPeriodSec(intValue); opt.setStatsDumpPeriodSec(intValue);
assert(opt.statsDumpPeriodSec() == intValue); assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
} }
{ // AdviseRandomOnOpen test { // AdviseRandomOnOpen test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setAdviseRandomOnOpen(boolValue); opt.setAdviseRandomOnOpen(boolValue);
assert(opt.adviseRandomOnOpen() == boolValue); assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
} }
{ // UseAdaptiveMutex test { // UseAdaptiveMutex test
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setUseAdaptiveMutex(boolValue); opt.setUseAdaptiveMutex(boolValue);
assert(opt.useAdaptiveMutex() == boolValue); assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
} }
{ // BytesPerSync test { // BytesPerSync test
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setBytesPerSync(longValue); opt.setBytesPerSync(longValue);
assert(opt.bytesPerSync() == longValue); assertThat(opt.bytesPerSync()).isEqualTo(longValue);
} }
} }
public static void main(String[] args) { @Test
DBOptions opt = new DBOptions(); public void rateLimiterConfig() {
testDBOptions(opt); DBOptions options = new DBOptions();
opt.dispose(); RateLimiterConfig rateLimiterConfig =
System.out.println("Passed DBOptionsTest"); 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();
} }
} }

@ -23,7 +23,7 @@ public class DirectComparatorTest {
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@Test @Test
public void shouldTestDirectComparator() throws IOException { public void directComparator() throws IOException {
final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() { final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() {
@Override @Override
@ -49,7 +49,5 @@ public class DirectComparatorTest {
// test the round-tripability of keys written and read with the DirectComparator // test the round-tripability of keys written and read with the DirectComparator
comparatorTest.testRoundtrip(FileSystems.getDefault().getPath( comparatorTest.testRoundtrip(FileSystems.getDefault().getPath(
dbFolder.getRoot().getAbsolutePath())); dbFolder.getRoot().getAbsolutePath()));
System.out.println("Passed DirectComparatorTest");
} }
} }

@ -16,10 +16,9 @@ public class FilterTest {
new RocksMemoryResource(); new RocksMemoryResource();
@Test @Test
public void shouldTestFilter() { public void filter() {
Options options = new Options(); Options options = new Options();
// test table config // test table config
BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
options.setTableFormatConfig(new BlockBasedTableConfig(). options.setTableFormatConfig(new BlockBasedTableConfig().
setFilter(new BloomFilter())); setFilter(new BloomFilter()));
options.dispose(); options.dispose();
@ -27,7 +26,7 @@ public class FilterTest {
System.runFinalization(); System.runFinalization();
// new Bloom filter // new Bloom filter
options = new Options(); options = new Options();
blockConfig = new BlockBasedTableConfig(); BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
blockConfig.setFilter(new BloomFilter()); blockConfig.setFilter(new BloomFilter());
options.setTableFormatConfig(blockConfig); options.setTableFormatConfig(blockConfig);
BloomFilter bloomFilter = new BloomFilter(10); BloomFilter bloomFilter = new BloomFilter(10);
@ -38,10 +37,5 @@ public class FilterTest {
blockConfig.setFilter(new BloomFilter(10, false)); blockConfig.setFilter(new BloomFilter(10, false));
options.setTableFormatConfig(blockConfig); options.setTableFormatConfig(blockConfig);
options.dispose(); options.dispose();
options = null;
blockConfig = null;
System.gc();
System.runFinalization();
System.out.println("Passed FilterTest.");
} }
} }

@ -4,73 +4,79 @@
// of patent rights can be found in the PATENTS file in the same directory. // of patent rights can be found in the PATENTS file in the same directory.
package org.rocksdb.test; 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 org.rocksdb.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class KeyMayExistTest { 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; RocksDB db;
DBOptions options = new DBOptions(); DBOptions options = new DBOptions();
options.setCreateIfMissing(true) options.setCreateIfMissing(true)
.setCreateMissingColumnFamilies(true); .setCreateMissingColumnFamilies(true);
try {
// open database using cf names // open database using cf names
List<ColumnFamilyDescriptor> cfNames = List<ColumnFamilyDescriptor> cfDescriptors =
new ArrayList<ColumnFamilyDescriptor>(); new ArrayList<ColumnFamilyDescriptor>();
List<ColumnFamilyHandle> columnFamilyHandleList = List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<ColumnFamilyHandle>(); new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor("default")); cfDescriptors.add(new ColumnFamilyDescriptor("default"));
cfNames.add(new ColumnFamilyDescriptor("new_cf")); cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
db = RocksDB.open(options, DB_PATH, cfNames, columnFamilyHandleList); db = RocksDB.open(options,
assert(columnFamilyHandleList.size()==2); dbFolder.getRoot().getAbsolutePath(),
cfDescriptors, columnFamilyHandleList);
assertThat(columnFamilyHandleList.size()).
isEqualTo(2);
db.put("key".getBytes(), "value".getBytes()); db.put("key".getBytes(), "value".getBytes());
// Test without column family // Test without column family
StringBuffer retValue = new StringBuffer(); StringBuffer retValue = new StringBuffer();
if (db.keyMayExist("key".getBytes(), retValue)) { boolean exists = db.keyMayExist("key".getBytes(), retValue);
assert(retValue.toString().equals("value")); assertThat(exists).isTrue();
} else { assertThat(retValue.toString()).
assert(false); isEqualTo("value");
}
// Test without column family but with readOptions // Test without column family but with readOptions
retValue = new StringBuffer(); retValue = new StringBuffer();
if (db.keyMayExist(new ReadOptions(), "key".getBytes(), exists = db.keyMayExist(new ReadOptions(), "key".getBytes(),
retValue)) { retValue);
assert(retValue.toString().equals("value")); assertThat(exists).isTrue();
} else { assertThat(retValue.toString()).
assert(false); isEqualTo("value");
}
// Test with column family // Test with column family
retValue = new StringBuffer(); retValue = new StringBuffer();
if (db.keyMayExist(columnFamilyHandleList.get(0), "key".getBytes(), exists = db.keyMayExist(columnFamilyHandleList.get(0), "key".getBytes(),
retValue)) { retValue);
assert(retValue.toString().equals("value")); assertThat(exists).isTrue();
} else { assertThat(retValue.toString()).
assert(false); isEqualTo("value");
}
// Test with column family and readOptions // Test with column family and readOptions
retValue = new StringBuffer(); retValue = new StringBuffer();
if (db.keyMayExist(new ReadOptions(), exists = db.keyMayExist(new ReadOptions(),
columnFamilyHandleList.get(0), "key".getBytes(), columnFamilyHandleList.get(0), "key".getBytes(),
retValue)) { retValue);
assert(retValue.toString().equals("value")); assertThat(exists).isTrue();
} else { assertThat(retValue.toString()).
assert(false); isEqualTo("value");
}
// KeyMayExist in CF1 must return false // KeyMayExist in CF1 must return false
assert(db.keyMayExist(columnFamilyHandleList.get(1), "key".getBytes(), assertThat(db.keyMayExist(columnFamilyHandleList.get(1),
retValue) == false); "key".getBytes(), retValue)).isFalse();
System.out.println("Passed KeyMayExistTest");
}catch (RocksDBException e){
e.printStackTrace();
assert(false);
}
} }
} }

@ -9,6 +9,8 @@ import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.rocksdb.*; import org.rocksdb.*;
import static org.assertj.core.api.Assertions.assertThat;
public class MemTableTest { public class MemTableTest {
@ClassRule @ClassRule
@ -16,22 +18,27 @@ public class MemTableTest {
new RocksMemoryResource(); new RocksMemoryResource();
@Test @Test
public void shouldTestMemTable() throws RocksDBException { public void memTable() throws RocksDBException {
Options options = new Options(); Options options = new Options();
// Test HashSkipListMemTableConfig // Test HashSkipListMemTableConfig
HashSkipListMemTableConfig memTableConfig = HashSkipListMemTableConfig memTableConfig =
new HashSkipListMemTableConfig(); new HashSkipListMemTableConfig();
assert(memTableConfig.bucketCount() == 1000000); assertThat(memTableConfig.bucketCount()).
isEqualTo(1000000);
memTableConfig.setBucketCount(2000000); memTableConfig.setBucketCount(2000000);
assert(memTableConfig.bucketCount() == 2000000); assertThat(memTableConfig.bucketCount()).
assert(memTableConfig.height() == 4); isEqualTo(2000000);
assertThat(memTableConfig.height()).
isEqualTo(4);
memTableConfig.setHeight(5); memTableConfig.setHeight(5);
assert(memTableConfig.height() == 5); assertThat(memTableConfig.height()).
assert(memTableConfig.branchingFactor() == 4); isEqualTo(5);
assertThat(memTableConfig.branchingFactor()).
isEqualTo(4);
memTableConfig.setBranchingFactor(6); memTableConfig.setBranchingFactor(6);
assert(memTableConfig.branchingFactor() == 6); assertThat(memTableConfig.branchingFactor()).
isEqualTo(6);
options.setMemTableConfig(memTableConfig); options.setMemTableConfig(memTableConfig);
memTableConfig = null;
options.dispose(); options.dispose();
System.gc(); System.gc();
System.runFinalization(); System.runFinalization();
@ -39,11 +46,12 @@ public class MemTableTest {
options = new Options(); options = new Options();
SkipListMemTableConfig skipMemTableConfig = SkipListMemTableConfig skipMemTableConfig =
new SkipListMemTableConfig(); new SkipListMemTableConfig();
assert(skipMemTableConfig.lookahead() == 0); assertThat(skipMemTableConfig.lookahead()).
isEqualTo(0);
skipMemTableConfig.setLookahead(20); skipMemTableConfig.setLookahead(20);
assert(skipMemTableConfig.lookahead() == 20); assertThat(skipMemTableConfig.lookahead()).
isEqualTo(20);
options.setMemTableConfig(skipMemTableConfig); options.setMemTableConfig(skipMemTableConfig);
skipMemTableConfig = null;
options.dispose(); options.dispose();
System.gc(); System.gc();
System.runFinalization(); System.runFinalization();
@ -51,31 +59,38 @@ public class MemTableTest {
options = new Options(); options = new Options();
HashLinkedListMemTableConfig hashLinkedListMemTableConfig = HashLinkedListMemTableConfig hashLinkedListMemTableConfig =
new HashLinkedListMemTableConfig(); new HashLinkedListMemTableConfig();
assert(hashLinkedListMemTableConfig.bucketCount() == 50000); assertThat(hashLinkedListMemTableConfig.bucketCount()).
isEqualTo(50000);
hashLinkedListMemTableConfig.setBucketCount(100000); hashLinkedListMemTableConfig.setBucketCount(100000);
assert(hashLinkedListMemTableConfig.bucketCount() == 100000); assertThat(hashLinkedListMemTableConfig.bucketCount()).
assert(hashLinkedListMemTableConfig.hugePageTlbSize() == 0); isEqualTo(100000);
assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
isEqualTo(0);
hashLinkedListMemTableConfig.setHugePageTlbSize(1); hashLinkedListMemTableConfig.setHugePageTlbSize(1);
assert(hashLinkedListMemTableConfig.hugePageTlbSize() == 1); assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
assert(hashLinkedListMemTableConfig. isEqualTo(1);
bucketEntriesLoggingThreshold() == 4096); assertThat(hashLinkedListMemTableConfig.
bucketEntriesLoggingThreshold()).
isEqualTo(4096);
hashLinkedListMemTableConfig. hashLinkedListMemTableConfig.
setBucketEntriesLoggingThreshold(200); setBucketEntriesLoggingThreshold(200);
assert(hashLinkedListMemTableConfig. assertThat(hashLinkedListMemTableConfig.
bucketEntriesLoggingThreshold() == 200); bucketEntriesLoggingThreshold()).
assert(hashLinkedListMemTableConfig. isEqualTo(200);
ifLogBucketDistWhenFlush()); assertThat(hashLinkedListMemTableConfig.
ifLogBucketDistWhenFlush()).isTrue();
hashLinkedListMemTableConfig. hashLinkedListMemTableConfig.
setIfLogBucketDistWhenFlush(false); setIfLogBucketDistWhenFlush(false);
assert(!hashLinkedListMemTableConfig. assertThat(hashLinkedListMemTableConfig.
ifLogBucketDistWhenFlush()); ifLogBucketDistWhenFlush()).isFalse();
assert(hashLinkedListMemTableConfig. assertThat(hashLinkedListMemTableConfig.
thresholdUseSkiplist() == 256); thresholdUseSkiplist()).
isEqualTo(256);
hashLinkedListMemTableConfig.setThresholdUseSkiplist(29); hashLinkedListMemTableConfig.setThresholdUseSkiplist(29);
assert(hashLinkedListMemTableConfig. assertThat(hashLinkedListMemTableConfig.
thresholdUseSkiplist() == 29); thresholdUseSkiplist()).
isEqualTo(29);
options.setMemTableConfig(hashLinkedListMemTableConfig); options.setMemTableConfig(hashLinkedListMemTableConfig);
hashLinkedListMemTableConfig = null;
options.dispose(); options.dispose();
System.gc(); System.gc();
System.runFinalization(); System.runFinalization();
@ -83,14 +98,14 @@ public class MemTableTest {
options = new Options(); options = new Options();
VectorMemTableConfig vectorMemTableConfig = VectorMemTableConfig vectorMemTableConfig =
new VectorMemTableConfig(); new VectorMemTableConfig();
assert(vectorMemTableConfig.reservedSize() == 0); assertThat(vectorMemTableConfig.reservedSize()).
isEqualTo(0);
vectorMemTableConfig.setReservedSize(123); vectorMemTableConfig.setReservedSize(123);
assert(vectorMemTableConfig.reservedSize() == 123); assertThat(vectorMemTableConfig.reservedSize()).
isEqualTo(123);
options.setMemTableConfig(vectorMemTableConfig); options.setMemTableConfig(vectorMemTableConfig);
vectorMemTableConfig = null;
options.dispose(); options.dispose();
System.gc(); System.gc();
System.runFinalization(); System.runFinalization();
System.out.println("Passed MemTableTest.");
} }
} }

@ -8,13 +8,14 @@ package org.rocksdb.test;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import org.junit.AfterClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.rocksdb.*; import org.rocksdb.*;
import static org.assertj.core.api.Assertions.assertThat;
public class MergeTest { public class MergeTest {
@ClassRule @ClassRule
@ -24,13 +25,8 @@ public class MergeTest {
@Rule @Rule
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@AfterClass
public static void printMergePass(){
System.out.println("Passed MergeTest.");
}
@Test @Test
public void shouldTestStringOption() public void stringOption()
throws InterruptedException, RocksDBException { throws InterruptedException, RocksDBException {
String db_path_string = String db_path_string =
dbFolder.getRoot().getAbsolutePath(); dbFolder.getRoot().getAbsolutePath();
@ -49,11 +45,11 @@ public class MergeTest {
db.close(); db.close();
opt.dispose(); opt.dispose();
assert(strValue.equals("aa,bb")); assertThat(strValue).isEqualTo("aa,bb");
} }
@Test @Test
public void shouldTestCFStringOption() public void cFStringOption()
throws InterruptedException, RocksDBException { throws InterruptedException, RocksDBException {
DBOptions opt = new DBOptions(); DBOptions opt = new DBOptions();
String db_path_string = String db_path_string =
@ -89,11 +85,11 @@ public class MergeTest {
} }
db.close(); db.close();
opt.dispose(); opt.dispose();
assert(strValue.equals("aa,bb")); assertThat(strValue).isEqualTo("aa,bb");
} }
@Test @Test
public void shouldTestOperatorOption() public void operatorOption()
throws InterruptedException, RocksDBException { throws InterruptedException, RocksDBException {
String db_path_string = String db_path_string =
dbFolder.getRoot().getAbsolutePath(); dbFolder.getRoot().getAbsolutePath();
@ -115,11 +111,11 @@ public class MergeTest {
db.close(); db.close();
opt.dispose(); opt.dispose();
assert(strValue.equals("aa,bb")); assertThat(strValue).isEqualTo("aa,bb");
} }
@Test @Test
public void shouldTestCFOperatorOption() public void cFOperatorOption()
throws InterruptedException, RocksDBException { throws InterruptedException, RocksDBException {
DBOptions opt = new DBOptions(); DBOptions opt = new DBOptions();
String db_path_string = String db_path_string =
@ -165,12 +161,12 @@ public class MergeTest {
columnFamilyHandle.dispose(); columnFamilyHandle.dispose();
db.close(); db.close();
opt.dispose(); opt.dispose();
assert(strValue.equals("aa,bb")); assertThat(strValue).isEqualTo("aa,bb");
assert(strValueTmpCf.equals("xx,yy")); assertThat(strValueTmpCf).isEqualTo("xx,yy");
} }
@Test @Test
public void shouldTestOperatorGcBehaviour() public void operatorGcBehaviour()
throws RocksDBException { throws RocksDBException {
String db_path_string = String db_path_string =
dbFolder.getRoot().getAbsolutePath(); dbFolder.getRoot().getAbsolutePath();
@ -207,9 +203,5 @@ public class MergeTest {
db = RocksDB.open(opt, db_path_string); db = RocksDB.open(opt, db_path_string);
db.close(); db.close();
opt.dispose(); opt.dispose();
stringAppendOperator = null;
newStringAppendOperator = null;
System.gc();
System.runFinalization();
} }
} }

@ -6,23 +6,296 @@
package org.rocksdb.test; package org.rocksdb.test;
import java.util.Random; import java.util.Random;
import org.rocksdb.RocksDB; import org.junit.ClassRule;
import org.rocksdb.Options; import org.junit.Test;
import org.rocksdb.*;
import static org.assertj.core.api.Assertions.assertThat;
public class OptionsTest { public class OptionsTest {
static { @ClassRule
RocksDB.loadLibrary(); public static final RocksMemoryResource rocksMemoryResource =
} new RocksMemoryResource();
public static void main(String[] args) {
@Test
public void options() throws RocksDBException {
Options opt = new Options(); Options opt = new Options();
Random rand = PlatformRandomHelper. Random rand = PlatformRandomHelper.
getPlatformSpecificRandomFactory(); getPlatformSpecificRandomFactory();
DBOptionsTest.testDBOptions(opt); 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(); 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();
} }
} }

@ -5,42 +5,44 @@
package org.rocksdb.test; package org.rocksdb.test;
import org.junit.AfterClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.rocksdb.EncodingType; import org.rocksdb.EncodingType;
import org.rocksdb.PlainTableConfig; import org.rocksdb.PlainTableConfig;
import static org.assertj.core.api.Assertions.assertThat;
public class PlainTableConfigTest { public class PlainTableConfigTest {
@ClassRule @ClassRule
public static final RocksMemoryResource rocksMemoryResource = public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource(); new RocksMemoryResource();
@AfterClass
public static void printMessage(){
System.out.println("Passed PlainTableConfigTest.");
}
@Test @Test
public void shouldTestPlainTableConfig() { public void plainTableConfig() {
PlainTableConfig plainTableConfig = new PlainTableConfig(); PlainTableConfig plainTableConfig = new PlainTableConfig();
plainTableConfig.setKeySize(5); plainTableConfig.setKeySize(5);
assert(plainTableConfig.keySize() == 5); assertThat(plainTableConfig.keySize()).
isEqualTo(5);
plainTableConfig.setBloomBitsPerKey(11); plainTableConfig.setBloomBitsPerKey(11);
assert(plainTableConfig.bloomBitsPerKey() == 11); assertThat(plainTableConfig.bloomBitsPerKey()).
isEqualTo(11);
plainTableConfig.setHashTableRatio(0.95); plainTableConfig.setHashTableRatio(0.95);
assert(plainTableConfig.hashTableRatio() == 0.95); assertThat(plainTableConfig.hashTableRatio()).
isEqualTo(0.95);
plainTableConfig.setIndexSparseness(18); plainTableConfig.setIndexSparseness(18);
assert(plainTableConfig.indexSparseness() == 18); assertThat(plainTableConfig.indexSparseness()).
isEqualTo(18);
plainTableConfig.setHugePageTlbSize(1); plainTableConfig.setHugePageTlbSize(1);
assert(plainTableConfig.hugePageTlbSize() == 1); assertThat(plainTableConfig.hugePageTlbSize()).
isEqualTo(1);
plainTableConfig.setEncodingType(EncodingType.kPrefix); plainTableConfig.setEncodingType(EncodingType.kPrefix);
assert(plainTableConfig.encodingType().equals( assertThat(plainTableConfig.encodingType()).isEqualTo(
EncodingType.kPrefix)); EncodingType.kPrefix);
plainTableConfig.setFullScanMode(true); plainTableConfig.setFullScanMode(true);
assert(plainTableConfig.fullScanMode()); assertThat(plainTableConfig.fullScanMode()).isTrue();
plainTableConfig.setStoreIndexInFile(true); plainTableConfig.setStoreIndexInFile(true);
assert(plainTableConfig.storeIndexInFile()); assertThat(plainTableConfig.storeIndexInFile()).
isTrue();
} }
} }

@ -13,6 +13,8 @@ import org.rocksdb.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class ReadOnlyTest { public class ReadOnlyTest {
@ClassRule @ClassRule
@ -23,32 +25,35 @@ public class ReadOnlyTest {
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@Test @Test
public void shouldTestReadOnlyOpen() { public void readOnlyOpen() throws RocksDBException {
RocksDB db = null, db2 = null, db3 = null; RocksDB db, db2, db3;
List<ColumnFamilyHandle> columnFamilyHandleList = List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>(); new ArrayList<>();
List<ColumnFamilyHandle> db2ColumnFamilyHandleList = List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
new ArrayList<>(); new ArrayList<>();
List<ColumnFamilyHandle> db3ColumnFamilyHandleList = List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList2 =
new ArrayList<>(); new ArrayList<>();
Options options = new Options(); Options options = new Options();
options.setCreateIfMissing(true); options.setCreateIfMissing(true);
try {
db = RocksDB.open(options, db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath()); dbFolder.getRoot().getAbsolutePath());
db.put("key".getBytes(), "value".getBytes()); db.put("key".getBytes(), "value".getBytes());
db2 = RocksDB.openReadOnly( db2 = RocksDB.openReadOnly(
dbFolder.getRoot().getAbsolutePath()); dbFolder.getRoot().getAbsolutePath());
assert("value".equals(new String(db2.get("key".getBytes())))); assertThat("value").
isEqualTo(new String(db2.get("key".getBytes())));
db.close(); db.close();
db2.close(); db2.close();
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
new ColumnFamilyOptions()));
List<ColumnFamilyDescriptor> cfNames = db = RocksDB.open(
new ArrayList<ColumnFamilyDescriptor>(); dbFolder.getRoot().getAbsolutePath(), cfDescriptors, columnFamilyHandleList);
cfNames.add(new ColumnFamilyDescriptor("default"));
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath(), cfNames, columnFamilyHandleList);
columnFamilyHandleList.add(db.createColumnFamily( columnFamilyHandleList.add(db.createColumnFamily(
new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions()))); new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
columnFamilyHandleList.add(db.createColumnFamily( columnFamilyHandleList.add(db.createColumnFamily(
@ -57,85 +62,167 @@ public class ReadOnlyTest {
"value2".getBytes()); "value2".getBytes());
db2 = RocksDB.openReadOnly( db2 = RocksDB.openReadOnly(
dbFolder.getRoot().getAbsolutePath(), cfNames, db2ColumnFamilyHandleList); dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
assert(db2.get("key2".getBytes())==null); readOnlyColumnFamilyHandleList);
assert(db2.get(columnFamilyHandleList.get(0), "key2".getBytes())==null); assertThat(db2.get("key2".getBytes())).isNull();
assertThat(db2.get(readOnlyColumnFamilyHandleList.get(0), "key2".getBytes())).
isNull();
List<ColumnFamilyDescriptor> cfNewName = cfDescriptors.clear();
new ArrayList<>(); cfDescriptors.add(
cfNewName.add(new ColumnFamilyDescriptor("default")); new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
cfNewName.add(new ColumnFamilyDescriptor("new_cf2")); new ColumnFamilyOptions()));
db3 = RocksDB.openReadOnly(dbFolder.getRoot().getAbsolutePath(), cfNewName, db3ColumnFamilyHandleList); cfDescriptors.add(
assert(new String(db3.get(db3ColumnFamilyHandleList.get(1), new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions()));
"key2".getBytes())).equals("value2")); db3 = RocksDB.openReadOnly(
}catch (RocksDBException e){ dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
e.printStackTrace(); readOnlyColumnFamilyHandleList2);
assert(false); 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<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
new ColumnFamilyOptions()));
List<ColumnFamilyHandle> 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 // test that put fails in readonly mode
try { rDb.put("key".getBytes(), "value".getBytes());
db2.put("key".getBytes(), "value".getBytes());
assert(false);
} catch (RocksDBException e) {
assert(true);
} }
try {
db3.put(db3ColumnFamilyHandleList.get(1), @Test(expected = RocksDBException.class)
public void failToCFWriteInReadOnly() throws RocksDBException {
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.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()); "key".getBytes(), "value".getBytes());
assert(false);
} catch (RocksDBException e) {
assert(true);
} }
// test that remove fails in readonly mode
try { @Test(expected = RocksDBException.class)
db2.remove("key".getBytes()); public void failToRemoveInReadOnly() throws RocksDBException {
assert(false); List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
} catch (RocksDBException e) { cfDescriptors.add(
assert(true); new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
new ColumnFamilyOptions()));
List<ColumnFamilyHandle> 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());
} }
try {
db3.remove(db3ColumnFamilyHandleList.get(1), @Test(expected = RocksDBException.class)
public void failToCFRemoveInReadOnly() throws RocksDBException {
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.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()); "key".getBytes());
assert(false);
} catch (RocksDBException e) {
assert(true);
} }
// test that write fails in readonly mode
@Test(expected = RocksDBException.class)
public void failToWriteBatchReadOnly() throws RocksDBException {
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.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(); WriteBatch wb = new WriteBatch();
wb.put("key".getBytes(), "value".getBytes()); wb.put("key".getBytes(), "value".getBytes());
try { rDb.write(new WriteOptions(), wb);
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();
} }
@Test(expected = RocksDBException.class)
public void failToCFWriteBatchReadOnly() throws RocksDBException {
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.setCreateIfMissing(true);
RocksDB db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.close(); db.close();
for (ColumnFamilyHandle columnFamilyHandle :
db2ColumnFamilyHandleList) { RocksDB rDb = RocksDB.openReadOnly(
columnFamilyHandle.dispose(); dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
} readOnlyColumnFamilyHandleList);
db2.close();
for (ColumnFamilyHandle columnFamilyHandle : WriteBatch wb = new WriteBatch();
db3ColumnFamilyHandleList) { wb.put(readOnlyColumnFamilyHandleList.get(0),
columnFamilyHandle.dispose(); "key".getBytes(), "value".getBytes());
} rDb.write(new WriteOptions(), wb);
db3.close();
System.out.println("Passed ReadOnlyTest.");
} }
} }

@ -7,7 +7,6 @@ package org.rocksdb.test;
import java.util.Random; import java.util.Random;
import org.junit.AfterClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -25,13 +24,8 @@ public class ReadOptionsTest {
@Rule @Rule
public ExpectedException exception = ExpectedException.none(); public ExpectedException exception = ExpectedException.none();
@AfterClass
public static void printMessage(){
System.out.println("Passed ReadOptionsTest.");
}
@Test @Test
public void shouldTestReadOptions() { public void readOptions() {
ReadOptions opt = new ReadOptions(); ReadOptions opt = new ReadOptions();
Random rand = new Random(); Random rand = new Random();
{ // VerifyChecksums test { // VerifyChecksums test
@ -60,49 +54,49 @@ public class ReadOptionsTest {
} }
@Test @Test
public void shouldFailVerifyChecksumUninitialized(){ public void failVerifyChecksumUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions( ReadOptions readOptions = setupUninitializedReadOptions(
exception); exception);
readOptions.setVerifyChecksums(true); readOptions.setVerifyChecksums(true);
} }
@Test @Test
public void shouldFailSetFillCacheUninitialized(){ public void failSetFillCacheUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions( ReadOptions readOptions = setupUninitializedReadOptions(
exception); exception);
readOptions.setFillCache(true); readOptions.setFillCache(true);
} }
@Test @Test
public void shouldFailFillCacheUninitialized(){ public void failFillCacheUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions( ReadOptions readOptions = setupUninitializedReadOptions(
exception); exception);
readOptions.fillCache(); readOptions.fillCache();
} }
@Test @Test
public void shouldFailSetTailingUninitialized(){ public void failSetTailingUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions( ReadOptions readOptions = setupUninitializedReadOptions(
exception); exception);
readOptions.setTailing(true); readOptions.setTailing(true);
} }
@Test @Test
public void shouldFailTailingUninitialized(){ public void failTailingUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions( ReadOptions readOptions = setupUninitializedReadOptions(
exception); exception);
readOptions.tailing(); readOptions.tailing();
} }
@Test @Test
public void shouldFailSetSnapshotUninitialized(){ public void failSetSnapshotUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions( ReadOptions readOptions = setupUninitializedReadOptions(
exception); exception);
readOptions.setSnapshot(null); readOptions.setSnapshot(null);
} }
@Test @Test
public void shouldFailSnapshotUninitialized(){ public void failSnapshotUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions( ReadOptions readOptions = setupUninitializedReadOptions(
exception); exception);
readOptions.snapshot(); readOptions.snapshot();

@ -23,7 +23,7 @@ public class RocksIteratorTest {
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@Test @Test
public void shouldTestRocksIteratorGc() public void rocksIteratorGc()
throws RocksDBException { throws RocksDBException {
RocksDB db; RocksDB db;
Options options = new Options(); Options options = new Options();
@ -44,6 +44,5 @@ public class RocksIteratorTest {
iter3.dispose(); iter3.dispose();
System.gc(); System.gc();
System.runFinalization(); System.runFinalization();
System.out.println("Passed RocksIteratorTest.");
} }
} }

@ -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<Class<?>> classes = new ArrayList<>();
for (String arg : args) {
classes.add(Class.forName(arg));
}
runner.run(classes.toArray(new Class[1]));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}

@ -14,6 +14,8 @@ import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException; import org.rocksdb.RocksDBException;
import org.rocksdb.Snapshot; import org.rocksdb.Snapshot;
import static org.assertj.core.api.Assertions.assertThat;
public class SnapshotTest { public class SnapshotTest {
@ClassRule @ClassRule
@ -24,7 +26,7 @@ public class SnapshotTest {
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@Test @Test
public void shouldTestSnapshots() throws RocksDBException { public void snapshots() throws RocksDBException {
RocksDB db; RocksDB db;
Options options = new Options(); Options options = new Options();
options.setCreateIfMissing(true); options.setCreateIfMissing(true);
@ -37,43 +39,43 @@ public class SnapshotTest {
// set snapshot in ReadOptions // set snapshot in ReadOptions
readOptions.setSnapshot(snapshot); readOptions.setSnapshot(snapshot);
// retrieve key value pair // retrieve key value pair
assert(new String(db.get("key".getBytes())) assertThat(new String(db.get("key".getBytes()))).
.equals("value")); isEqualTo("value");
// retrieve key value pair created before // retrieve key value pair created before
// the snapshot was made // the snapshot was made
assert(new String(db.get(readOptions, assertThat(new String(db.get(readOptions,
"key".getBytes())).equals("value")); "key".getBytes()))).isEqualTo("value");
// add new key/value pair // add new key/value pair
db.put("newkey".getBytes(), "newvalue".getBytes()); db.put("newkey".getBytes(), "newvalue".getBytes());
// using no snapshot the latest db entries // using no snapshot the latest db entries
// will be taken into account // will be taken into account
assert(new String(db.get("newkey".getBytes())) assertThat(new String(db.get("newkey".getBytes()))).
.equals("newvalue")); isEqualTo("newvalue");
// snapshopot was created before newkey // snapshopot was created before newkey
assert(db.get(readOptions, "newkey".getBytes()) assertThat(db.get(readOptions, "newkey".getBytes())).
== null); isNull();
// Retrieve snapshot from read options // Retrieve snapshot from read options
Snapshot sameSnapshot = readOptions.snapshot(); Snapshot sameSnapshot = readOptions.snapshot();
readOptions.setSnapshot(sameSnapshot); readOptions.setSnapshot(sameSnapshot);
// results must be the same with new Snapshot // results must be the same with new Snapshot
// instance using the same native pointer // instance using the same native pointer
assert(new String(db.get(readOptions, assertThat(new String(db.get(readOptions,
"key".getBytes())).equals("value")); "key".getBytes()))).isEqualTo("value");
// update key value pair to newvalue // update key value pair to newvalue
db.put("key".getBytes(), "newvalue".getBytes()); db.put("key".getBytes(), "newvalue".getBytes());
// read with previously created snapshot will // read with previously created snapshot will
// read previous version of key value pair // read previous version of key value pair
assert(new String(db.get(readOptions, assertThat(new String(db.get(readOptions,
"key".getBytes())).equals("value")); "key".getBytes()))).isEqualTo("value");
// read for newkey using the snapshot must be // read for newkey using the snapshot must be
// null // null
assert(db.get(readOptions, "newkey".getBytes()) assertThat(db.get(readOptions, "newkey".getBytes())).
== null); isNull();
// setting null to snapshot in ReadOptions leads // setting null to snapshot in ReadOptions leads
// to no Snapshot being used. // to no Snapshot being used.
readOptions.setSnapshot(null); readOptions.setSnapshot(null);
assert(new String(db.get(readOptions, assertThat(new String(db.get(readOptions,
"newkey".getBytes())).equals("newvalue")); "newkey".getBytes()))).isEqualTo("newvalue");
// release Snapshot // release Snapshot
db.releaseSnapshot(snapshot); db.releaseSnapshot(snapshot);
// Close database // Close database

@ -25,7 +25,7 @@ public class StatisticsCollectorTest {
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@Test @Test
public void shouldTestStatisticsCollector() public void statisticsCollector()
throws InterruptedException, RocksDBException { throws InterruptedException, RocksDBException {
Options opt = new Options().createStatistics().setCreateIfMissing(true); Options opt = new Options().createStatistics().setCreateIfMissing(true);
Statistics stats = opt.statisticsPtr(); Statistics stats = opt.statisticsPtr();
@ -49,7 +49,5 @@ public class StatisticsCollectorTest {
db.close(); db.close();
opt.dispose(); opt.dispose();
System.out.println("Stats collector test passed.!");
} }
} }

@ -8,7 +8,6 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors. // found in the LICENSE file. See the AUTHORS file for names of contributors.
package org.rocksdb.test; package org.rocksdb.test;
import org.junit.AfterClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -36,19 +35,14 @@ public class WriteBatchTest {
@Rule @Rule
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@AfterClass
public static void printMergePass(){
System.out.println("Passed WriteBatchTest.");
}
@Test @Test
public void shouldTestEmptyWriteBatch() { public void emptyWriteBatch() {
WriteBatch batch = new WriteBatch(); WriteBatch batch = new WriteBatch();
assertThat(batch.count()).isEqualTo(0); assertThat(batch.count()).isEqualTo(0);
} }
@Test @Test
public void shouldTestMultipleBatchOperations() public void multipleBatchOperations()
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
WriteBatch batch = new WriteBatch(); WriteBatch batch = new WriteBatch();
batch.put("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII")); batch.put("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
@ -66,7 +60,7 @@ public class WriteBatchTest {
} }
@Test @Test
public void shouldTestAppendOperation() public void testAppendOperation()
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
WriteBatch b1 = new WriteBatch(); WriteBatch b1 = new WriteBatch();
WriteBatch b2 = new WriteBatch(); WriteBatch b2 = new WriteBatch();
@ -97,7 +91,7 @@ public class WriteBatchTest {
} }
@Test @Test
public void shouldTestBlobOperation() public void blobOperation()
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
WriteBatch batch = new WriteBatch(); WriteBatch batch = new WriteBatch();
batch.put("k1".getBytes("US-ASCII"), "v1".getBytes("US-ASCII")); batch.put("k1".getBytes("US-ASCII"), "v1".getBytes("US-ASCII"));

@ -5,7 +5,6 @@
package org.rocksdb.test; package org.rocksdb.test;
import org.junit.AfterClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.rocksdb.WriteOptions; import org.rocksdb.WriteOptions;
@ -18,13 +17,8 @@ public class WriteOptionsTest {
public static final RocksMemoryResource rocksMemoryResource = public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource(); new RocksMemoryResource();
@AfterClass
public static void printMessage(){
System.out.println("Passed WriteOptionsTest.");
}
@Test @Test
public void shouldTestWriteOptions(){ public void writeOptions(){
WriteOptions writeOptions = new WriteOptions(); WriteOptions writeOptions = new WriteOptions();
writeOptions.setDisableWAL(true); writeOptions.setDisableWAL(true);
assertThat(writeOptions.disableWAL()).isTrue(); assertThat(writeOptions.disableWAL()).isTrue();

@ -159,6 +159,7 @@
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-all</artifactId>
<version>1.9.5</version> <version>1.9.5</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

Loading…
Cancel
Save