mirror of https://github.com/facebook/rocksdb.git
[RocksJava] Integrated review comments from adamretter in D28209
This commit is contained in:
parent
b092686959
commit
36f3a0bb8e
|
@ -120,7 +120,7 @@ resolve_test_deps:
|
|||
|
||||
test: java resolve_test_deps
|
||||
javac -cp $(JAVA_TESTCLASSPATH) org/rocksdb/test/*.java
|
||||
java -ea -Djava.library.path=.:../ -cp "$(JAVA_TESTCLASSPATH)" org.junit.runner.JUnitCore $(JAVA_TESTS)
|
||||
java -ea -Djava.library.path=.:../ -cp "$(JAVA_TESTCLASSPATH)" org.rocksdb.test.RocksJunitRunner $(JAVA_TESTS)
|
||||
|
||||
db_bench: java
|
||||
javac org/rocksdb/benchmark/*.java
|
||||
|
|
|
@ -13,6 +13,8 @@ import org.rocksdb.*;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BackupableDBTest {
|
||||
|
||||
@ClassRule
|
||||
|
@ -26,7 +28,7 @@ public class BackupableDBTest {
|
|||
public TemporaryFolder backupFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void shouldTestBackupableDb() {
|
||||
public void backupableDb() throws RocksDBException {
|
||||
|
||||
Options opt = new Options();
|
||||
opt.setCreateIfMissing(true);
|
||||
|
@ -34,108 +36,110 @@ public class BackupableDBTest {
|
|||
BackupableDBOptions bopt = new BackupableDBOptions(
|
||||
backupFolder.getRoot().getAbsolutePath(), false,
|
||||
true, false, true, 0, 0);
|
||||
BackupableDB bdb = null;
|
||||
BackupableDB bdb;
|
||||
List<BackupInfo> backupInfos;
|
||||
List<BackupInfo> restoreInfos;
|
||||
try {
|
||||
bdb = BackupableDB.open(opt, bopt,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
|
||||
bdb.put("abc".getBytes(), "def".getBytes());
|
||||
bdb.put("ghi".getBytes(), "jkl".getBytes());
|
||||
bdb = BackupableDB.open(opt, bopt,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
bdb.put("abc".getBytes(), "def".getBytes());
|
||||
bdb.put("ghi".getBytes(), "jkl".getBytes());
|
||||
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assert(backupInfos.size() == 0);
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assertThat(backupInfos.size()).
|
||||
isEqualTo(0);
|
||||
|
||||
bdb.createNewBackup(true);
|
||||
bdb.createNewBackup(true);
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assertThat(backupInfos.size()).
|
||||
isEqualTo(1);
|
||||
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assert(backupInfos.size() == 1);
|
||||
// Retrieving backup infos twice shall not
|
||||
// lead to different results
|
||||
List<BackupInfo> tmpBackupInfo = bdb.getBackupInfos();
|
||||
assertThat(tmpBackupInfo.get(0).backupId()).
|
||||
isEqualTo(backupInfos.get(0).backupId());
|
||||
assertThat(tmpBackupInfo.get(0).timestamp()).
|
||||
isEqualTo(backupInfos.get(0).timestamp());
|
||||
assertThat(tmpBackupInfo.get(0).size()).
|
||||
isEqualTo(backupInfos.get(0).size());
|
||||
assertThat(tmpBackupInfo.get(0).numberFiles()).
|
||||
isEqualTo(backupInfos.get(0).numberFiles());
|
||||
|
||||
// Retrieving backup infos twice shall not
|
||||
// lead to different results
|
||||
List<BackupInfo> tmpBackupInfo = bdb.getBackupInfos();
|
||||
assert(tmpBackupInfo.get(0).backupId() ==
|
||||
backupInfos.get(0).backupId());
|
||||
assert(tmpBackupInfo.get(0).timestamp() ==
|
||||
backupInfos.get(0).timestamp());
|
||||
assert(tmpBackupInfo.get(0).size() ==
|
||||
backupInfos.get(0).size());
|
||||
assert(tmpBackupInfo.get(0).numberFiles() ==
|
||||
backupInfos.get(0).numberFiles());
|
||||
// delete record after backup
|
||||
bdb.remove("abc".getBytes());
|
||||
byte[] value = bdb.get("abc".getBytes());
|
||||
assertThat(value).isNull();
|
||||
bdb.close();
|
||||
|
||||
// delete record after backup
|
||||
bdb.remove("abc".getBytes());
|
||||
byte[] value = bdb.get("abc".getBytes());
|
||||
assert(value == null);
|
||||
bdb.close();
|
||||
// restore from backup
|
||||
RestoreOptions ropt = new RestoreOptions(false);
|
||||
RestoreBackupableDB rdb = new RestoreBackupableDB(bopt);
|
||||
|
||||
// restore from backup
|
||||
RestoreOptions ropt = new RestoreOptions(false);
|
||||
RestoreBackupableDB rdb = new RestoreBackupableDB(bopt);
|
||||
// getting backup infos from restorable db should
|
||||
// lead to the same infos as from backupable db
|
||||
restoreInfos = rdb.getBackupInfos();
|
||||
assertThat(restoreInfos.size()).
|
||||
isEqualTo(backupInfos.size());
|
||||
assertThat(restoreInfos.get(0).backupId()).
|
||||
isEqualTo(backupInfos.get(0).backupId());
|
||||
assertThat(restoreInfos.get(0).timestamp()).
|
||||
isEqualTo(backupInfos.get(0).timestamp());
|
||||
assertThat(restoreInfos.get(0).size()).
|
||||
isEqualTo(backupInfos.get(0).size());
|
||||
assertThat(restoreInfos.get(0).numberFiles()).
|
||||
isEqualTo(backupInfos.get(0).numberFiles());
|
||||
|
||||
// getting backup infos from restorable db should
|
||||
// lead to the same infos as from backupable db
|
||||
restoreInfos = rdb.getBackupInfos();
|
||||
assert(restoreInfos.size() == backupInfos.size());
|
||||
assert(restoreInfos.get(0).backupId() ==
|
||||
backupInfos.get(0).backupId());
|
||||
assert(restoreInfos.get(0).timestamp() ==
|
||||
backupInfos.get(0).timestamp());
|
||||
assert(restoreInfos.get(0).size() ==
|
||||
backupInfos.get(0).size());
|
||||
assert(restoreInfos.get(0).numberFiles() ==
|
||||
backupInfos.get(0).numberFiles());
|
||||
rdb.restoreDBFromLatestBackup(
|
||||
dbFolder.getRoot().getAbsolutePath(),
|
||||
dbFolder.getRoot().getAbsolutePath(),
|
||||
ropt);
|
||||
// do nothing because there is only one backup
|
||||
rdb.purgeOldBackups(1);
|
||||
restoreInfos = rdb.getBackupInfos();
|
||||
assertThat(restoreInfos.size()).
|
||||
isEqualTo(1);
|
||||
rdb.dispose();
|
||||
ropt.dispose();
|
||||
|
||||
rdb.restoreDBFromLatestBackup(
|
||||
dbFolder.getRoot().getAbsolutePath(),
|
||||
dbFolder.getRoot().getAbsolutePath(),
|
||||
ropt);
|
||||
// do nothing because there is only one backup
|
||||
rdb.purgeOldBackups(1);
|
||||
restoreInfos = rdb.getBackupInfos();
|
||||
assert(restoreInfos.size() == 1);
|
||||
rdb.dispose();
|
||||
ropt.dispose();
|
||||
// verify that backed up data contains deleted record
|
||||
bdb = BackupableDB.open(opt, bopt,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
value = bdb.get("abc".getBytes());
|
||||
assertThat(new String(value)).
|
||||
isEqualTo("def");
|
||||
|
||||
// verify that backed up data contains deleted record
|
||||
bdb = BackupableDB.open(opt, bopt,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
value = bdb.get("abc".getBytes());
|
||||
assert(new String(value).equals("def"));
|
||||
bdb.createNewBackup(false);
|
||||
// after new backup there must be two backup infos
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assertThat(backupInfos.size()).
|
||||
isEqualTo(2);
|
||||
// deleting the backup must be possible using the
|
||||
// id provided by backup infos
|
||||
bdb.deleteBackup(backupInfos.get(1).backupId());
|
||||
// after deletion there should only be one info
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assertThat(backupInfos.size()).
|
||||
isEqualTo(1);
|
||||
bdb.createNewBackup(false);
|
||||
bdb.createNewBackup(false);
|
||||
bdb.createNewBackup(false);
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assertThat(backupInfos.size()).
|
||||
isEqualTo(4);
|
||||
// purge everything and keep two
|
||||
bdb.purgeOldBackups(2);
|
||||
// backup infos need to be two
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assertThat(backupInfos.size()).
|
||||
isEqualTo(2);
|
||||
assertThat(backupInfos.get(0).backupId()).
|
||||
isEqualTo(4);
|
||||
assertThat(backupInfos.get(1).backupId()).
|
||||
isEqualTo(5);
|
||||
|
||||
bdb.createNewBackup(false);
|
||||
// after new backup there must be two backup infos
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assert(backupInfos.size() == 2);
|
||||
// deleting the backup must be possible using the
|
||||
// id provided by backup infos
|
||||
bdb.deleteBackup(backupInfos.get(1).backupId());
|
||||
// after deletion there should only be one info
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assert(backupInfos.size() == 1);
|
||||
bdb.createNewBackup(false);
|
||||
bdb.createNewBackup(false);
|
||||
bdb.createNewBackup(false);
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assert(backupInfos.size() == 4);
|
||||
// purge everything and keep two
|
||||
bdb.purgeOldBackups(2);
|
||||
// backup infos need to be two
|
||||
backupInfos = bdb.getBackupInfos();
|
||||
assert(backupInfos.size() == 2);
|
||||
assert(backupInfos.get(0).backupId() == 4);
|
||||
assert(backupInfos.get(1).backupId() == 5);
|
||||
} catch (RocksDBException e) {
|
||||
System.err.format("[ERROR]: %s%n", e);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
opt.dispose();
|
||||
bopt.dispose();
|
||||
if (bdb != null) {
|
||||
bdb.close();
|
||||
}
|
||||
}
|
||||
System.out.println("Passed BackupableDBTest.");
|
||||
opt.dispose();
|
||||
bopt.dispose();
|
||||
bdb.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.*;
|
||||
|
@ -18,13 +17,8 @@ public class BlockBasedTableConfigTest {
|
|||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@AfterClass
|
||||
public static void printMessage(){
|
||||
System.out.println("Passed BlockBasedTableConfigTest.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestBlockBasedTableConfig() {
|
||||
public void blockBasedTableConfig() {
|
||||
BlockBasedTableConfig blockBasedTableConfig =
|
||||
new BlockBasedTableConfig();
|
||||
blockBasedTableConfig.setNoBlockCache(true);
|
||||
|
@ -68,7 +62,7 @@ public class BlockBasedTableConfigTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestBlockBasedTableWithFilter() {
|
||||
public void blockBasedTableWithFilter() {
|
||||
Options options = new Options();
|
||||
options.setTableFormatConfig(
|
||||
new BlockBasedTableConfig().setFilter(
|
||||
|
@ -78,7 +72,7 @@ public class BlockBasedTableConfigTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestBlockBasedTableWithoutFilter() {
|
||||
public void blockBasedTableWithoutFilter() {
|
||||
Options options = new Options();
|
||||
options.setTableFormatConfig(
|
||||
new BlockBasedTableConfig().setFilter(null));
|
||||
|
|
|
@ -26,7 +26,7 @@ public class ColumnFamilyTest {
|
|||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void shouldTestColumnFamilies() {
|
||||
public void columnFamilies() {
|
||||
String db_path = dbFolder.getRoot().getAbsolutePath();
|
||||
RocksDB db = null;
|
||||
Options options = new Options();
|
||||
|
@ -291,6 +291,5 @@ public class ColumnFamilyTest {
|
|||
db.close();
|
||||
// be sure to dispose c++ pointers
|
||||
options.dispose();
|
||||
System.out.println("Passed ColumnFamilyTest.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class ComparatorOptionsTest {
|
|||
new RocksMemoryResource();
|
||||
|
||||
@Test
|
||||
public void shouldTestComparatorOptions() {
|
||||
public void comparatorOptions() {
|
||||
final ComparatorOptions copt = new ComparatorOptions();
|
||||
|
||||
assertThat(copt).isNotNull();
|
||||
|
@ -32,6 +32,5 @@ public class ComparatorOptionsTest {
|
|||
}
|
||||
|
||||
copt.dispose();
|
||||
System.out.println("Passed ComparatorOptionsTest");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -26,13 +25,8 @@ public class ComparatorTest {
|
|||
@Rule
|
||||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@AfterClass
|
||||
public static void printMessage(){
|
||||
System.out.println("Passed ComparatorTest.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestComparator() throws IOException {
|
||||
public void javaComparator() throws IOException {
|
||||
|
||||
final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() {
|
||||
@Override
|
||||
|
@ -58,7 +52,7 @@ public class ComparatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestBuiltinForwardComparator()
|
||||
public void builtinForwardComparator()
|
||||
throws RocksDBException {
|
||||
Options options = new Options();
|
||||
options.setCreateIfMissing(true);
|
||||
|
@ -112,7 +106,7 @@ public class ComparatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestBuiltinReverseComparator()
|
||||
public void builtinReverseComparator()
|
||||
throws RocksDBException {
|
||||
Options options = new Options();
|
||||
options.setCreateIfMissing(true);
|
||||
|
@ -170,7 +164,7 @@ public class ComparatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestBuiltinComparatorEnum(){
|
||||
public void builtinComparatorEnum(){
|
||||
assertThat(BuiltinComparator.BYTEWISE_COMPARATOR.ordinal())
|
||||
.isEqualTo(0);
|
||||
assertThat(
|
||||
|
|
|
@ -5,224 +5,252 @@
|
|||
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.rocksdb.DBOptions;
|
||||
import org.rocksdb.DBOptionsInterface;
|
||||
import org.rocksdb.RocksDB;
|
||||
import org.rocksdb.RocksDBException;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DBOptionsTest {
|
||||
static {
|
||||
RocksDB.loadLibrary();
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@Test
|
||||
public void dbOptions() throws RocksDBException {
|
||||
testDBOptions(new DBOptions());
|
||||
}
|
||||
|
||||
public static void testDBOptions(DBOptionsInterface opt) {
|
||||
static void testDBOptions(DBOptionsInterface opt) throws RocksDBException {
|
||||
Random rand = PlatformRandomHelper.
|
||||
getPlatformSpecificRandomFactory();
|
||||
{ // CreateIfMissing test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setCreateIfMissing(boolValue);
|
||||
assert(opt.createIfMissing() == boolValue);
|
||||
assertThat(opt.createIfMissing()).
|
||||
isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // CreateMissingColumnFamilies test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setCreateMissingColumnFamilies(boolValue);
|
||||
assert(opt.createMissingColumnFamilies() == boolValue);
|
||||
assertThat(opt.createMissingColumnFamilies()).
|
||||
isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // ErrorIfExists test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setErrorIfExists(boolValue);
|
||||
assert(opt.errorIfExists() == boolValue);
|
||||
assertThat(opt.errorIfExists()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // ParanoidChecks test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setParanoidChecks(boolValue);
|
||||
assert(opt.paranoidChecks() == boolValue);
|
||||
assertThat(opt.paranoidChecks()).
|
||||
isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{
|
||||
// MaxTotalWalSize test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setMaxTotalWalSize(longValue);
|
||||
assert(opt.maxTotalWalSize() == longValue);
|
||||
assertThat(opt.maxTotalWalSize()).
|
||||
isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // MaxOpenFiles test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMaxOpenFiles(intValue);
|
||||
assert(opt.maxOpenFiles() == intValue);
|
||||
assertThat(opt.maxOpenFiles()).isEqualTo(intValue);
|
||||
}
|
||||
|
||||
{ // DisableDataSync test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setDisableDataSync(boolValue);
|
||||
assert(opt.disableDataSync() == boolValue);
|
||||
assertThat(opt.disableDataSync()).
|
||||
isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // UseFsync test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setUseFsync(boolValue);
|
||||
assert(opt.useFsync() == boolValue);
|
||||
assertThat(opt.useFsync()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // DbLogDir test
|
||||
String str = "path/to/DbLogDir";
|
||||
opt.setDbLogDir(str);
|
||||
assert(opt.dbLogDir().equals(str));
|
||||
assertThat(opt.dbLogDir()).isEqualTo(str);
|
||||
}
|
||||
|
||||
{ // WalDir test
|
||||
String str = "path/to/WalDir";
|
||||
opt.setWalDir(str);
|
||||
assert(opt.walDir().equals(str));
|
||||
assertThat(opt.walDir()).isEqualTo(str);
|
||||
}
|
||||
|
||||
{ // DeleteObsoleteFilesPeriodMicros test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setDeleteObsoleteFilesPeriodMicros(longValue);
|
||||
assert(opt.deleteObsoleteFilesPeriodMicros() == longValue);
|
||||
assertThat(opt.deleteObsoleteFilesPeriodMicros()).
|
||||
isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // MaxBackgroundCompactions test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMaxBackgroundCompactions(intValue);
|
||||
assert(opt.maxBackgroundCompactions() == intValue);
|
||||
assertThat(opt.maxBackgroundCompactions()).
|
||||
isEqualTo(intValue);
|
||||
}
|
||||
|
||||
{ // MaxBackgroundFlushes test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMaxBackgroundFlushes(intValue);
|
||||
assert(opt.maxBackgroundFlushes() == intValue);
|
||||
assertThat(opt.maxBackgroundFlushes()).
|
||||
isEqualTo(intValue);
|
||||
}
|
||||
|
||||
{ // MaxLogFileSize test
|
||||
try {
|
||||
long longValue = rand.nextLong();
|
||||
opt.setMaxLogFileSize(longValue);
|
||||
assert(opt.maxLogFileSize() == longValue);
|
||||
} catch (RocksDBException e) {
|
||||
System.out.println(e.getMessage());
|
||||
assert(false);
|
||||
}
|
||||
long longValue = rand.nextLong();
|
||||
opt.setMaxLogFileSize(longValue);
|
||||
assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // LogFileTimeToRoll test
|
||||
try {
|
||||
long longValue = rand.nextLong();
|
||||
opt.setLogFileTimeToRoll(longValue);
|
||||
assert(opt.logFileTimeToRoll() == longValue);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
}
|
||||
long longValue = rand.nextLong();
|
||||
opt.setLogFileTimeToRoll(longValue);
|
||||
assertThat(opt.logFileTimeToRoll()).
|
||||
isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // KeepLogFileNum test
|
||||
try {
|
||||
long longValue = rand.nextLong();
|
||||
opt.setKeepLogFileNum(longValue);
|
||||
assert(opt.keepLogFileNum() == longValue);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
}
|
||||
long longValue = rand.nextLong();
|
||||
opt.setKeepLogFileNum(longValue);
|
||||
assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // MaxManifestFileSize test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setMaxManifestFileSize(longValue);
|
||||
assert(opt.maxManifestFileSize() == longValue);
|
||||
assertThat(opt.maxManifestFileSize()).
|
||||
isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // TableCacheNumshardbits test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setTableCacheNumshardbits(intValue);
|
||||
assert(opt.tableCacheNumshardbits() == intValue);
|
||||
assertThat(opt.tableCacheNumshardbits()).
|
||||
isEqualTo(intValue);
|
||||
}
|
||||
|
||||
{ // TableCacheRemoveScanCountLimit test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setTableCacheRemoveScanCountLimit(intValue);
|
||||
assert(opt.tableCacheRemoveScanCountLimit() == intValue);
|
||||
assertThat(opt.tableCacheRemoveScanCountLimit()).
|
||||
isEqualTo(intValue);
|
||||
}
|
||||
|
||||
{ // WalSizeLimitMB test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setWalSizeLimitMB(longValue);
|
||||
assertThat(opt.walSizeLimitMB()).isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // WalTtlSeconds test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setWalTtlSeconds(longValue);
|
||||
assert(opt.walTtlSeconds() == longValue);
|
||||
assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // ManifestPreallocationSize test
|
||||
try {
|
||||
long longValue = rand.nextLong();
|
||||
opt.setManifestPreallocationSize(longValue);
|
||||
assert(opt.manifestPreallocationSize() == longValue);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
}
|
||||
long longValue = rand.nextLong();
|
||||
opt.setManifestPreallocationSize(longValue);
|
||||
assertThat(opt.manifestPreallocationSize()).
|
||||
isEqualTo(longValue);
|
||||
}
|
||||
|
||||
{ // AllowOsBuffer test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setAllowOsBuffer(boolValue);
|
||||
assert(opt.allowOsBuffer() == boolValue);
|
||||
assertThat(opt.allowOsBuffer()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // AllowMmapReads test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setAllowMmapReads(boolValue);
|
||||
assert(opt.allowMmapReads() == boolValue);
|
||||
assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // AllowMmapWrites test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setAllowMmapWrites(boolValue);
|
||||
assert(opt.allowMmapWrites() == boolValue);
|
||||
assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // IsFdCloseOnExec test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setIsFdCloseOnExec(boolValue);
|
||||
assert(opt.isFdCloseOnExec() == boolValue);
|
||||
assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // SkipLogErrorOnRecovery test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setSkipLogErrorOnRecovery(boolValue);
|
||||
assert(opt.skipLogErrorOnRecovery() == boolValue);
|
||||
assertThat(opt.skipLogErrorOnRecovery()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // StatsDumpPeriodSec test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setStatsDumpPeriodSec(intValue);
|
||||
assert(opt.statsDumpPeriodSec() == intValue);
|
||||
assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
|
||||
}
|
||||
|
||||
{ // AdviseRandomOnOpen test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setAdviseRandomOnOpen(boolValue);
|
||||
assert(opt.adviseRandomOnOpen() == boolValue);
|
||||
assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // UseAdaptiveMutex test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setUseAdaptiveMutex(boolValue);
|
||||
assert(opt.useAdaptiveMutex() == boolValue);
|
||||
assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
|
||||
}
|
||||
|
||||
{ // BytesPerSync test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setBytesPerSync(longValue);
|
||||
assert(opt.bytesPerSync() == longValue);
|
||||
assertThat(opt.bytesPerSync()).isEqualTo(longValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
DBOptions opt = new DBOptions();
|
||||
testDBOptions(opt);
|
||||
opt.dispose();
|
||||
System.out.println("Passed DBOptionsTest");
|
||||
@Test
|
||||
public void rateLimiterConfig() {
|
||||
DBOptions options = new DBOptions();
|
||||
RateLimiterConfig rateLimiterConfig =
|
||||
new GenericRateLimiterConfig(1000, 0, 1);
|
||||
options.setRateLimiterConfig(rateLimiterConfig);
|
||||
options.dispose();
|
||||
// Test with parameter initialization
|
||||
DBOptions anotherOptions = new DBOptions();
|
||||
anotherOptions.setRateLimiterConfig(
|
||||
new GenericRateLimiterConfig(1000));
|
||||
anotherOptions.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statistics() {
|
||||
DBOptions options = new DBOptions();
|
||||
Statistics statistics = options.createStatistics().
|
||||
statisticsPtr();
|
||||
assertThat(statistics).isNotNull();
|
||||
|
||||
DBOptions anotherOptions = new DBOptions();
|
||||
statistics = anotherOptions.statisticsPtr();
|
||||
assertThat(statistics).isNotNull();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class DirectComparatorTest {
|
|||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void shouldTestDirectComparator() throws IOException {
|
||||
public void directComparator() throws IOException {
|
||||
|
||||
final AbstractComparatorTest comparatorTest = new AbstractComparatorTest() {
|
||||
@Override
|
||||
|
@ -49,7 +49,5 @@ public class DirectComparatorTest {
|
|||
// test the round-tripability of keys written and read with the DirectComparator
|
||||
comparatorTest.testRoundtrip(FileSystems.getDefault().getPath(
|
||||
dbFolder.getRoot().getAbsolutePath()));
|
||||
|
||||
System.out.println("Passed DirectComparatorTest");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,9 @@ public class FilterTest {
|
|||
new RocksMemoryResource();
|
||||
|
||||
@Test
|
||||
public void shouldTestFilter() {
|
||||
public void filter() {
|
||||
Options options = new Options();
|
||||
// test table config
|
||||
BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
|
||||
options.setTableFormatConfig(new BlockBasedTableConfig().
|
||||
setFilter(new BloomFilter()));
|
||||
options.dispose();
|
||||
|
@ -27,7 +26,7 @@ public class FilterTest {
|
|||
System.runFinalization();
|
||||
// new Bloom filter
|
||||
options = new Options();
|
||||
blockConfig = new BlockBasedTableConfig();
|
||||
BlockBasedTableConfig blockConfig = new BlockBasedTableConfig();
|
||||
blockConfig.setFilter(new BloomFilter());
|
||||
options.setTableFormatConfig(blockConfig);
|
||||
BloomFilter bloomFilter = new BloomFilter(10);
|
||||
|
@ -38,10 +37,5 @@ public class FilterTest {
|
|||
blockConfig.setFilter(new BloomFilter(10, false));
|
||||
options.setTableFormatConfig(blockConfig);
|
||||
options.dispose();
|
||||
options = null;
|
||||
blockConfig = null;
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
System.out.println("Passed FilterTest.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,73 +4,79 @@
|
|||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KeyMayExistTest {
|
||||
static final String DB_PATH = "/tmp/rocksdbjni_keymayexit_test";
|
||||
static {
|
||||
RocksDB.loadLibrary();
|
||||
}
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public static void main(String[] args){
|
||||
public class KeyMayExistTest {
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void keyMayExist() throws RocksDBException {
|
||||
RocksDB db;
|
||||
DBOptions options = new DBOptions();
|
||||
options.setCreateIfMissing(true)
|
||||
.setCreateMissingColumnFamilies(true);
|
||||
try {
|
||||
// open database using cf names
|
||||
List<ColumnFamilyDescriptor> cfNames =
|
||||
new ArrayList<ColumnFamilyDescriptor>();
|
||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||
new ArrayList<ColumnFamilyHandle>();
|
||||
cfNames.add(new ColumnFamilyDescriptor("default"));
|
||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
||||
db = RocksDB.open(options, DB_PATH, cfNames, columnFamilyHandleList);
|
||||
assert(columnFamilyHandleList.size()==2);
|
||||
// open database using cf names
|
||||
List<ColumnFamilyDescriptor> cfDescriptors =
|
||||
new ArrayList<ColumnFamilyDescriptor>();
|
||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||
new ArrayList<>();
|
||||
cfDescriptors.add(new ColumnFamilyDescriptor("default"));
|
||||
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
|
||||
db = RocksDB.open(options,
|
||||
dbFolder.getRoot().getAbsolutePath(),
|
||||
cfDescriptors, columnFamilyHandleList);
|
||||
assertThat(columnFamilyHandleList.size()).
|
||||
isEqualTo(2);
|
||||
db.put("key".getBytes(), "value".getBytes());
|
||||
// Test without column family
|
||||
StringBuffer retValue = new StringBuffer();
|
||||
boolean exists = db.keyMayExist("key".getBytes(), retValue);
|
||||
assertThat(exists).isTrue();
|
||||
assertThat(retValue.toString()).
|
||||
isEqualTo("value");
|
||||
|
||||
db.put("key".getBytes(), "value".getBytes());
|
||||
// Test without column family
|
||||
StringBuffer retValue = new StringBuffer();
|
||||
if (db.keyMayExist("key".getBytes(), retValue)) {
|
||||
assert(retValue.toString().equals("value"));
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
// Test without column family but with readOptions
|
||||
retValue = new StringBuffer();
|
||||
if (db.keyMayExist(new ReadOptions(), "key".getBytes(),
|
||||
retValue)) {
|
||||
assert(retValue.toString().equals("value"));
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
// Test with column family
|
||||
retValue = new StringBuffer();
|
||||
if (db.keyMayExist(columnFamilyHandleList.get(0), "key".getBytes(),
|
||||
retValue)) {
|
||||
assert(retValue.toString().equals("value"));
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
// Test with column family and readOptions
|
||||
retValue = new StringBuffer();
|
||||
if (db.keyMayExist(new ReadOptions(),
|
||||
columnFamilyHandleList.get(0), "key".getBytes(),
|
||||
retValue)) {
|
||||
assert(retValue.toString().equals("value"));
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
// KeyMayExist in CF1 must return false
|
||||
assert(db.keyMayExist(columnFamilyHandleList.get(1), "key".getBytes(),
|
||||
retValue) == false);
|
||||
System.out.println("Passed KeyMayExistTest");
|
||||
}catch (RocksDBException e){
|
||||
e.printStackTrace();
|
||||
assert(false);
|
||||
}
|
||||
// Test without column family but with readOptions
|
||||
retValue = new StringBuffer();
|
||||
exists = db.keyMayExist(new ReadOptions(), "key".getBytes(),
|
||||
retValue);
|
||||
assertThat(exists).isTrue();
|
||||
assertThat(retValue.toString()).
|
||||
isEqualTo("value");
|
||||
|
||||
// Test with column family
|
||||
retValue = new StringBuffer();
|
||||
exists = db.keyMayExist(columnFamilyHandleList.get(0), "key".getBytes(),
|
||||
retValue);
|
||||
assertThat(exists).isTrue();
|
||||
assertThat(retValue.toString()).
|
||||
isEqualTo("value");
|
||||
|
||||
// Test with column family and readOptions
|
||||
retValue = new StringBuffer();
|
||||
exists = db.keyMayExist(new ReadOptions(),
|
||||
columnFamilyHandleList.get(0), "key".getBytes(),
|
||||
retValue);
|
||||
assertThat(exists).isTrue();
|
||||
assertThat(retValue.toString()).
|
||||
isEqualTo("value");
|
||||
|
||||
// KeyMayExist in CF1 must return false
|
||||
assertThat(db.keyMayExist(columnFamilyHandleList.get(1),
|
||||
"key".getBytes(), retValue)).isFalse();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import org.junit.ClassRule;
|
|||
import org.junit.Test;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MemTableTest {
|
||||
|
||||
@ClassRule
|
||||
|
@ -16,22 +18,27 @@ public class MemTableTest {
|
|||
new RocksMemoryResource();
|
||||
|
||||
@Test
|
||||
public void shouldTestMemTable() throws RocksDBException {
|
||||
public void memTable() throws RocksDBException {
|
||||
Options options = new Options();
|
||||
// Test HashSkipListMemTableConfig
|
||||
HashSkipListMemTableConfig memTableConfig =
|
||||
new HashSkipListMemTableConfig();
|
||||
assert(memTableConfig.bucketCount() == 1000000);
|
||||
assertThat(memTableConfig.bucketCount()).
|
||||
isEqualTo(1000000);
|
||||
memTableConfig.setBucketCount(2000000);
|
||||
assert(memTableConfig.bucketCount() == 2000000);
|
||||
assert(memTableConfig.height() == 4);
|
||||
assertThat(memTableConfig.bucketCount()).
|
||||
isEqualTo(2000000);
|
||||
assertThat(memTableConfig.height()).
|
||||
isEqualTo(4);
|
||||
memTableConfig.setHeight(5);
|
||||
assert(memTableConfig.height() == 5);
|
||||
assert(memTableConfig.branchingFactor() == 4);
|
||||
assertThat(memTableConfig.height()).
|
||||
isEqualTo(5);
|
||||
assertThat(memTableConfig.branchingFactor()).
|
||||
isEqualTo(4);
|
||||
memTableConfig.setBranchingFactor(6);
|
||||
assert(memTableConfig.branchingFactor() == 6);
|
||||
assertThat(memTableConfig.branchingFactor()).
|
||||
isEqualTo(6);
|
||||
options.setMemTableConfig(memTableConfig);
|
||||
memTableConfig = null;
|
||||
options.dispose();
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
|
@ -39,11 +46,12 @@ public class MemTableTest {
|
|||
options = new Options();
|
||||
SkipListMemTableConfig skipMemTableConfig =
|
||||
new SkipListMemTableConfig();
|
||||
assert(skipMemTableConfig.lookahead() == 0);
|
||||
assertThat(skipMemTableConfig.lookahead()).
|
||||
isEqualTo(0);
|
||||
skipMemTableConfig.setLookahead(20);
|
||||
assert(skipMemTableConfig.lookahead() == 20);
|
||||
assertThat(skipMemTableConfig.lookahead()).
|
||||
isEqualTo(20);
|
||||
options.setMemTableConfig(skipMemTableConfig);
|
||||
skipMemTableConfig = null;
|
||||
options.dispose();
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
|
@ -51,31 +59,38 @@ public class MemTableTest {
|
|||
options = new Options();
|
||||
HashLinkedListMemTableConfig hashLinkedListMemTableConfig =
|
||||
new HashLinkedListMemTableConfig();
|
||||
assert(hashLinkedListMemTableConfig.bucketCount() == 50000);
|
||||
assertThat(hashLinkedListMemTableConfig.bucketCount()).
|
||||
isEqualTo(50000);
|
||||
hashLinkedListMemTableConfig.setBucketCount(100000);
|
||||
assert(hashLinkedListMemTableConfig.bucketCount() == 100000);
|
||||
assert(hashLinkedListMemTableConfig.hugePageTlbSize() == 0);
|
||||
assertThat(hashLinkedListMemTableConfig.bucketCount()).
|
||||
isEqualTo(100000);
|
||||
assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
|
||||
isEqualTo(0);
|
||||
hashLinkedListMemTableConfig.setHugePageTlbSize(1);
|
||||
assert(hashLinkedListMemTableConfig.hugePageTlbSize() == 1);
|
||||
assert(hashLinkedListMemTableConfig.
|
||||
bucketEntriesLoggingThreshold() == 4096);
|
||||
assertThat(hashLinkedListMemTableConfig.hugePageTlbSize()).
|
||||
isEqualTo(1);
|
||||
assertThat(hashLinkedListMemTableConfig.
|
||||
bucketEntriesLoggingThreshold()).
|
||||
isEqualTo(4096);
|
||||
hashLinkedListMemTableConfig.
|
||||
setBucketEntriesLoggingThreshold(200);
|
||||
assert(hashLinkedListMemTableConfig.
|
||||
bucketEntriesLoggingThreshold() == 200);
|
||||
assert(hashLinkedListMemTableConfig.
|
||||
ifLogBucketDistWhenFlush());
|
||||
assertThat(hashLinkedListMemTableConfig.
|
||||
bucketEntriesLoggingThreshold()).
|
||||
isEqualTo(200);
|
||||
assertThat(hashLinkedListMemTableConfig.
|
||||
ifLogBucketDistWhenFlush()).isTrue();
|
||||
hashLinkedListMemTableConfig.
|
||||
setIfLogBucketDistWhenFlush(false);
|
||||
assert(!hashLinkedListMemTableConfig.
|
||||
ifLogBucketDistWhenFlush());
|
||||
assert(hashLinkedListMemTableConfig.
|
||||
thresholdUseSkiplist() == 256);
|
||||
assertThat(hashLinkedListMemTableConfig.
|
||||
ifLogBucketDistWhenFlush()).isFalse();
|
||||
assertThat(hashLinkedListMemTableConfig.
|
||||
thresholdUseSkiplist()).
|
||||
isEqualTo(256);
|
||||
hashLinkedListMemTableConfig.setThresholdUseSkiplist(29);
|
||||
assert(hashLinkedListMemTableConfig.
|
||||
thresholdUseSkiplist() == 29);
|
||||
assertThat(hashLinkedListMemTableConfig.
|
||||
thresholdUseSkiplist()).
|
||||
isEqualTo(29);
|
||||
options.setMemTableConfig(hashLinkedListMemTableConfig);
|
||||
hashLinkedListMemTableConfig = null;
|
||||
options.dispose();
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
|
@ -83,14 +98,14 @@ public class MemTableTest {
|
|||
options = new Options();
|
||||
VectorMemTableConfig vectorMemTableConfig =
|
||||
new VectorMemTableConfig();
|
||||
assert(vectorMemTableConfig.reservedSize() == 0);
|
||||
assertThat(vectorMemTableConfig.reservedSize()).
|
||||
isEqualTo(0);
|
||||
vectorMemTableConfig.setReservedSize(123);
|
||||
assert(vectorMemTableConfig.reservedSize() == 123);
|
||||
assertThat(vectorMemTableConfig.reservedSize()).
|
||||
isEqualTo(123);
|
||||
options.setMemTableConfig(vectorMemTableConfig);
|
||||
vectorMemTableConfig = null;
|
||||
options.dispose();
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
System.out.println("Passed MemTableTest.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,14 @@ package org.rocksdb.test;
|
|||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MergeTest {
|
||||
|
||||
@ClassRule
|
||||
|
@ -24,13 +25,8 @@ public class MergeTest {
|
|||
@Rule
|
||||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@AfterClass
|
||||
public static void printMergePass(){
|
||||
System.out.println("Passed MergeTest.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestStringOption()
|
||||
public void stringOption()
|
||||
throws InterruptedException, RocksDBException {
|
||||
String db_path_string =
|
||||
dbFolder.getRoot().getAbsolutePath();
|
||||
|
@ -49,11 +45,11 @@ public class MergeTest {
|
|||
|
||||
db.close();
|
||||
opt.dispose();
|
||||
assert(strValue.equals("aa,bb"));
|
||||
assertThat(strValue).isEqualTo("aa,bb");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestCFStringOption()
|
||||
public void cFStringOption()
|
||||
throws InterruptedException, RocksDBException {
|
||||
DBOptions opt = new DBOptions();
|
||||
String db_path_string =
|
||||
|
@ -89,11 +85,11 @@ public class MergeTest {
|
|||
}
|
||||
db.close();
|
||||
opt.dispose();
|
||||
assert(strValue.equals("aa,bb"));
|
||||
assertThat(strValue).isEqualTo("aa,bb");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestOperatorOption()
|
||||
public void operatorOption()
|
||||
throws InterruptedException, RocksDBException {
|
||||
String db_path_string =
|
||||
dbFolder.getRoot().getAbsolutePath();
|
||||
|
@ -115,11 +111,11 @@ public class MergeTest {
|
|||
|
||||
db.close();
|
||||
opt.dispose();
|
||||
assert(strValue.equals("aa,bb"));
|
||||
assertThat(strValue).isEqualTo("aa,bb");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestCFOperatorOption()
|
||||
public void cFOperatorOption()
|
||||
throws InterruptedException, RocksDBException {
|
||||
DBOptions opt = new DBOptions();
|
||||
String db_path_string =
|
||||
|
@ -165,12 +161,12 @@ public class MergeTest {
|
|||
columnFamilyHandle.dispose();
|
||||
db.close();
|
||||
opt.dispose();
|
||||
assert(strValue.equals("aa,bb"));
|
||||
assert(strValueTmpCf.equals("xx,yy"));
|
||||
assertThat(strValue).isEqualTo("aa,bb");
|
||||
assertThat(strValueTmpCf).isEqualTo("xx,yy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestOperatorGcBehaviour()
|
||||
public void operatorGcBehaviour()
|
||||
throws RocksDBException {
|
||||
String db_path_string =
|
||||
dbFolder.getRoot().getAbsolutePath();
|
||||
|
@ -207,9 +203,5 @@ public class MergeTest {
|
|||
db = RocksDB.open(opt, db_path_string);
|
||||
db.close();
|
||||
opt.dispose();
|
||||
stringAppendOperator = null;
|
||||
newStringAppendOperator = null;
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,23 +6,296 @@
|
|||
package org.rocksdb.test;
|
||||
|
||||
import java.util.Random;
|
||||
import org.rocksdb.RocksDB;
|
||||
import org.rocksdb.Options;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class OptionsTest {
|
||||
|
||||
static {
|
||||
RocksDB.loadLibrary();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@Test
|
||||
public void options() throws RocksDBException {
|
||||
Options opt = new Options();
|
||||
Random rand = PlatformRandomHelper.
|
||||
getPlatformSpecificRandomFactory();
|
||||
|
||||
DBOptionsTest.testDBOptions(opt);
|
||||
ColumnFamilyOptionsTest.testCFOptions(opt);
|
||||
|
||||
{ // WriteBufferSize test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setWriteBufferSize(longValue);
|
||||
assert(opt.writeBufferSize() == longValue);
|
||||
}
|
||||
|
||||
{ // MaxWriteBufferNumber test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMaxWriteBufferNumber(intValue);
|
||||
assert(opt.maxWriteBufferNumber() == intValue);
|
||||
}
|
||||
|
||||
{ // MinWriteBufferNumberToMerge test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMinWriteBufferNumberToMerge(intValue);
|
||||
assert(opt.minWriteBufferNumberToMerge() == intValue);
|
||||
}
|
||||
|
||||
{ // NumLevels test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setNumLevels(intValue);
|
||||
assert(opt.numLevels() == intValue);
|
||||
}
|
||||
|
||||
{ // LevelFileNumCompactionTrigger test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setLevelZeroFileNumCompactionTrigger(intValue);
|
||||
assert(opt.levelZeroFileNumCompactionTrigger() == intValue);
|
||||
}
|
||||
|
||||
{ // LevelSlowdownWritesTrigger test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setLevelZeroSlowdownWritesTrigger(intValue);
|
||||
assert(opt.levelZeroSlowdownWritesTrigger() == intValue);
|
||||
}
|
||||
|
||||
{ // LevelStopWritesTrigger test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setLevelZeroStopWritesTrigger(intValue);
|
||||
assert(opt.levelZeroStopWritesTrigger() == intValue);
|
||||
}
|
||||
|
||||
{ // MaxMemCompactionLevel test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMaxMemCompactionLevel(intValue);
|
||||
assert(opt.maxMemCompactionLevel() == intValue);
|
||||
}
|
||||
|
||||
{ // TargetFileSizeBase test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setTargetFileSizeBase(longValue);
|
||||
assert(opt.targetFileSizeBase() == longValue);
|
||||
}
|
||||
|
||||
{ // TargetFileSizeMultiplier test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setTargetFileSizeMultiplier(intValue);
|
||||
assert(opt.targetFileSizeMultiplier() == intValue);
|
||||
}
|
||||
|
||||
{ // MaxBytesForLevelBase test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setMaxBytesForLevelBase(longValue);
|
||||
assert(opt.maxBytesForLevelBase() == longValue);
|
||||
}
|
||||
|
||||
{ // MaxBytesForLevelMultiplier test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMaxBytesForLevelMultiplier(intValue);
|
||||
assert(opt.maxBytesForLevelMultiplier() == intValue);
|
||||
}
|
||||
|
||||
{ // ExpandedCompactionFactor test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setExpandedCompactionFactor(intValue);
|
||||
assert(opt.expandedCompactionFactor() == intValue);
|
||||
}
|
||||
|
||||
{ // SourceCompactionFactor test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setSourceCompactionFactor(intValue);
|
||||
assert(opt.sourceCompactionFactor() == intValue);
|
||||
}
|
||||
|
||||
{ // MaxGrandparentOverlapFactor test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMaxGrandparentOverlapFactor(intValue);
|
||||
assert(opt.maxGrandparentOverlapFactor() == intValue);
|
||||
}
|
||||
|
||||
{ // SoftRateLimit test
|
||||
double doubleValue = rand.nextDouble();
|
||||
opt.setSoftRateLimit(doubleValue);
|
||||
assert(opt.softRateLimit() == doubleValue);
|
||||
}
|
||||
|
||||
{ // HardRateLimit test
|
||||
double doubleValue = rand.nextDouble();
|
||||
opt.setHardRateLimit(doubleValue);
|
||||
assert(opt.hardRateLimit() == doubleValue);
|
||||
}
|
||||
|
||||
{ // RateLimitDelayMaxMilliseconds test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setRateLimitDelayMaxMilliseconds(intValue);
|
||||
assert(opt.rateLimitDelayMaxMilliseconds() == intValue);
|
||||
}
|
||||
|
||||
{ // ArenaBlockSize test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setArenaBlockSize(longValue);
|
||||
assert(opt.arenaBlockSize() == longValue);
|
||||
}
|
||||
|
||||
{ // DisableAutoCompactions test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setDisableAutoCompactions(boolValue);
|
||||
assert(opt.disableAutoCompactions() == boolValue);
|
||||
}
|
||||
|
||||
{ // PurgeRedundantKvsWhileFlush test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setPurgeRedundantKvsWhileFlush(boolValue);
|
||||
assert(opt.purgeRedundantKvsWhileFlush() == boolValue);
|
||||
}
|
||||
|
||||
{ // VerifyChecksumsInCompaction test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setVerifyChecksumsInCompaction(boolValue);
|
||||
assert(opt.verifyChecksumsInCompaction() == boolValue);
|
||||
}
|
||||
|
||||
{ // FilterDeletes test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setFilterDeletes(boolValue);
|
||||
assert(opt.filterDeletes() == boolValue);
|
||||
}
|
||||
|
||||
{ // MaxSequentialSkipInIterations test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setMaxSequentialSkipInIterations(longValue);
|
||||
assert(opt.maxSequentialSkipInIterations() == longValue);
|
||||
}
|
||||
|
||||
{ // InplaceUpdateSupport test
|
||||
boolean boolValue = rand.nextBoolean();
|
||||
opt.setInplaceUpdateSupport(boolValue);
|
||||
assert(opt.inplaceUpdateSupport() == boolValue);
|
||||
}
|
||||
|
||||
{ // InplaceUpdateNumLocks test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setInplaceUpdateNumLocks(longValue);
|
||||
assert(opt.inplaceUpdateNumLocks() == longValue);
|
||||
}
|
||||
|
||||
{ // MemtablePrefixBloomBits test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMemtablePrefixBloomBits(intValue);
|
||||
assert(opt.memtablePrefixBloomBits() == intValue);
|
||||
}
|
||||
|
||||
{ // MemtablePrefixBloomProbes test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMemtablePrefixBloomProbes(intValue);
|
||||
assert(opt.memtablePrefixBloomProbes() == intValue);
|
||||
}
|
||||
|
||||
{ // BloomLocality test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setBloomLocality(intValue);
|
||||
assert(opt.bloomLocality() == intValue);
|
||||
}
|
||||
|
||||
{ // MaxSuccessiveMerges test
|
||||
long longValue = rand.nextLong();
|
||||
opt.setMaxSuccessiveMerges(longValue);
|
||||
assert(opt.maxSuccessiveMerges() == longValue);
|
||||
}
|
||||
|
||||
{ // MinPartialMergeOperands test
|
||||
int intValue = rand.nextInt();
|
||||
opt.setMinPartialMergeOperands(intValue);
|
||||
assert(opt.minPartialMergeOperands() == intValue);
|
||||
}
|
||||
|
||||
opt.dispose();
|
||||
System.out.println("Passed OptionsTest");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linkageOfPrepMethods() {
|
||||
Options options = new Options();
|
||||
options.optimizeUniversalStyleCompaction();
|
||||
options.optimizeUniversalStyleCompaction(4000);
|
||||
options.optimizeLevelStyleCompaction();
|
||||
options.optimizeLevelStyleCompaction(3000);
|
||||
options.optimizeForPointLookup(10);
|
||||
options.prepareForBulkLoad();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compressionTypes() {
|
||||
Options options = new Options();
|
||||
for(CompressionType compressionType :
|
||||
CompressionType.values()) {
|
||||
options.setCompressionType(compressionType);
|
||||
assertThat(options.compressionType()).
|
||||
isEqualTo(compressionType);
|
||||
}
|
||||
options.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compactionStyles() {
|
||||
Options options = new Options();
|
||||
for (CompactionStyle compactionStyle :
|
||||
CompactionStyle.values()) {
|
||||
options.setCompactionStyle(compactionStyle);
|
||||
assertThat(options.compactionStyle()).
|
||||
isEqualTo(compactionStyle);
|
||||
}
|
||||
options.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rateLimiterConfig() {
|
||||
Options options = new Options();
|
||||
RateLimiterConfig rateLimiterConfig =
|
||||
new GenericRateLimiterConfig(1000, 0, 1);
|
||||
options.setRateLimiterConfig(rateLimiterConfig);
|
||||
options.dispose();
|
||||
// Test with parameter initialization
|
||||
Options anotherOptions = new Options();
|
||||
anotherOptions.setRateLimiterConfig(
|
||||
new GenericRateLimiterConfig(1000));
|
||||
anotherOptions.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetTestPrefixExtractor() {
|
||||
Options options = new Options();
|
||||
options.useFixedLengthPrefixExtractor(100);
|
||||
options.useFixedLengthPrefixExtractor(10);
|
||||
options.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestMemTableFactoryName()
|
||||
throws RocksDBException {
|
||||
Options options = new Options();
|
||||
options.setMemTableConfig(new VectorMemTableConfig());
|
||||
assertThat(options.memTableFactoryName()).
|
||||
isEqualTo("VectorRepFactory");
|
||||
options.setMemTableConfig(
|
||||
new HashLinkedListMemTableConfig());
|
||||
assertThat(options.memTableFactoryName()).
|
||||
isEqualTo("HashLinkedListRepFactory");
|
||||
options.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statistics() {
|
||||
Options options = new Options();
|
||||
Statistics statistics = options.createStatistics().
|
||||
statisticsPtr();
|
||||
assertThat(statistics).isNotNull();
|
||||
|
||||
Options anotherOptions = new Options();
|
||||
statistics = anotherOptions.statisticsPtr();
|
||||
assertThat(statistics).isNotNull();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,42 +5,44 @@
|
|||
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.EncodingType;
|
||||
import org.rocksdb.PlainTableConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class PlainTableConfigTest {
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@AfterClass
|
||||
public static void printMessage(){
|
||||
System.out.println("Passed PlainTableConfigTest.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestPlainTableConfig() {
|
||||
public void plainTableConfig() {
|
||||
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||
plainTableConfig.setKeySize(5);
|
||||
assert(plainTableConfig.keySize() == 5);
|
||||
assertThat(plainTableConfig.keySize()).
|
||||
isEqualTo(5);
|
||||
plainTableConfig.setBloomBitsPerKey(11);
|
||||
assert(plainTableConfig.bloomBitsPerKey() == 11);
|
||||
assertThat(plainTableConfig.bloomBitsPerKey()).
|
||||
isEqualTo(11);
|
||||
plainTableConfig.setHashTableRatio(0.95);
|
||||
assert(plainTableConfig.hashTableRatio() == 0.95);
|
||||
assertThat(plainTableConfig.hashTableRatio()).
|
||||
isEqualTo(0.95);
|
||||
plainTableConfig.setIndexSparseness(18);
|
||||
assert(plainTableConfig.indexSparseness() == 18);
|
||||
assertThat(plainTableConfig.indexSparseness()).
|
||||
isEqualTo(18);
|
||||
plainTableConfig.setHugePageTlbSize(1);
|
||||
assert(plainTableConfig.hugePageTlbSize() == 1);
|
||||
assertThat(plainTableConfig.hugePageTlbSize()).
|
||||
isEqualTo(1);
|
||||
plainTableConfig.setEncodingType(EncodingType.kPrefix);
|
||||
assert(plainTableConfig.encodingType().equals(
|
||||
EncodingType.kPrefix));
|
||||
assertThat(plainTableConfig.encodingType()).isEqualTo(
|
||||
EncodingType.kPrefix);
|
||||
plainTableConfig.setFullScanMode(true);
|
||||
assert(plainTableConfig.fullScanMode());
|
||||
assertThat(plainTableConfig.fullScanMode()).isTrue();
|
||||
plainTableConfig.setStoreIndexInFile(true);
|
||||
assert(plainTableConfig.storeIndexInFile());
|
||||
assertThat(plainTableConfig.storeIndexInFile()).
|
||||
isTrue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import org.rocksdb.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ReadOnlyTest {
|
||||
|
||||
@ClassRule
|
||||
|
@ -23,119 +25,204 @@ public class ReadOnlyTest {
|
|||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void shouldTestReadOnlyOpen() {
|
||||
RocksDB db = null, db2 = null, db3 = null;
|
||||
public void readOnlyOpen() throws RocksDBException {
|
||||
RocksDB db, db2, db3;
|
||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||
new ArrayList<>();
|
||||
List<ColumnFamilyHandle> db2ColumnFamilyHandleList =
|
||||
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList =
|
||||
new ArrayList<>();
|
||||
List<ColumnFamilyHandle> db3ColumnFamilyHandleList =
|
||||
List<ColumnFamilyHandle> readOnlyColumnFamilyHandleList2 =
|
||||
new ArrayList<>();
|
||||
|
||||
Options options = new Options();
|
||||
options.setCreateIfMissing(true);
|
||||
|
||||
db = RocksDB.open(options,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
db.put("key".getBytes(), "value".getBytes());
|
||||
db2 = RocksDB.openReadOnly(
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
assertThat("value").
|
||||
isEqualTo(new String(db2.get("key".getBytes())));
|
||||
db.close();
|
||||
db2.close();
|
||||
|
||||
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
|
||||
cfDescriptors.add(
|
||||
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
|
||||
new ColumnFamilyOptions()));
|
||||
|
||||
db = RocksDB.open(
|
||||
dbFolder.getRoot().getAbsolutePath(), cfDescriptors, columnFamilyHandleList);
|
||||
columnFamilyHandleList.add(db.createColumnFamily(
|
||||
new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
|
||||
columnFamilyHandleList.add(db.createColumnFamily(
|
||||
new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions())));
|
||||
db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
|
||||
"value2".getBytes());
|
||||
|
||||
db2 = RocksDB.openReadOnly(
|
||||
dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
|
||||
readOnlyColumnFamilyHandleList);
|
||||
assertThat(db2.get("key2".getBytes())).isNull();
|
||||
assertThat(db2.get(readOnlyColumnFamilyHandleList.get(0), "key2".getBytes())).
|
||||
isNull();
|
||||
|
||||
cfDescriptors.clear();
|
||||
cfDescriptors.add(
|
||||
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
|
||||
new ColumnFamilyOptions()));
|
||||
cfDescriptors.add(
|
||||
new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions()));
|
||||
db3 = RocksDB.openReadOnly(
|
||||
dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
|
||||
readOnlyColumnFamilyHandleList2);
|
||||
assertThat(new String(db3.get(readOnlyColumnFamilyHandleList2.get(1),
|
||||
"key2".getBytes()))).isEqualTo("value2");
|
||||
db.close();
|
||||
db2.close();
|
||||
db3.close();
|
||||
options.dispose();
|
||||
}
|
||||
|
||||
@Test(expected = RocksDBException.class)
|
||||
public void failToWriteInReadOnly() throws RocksDBException {
|
||||
List<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);
|
||||
try {
|
||||
db = RocksDB.open(options,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
db.put("key".getBytes(), "value".getBytes());
|
||||
db2 = RocksDB.openReadOnly(
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
assert("value".equals(new String(db2.get("key".getBytes()))));
|
||||
db.close();
|
||||
db2.close();
|
||||
|
||||
|
||||
List<ColumnFamilyDescriptor> cfNames =
|
||||
new ArrayList<ColumnFamilyDescriptor>();
|
||||
cfNames.add(new ColumnFamilyDescriptor("default"));
|
||||
|
||||
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath(), cfNames, columnFamilyHandleList);
|
||||
columnFamilyHandleList.add(db.createColumnFamily(
|
||||
new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
|
||||
columnFamilyHandleList.add(db.createColumnFamily(
|
||||
new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions())));
|
||||
db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
|
||||
"value2".getBytes());
|
||||
|
||||
db2 = RocksDB.openReadOnly(
|
||||
dbFolder.getRoot().getAbsolutePath(), cfNames, db2ColumnFamilyHandleList);
|
||||
assert(db2.get("key2".getBytes())==null);
|
||||
assert(db2.get(columnFamilyHandleList.get(0), "key2".getBytes())==null);
|
||||
|
||||
List<ColumnFamilyDescriptor> cfNewName =
|
||||
new ArrayList<>();
|
||||
cfNewName.add(new ColumnFamilyDescriptor("default"));
|
||||
cfNewName.add(new ColumnFamilyDescriptor("new_cf2"));
|
||||
db3 = RocksDB.openReadOnly(dbFolder.getRoot().getAbsolutePath(), cfNewName, db3ColumnFamilyHandleList);
|
||||
assert(new String(db3.get(db3ColumnFamilyHandleList.get(1),
|
||||
"key2".getBytes())).equals("value2"));
|
||||
}catch (RocksDBException e){
|
||||
e.printStackTrace();
|
||||
assert(false);
|
||||
}
|
||||
RocksDB db = RocksDB.open(options,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
db.close();
|
||||
RocksDB rDb = RocksDB.openReadOnly(
|
||||
dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
|
||||
readOnlyColumnFamilyHandleList);
|
||||
// test that put fails in readonly mode
|
||||
try {
|
||||
db2.put("key".getBytes(), "value".getBytes());
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(true);
|
||||
}
|
||||
try {
|
||||
db3.put(db3ColumnFamilyHandleList.get(1),
|
||||
"key".getBytes(), "value".getBytes());
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(true);
|
||||
}
|
||||
// test that remove fails in readonly mode
|
||||
try {
|
||||
db2.remove("key".getBytes());
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(true);
|
||||
}
|
||||
try {
|
||||
db3.remove(db3ColumnFamilyHandleList.get(1),
|
||||
"key".getBytes());
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(true);
|
||||
}
|
||||
// test that write fails in readonly mode
|
||||
rDb.put("key".getBytes(), "value".getBytes());
|
||||
}
|
||||
|
||||
@Test(expected = RocksDBException.class)
|
||||
public void failToCFWriteInReadOnly() throws RocksDBException {
|
||||
List<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());
|
||||
}
|
||||
|
||||
@Test(expected = RocksDBException.class)
|
||||
public void failToRemoveInReadOnly() 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("key".getBytes());
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
@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();
|
||||
wb.put("key".getBytes(), "value".getBytes());
|
||||
try {
|
||||
db2.write(new WriteOptions(), wb);
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(true);
|
||||
}
|
||||
wb.dispose();
|
||||
wb = new WriteBatch();
|
||||
wb.put(db3ColumnFamilyHandleList.get(1),
|
||||
"key".getBytes(), "value".getBytes());
|
||||
try {
|
||||
db3.write(new WriteOptions(), wb);
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(true);
|
||||
}
|
||||
wb.dispose();
|
||||
// cleanup c++ pointers
|
||||
for (ColumnFamilyHandle columnFamilyHandle :
|
||||
columnFamilyHandleList) {
|
||||
columnFamilyHandle.dispose();
|
||||
}
|
||||
rDb.write(new WriteOptions(), wb);
|
||||
}
|
||||
|
||||
@Test(expected = RocksDBException.class)
|
||||
public void failToCFWriteBatchReadOnly() throws RocksDBException {
|
||||
List<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();
|
||||
for (ColumnFamilyHandle columnFamilyHandle :
|
||||
db2ColumnFamilyHandleList) {
|
||||
columnFamilyHandle.dispose();
|
||||
}
|
||||
db2.close();
|
||||
for (ColumnFamilyHandle columnFamilyHandle :
|
||||
db3ColumnFamilyHandleList) {
|
||||
columnFamilyHandle.dispose();
|
||||
}
|
||||
db3.close();
|
||||
System.out.println("Passed ReadOnlyTest.");
|
||||
|
||||
RocksDB rDb = RocksDB.openReadOnly(
|
||||
dbFolder.getRoot().getAbsolutePath(), cfDescriptors,
|
||||
readOnlyColumnFamilyHandleList);
|
||||
|
||||
WriteBatch wb = new WriteBatch();
|
||||
wb.put(readOnlyColumnFamilyHandleList.get(0),
|
||||
"key".getBytes(), "value".getBytes());
|
||||
rDb.write(new WriteOptions(), wb);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.rocksdb.test;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -25,13 +24,8 @@ public class ReadOptionsTest {
|
|||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@AfterClass
|
||||
public static void printMessage(){
|
||||
System.out.println("Passed ReadOptionsTest.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestReadOptions() {
|
||||
public void readOptions() {
|
||||
ReadOptions opt = new ReadOptions();
|
||||
Random rand = new Random();
|
||||
{ // VerifyChecksums test
|
||||
|
@ -60,49 +54,49 @@ public class ReadOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailVerifyChecksumUninitialized(){
|
||||
public void failVerifyChecksumUninitialized(){
|
||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||
exception);
|
||||
readOptions.setVerifyChecksums(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailSetFillCacheUninitialized(){
|
||||
public void failSetFillCacheUninitialized(){
|
||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||
exception);
|
||||
readOptions.setFillCache(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailFillCacheUninitialized(){
|
||||
public void failFillCacheUninitialized(){
|
||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||
exception);
|
||||
readOptions.fillCache();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailSetTailingUninitialized(){
|
||||
public void failSetTailingUninitialized(){
|
||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||
exception);
|
||||
readOptions.setTailing(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailTailingUninitialized(){
|
||||
public void failTailingUninitialized(){
|
||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||
exception);
|
||||
readOptions.tailing();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailSetSnapshotUninitialized(){
|
||||
public void failSetSnapshotUninitialized(){
|
||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||
exception);
|
||||
readOptions.setSnapshot(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailSnapshotUninitialized(){
|
||||
public void failSnapshotUninitialized(){
|
||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||
exception);
|
||||
readOptions.snapshot();
|
||||
|
|
|
@ -23,7 +23,7 @@ public class RocksIteratorTest {
|
|||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void shouldTestRocksIteratorGc()
|
||||
public void rocksIteratorGc()
|
||||
throws RocksDBException {
|
||||
RocksDB db;
|
||||
Options options = new Options();
|
||||
|
@ -44,6 +44,5 @@ public class RocksIteratorTest {
|
|||
iter3.dispose();
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
System.out.println("Passed RocksIteratorTest.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.Snapshot;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SnapshotTest {
|
||||
|
||||
@ClassRule
|
||||
|
@ -24,7 +26,7 @@ public class SnapshotTest {
|
|||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void shouldTestSnapshots() throws RocksDBException {
|
||||
public void snapshots() throws RocksDBException {
|
||||
RocksDB db;
|
||||
Options options = new Options();
|
||||
options.setCreateIfMissing(true);
|
||||
|
@ -37,43 +39,43 @@ public class SnapshotTest {
|
|||
// set snapshot in ReadOptions
|
||||
readOptions.setSnapshot(snapshot);
|
||||
// retrieve key value pair
|
||||
assert(new String(db.get("key".getBytes()))
|
||||
.equals("value"));
|
||||
assertThat(new String(db.get("key".getBytes()))).
|
||||
isEqualTo("value");
|
||||
// retrieve key value pair created before
|
||||
// the snapshot was made
|
||||
assert(new String(db.get(readOptions,
|
||||
"key".getBytes())).equals("value"));
|
||||
assertThat(new String(db.get(readOptions,
|
||||
"key".getBytes()))).isEqualTo("value");
|
||||
// add new key/value pair
|
||||
db.put("newkey".getBytes(), "newvalue".getBytes());
|
||||
// using no snapshot the latest db entries
|
||||
// will be taken into account
|
||||
assert(new String(db.get("newkey".getBytes()))
|
||||
.equals("newvalue"));
|
||||
assertThat(new String(db.get("newkey".getBytes()))).
|
||||
isEqualTo("newvalue");
|
||||
// snapshopot was created before newkey
|
||||
assert(db.get(readOptions, "newkey".getBytes())
|
||||
== null);
|
||||
assertThat(db.get(readOptions, "newkey".getBytes())).
|
||||
isNull();
|
||||
// Retrieve snapshot from read options
|
||||
Snapshot sameSnapshot = readOptions.snapshot();
|
||||
readOptions.setSnapshot(sameSnapshot);
|
||||
// results must be the same with new Snapshot
|
||||
// instance using the same native pointer
|
||||
assert(new String(db.get(readOptions,
|
||||
"key".getBytes())).equals("value"));
|
||||
assertThat(new String(db.get(readOptions,
|
||||
"key".getBytes()))).isEqualTo("value");
|
||||
// update key value pair to newvalue
|
||||
db.put("key".getBytes(), "newvalue".getBytes());
|
||||
// read with previously created snapshot will
|
||||
// read previous version of key value pair
|
||||
assert(new String(db.get(readOptions,
|
||||
"key".getBytes())).equals("value"));
|
||||
assertThat(new String(db.get(readOptions,
|
||||
"key".getBytes()))).isEqualTo("value");
|
||||
// read for newkey using the snapshot must be
|
||||
// null
|
||||
assert(db.get(readOptions, "newkey".getBytes())
|
||||
== null);
|
||||
assertThat(db.get(readOptions, "newkey".getBytes())).
|
||||
isNull();
|
||||
// setting null to snapshot in ReadOptions leads
|
||||
// to no Snapshot being used.
|
||||
readOptions.setSnapshot(null);
|
||||
assert(new String(db.get(readOptions,
|
||||
"newkey".getBytes())).equals("newvalue"));
|
||||
assertThat(new String(db.get(readOptions,
|
||||
"newkey".getBytes()))).isEqualTo("newvalue");
|
||||
// release Snapshot
|
||||
db.releaseSnapshot(snapshot);
|
||||
// Close database
|
||||
|
|
|
@ -25,7 +25,7 @@ public class StatisticsCollectorTest {
|
|||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void shouldTestStatisticsCollector()
|
||||
public void statisticsCollector()
|
||||
throws InterruptedException, RocksDBException {
|
||||
Options opt = new Options().createStatistics().setCreateIfMissing(true);
|
||||
Statistics stats = opt.statisticsPtr();
|
||||
|
@ -49,7 +49,5 @@ public class StatisticsCollectorTest {
|
|||
|
||||
db.close();
|
||||
opt.dispose();
|
||||
|
||||
System.out.println("Stats collector test passed.!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -36,19 +35,14 @@ public class WriteBatchTest {
|
|||
@Rule
|
||||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@AfterClass
|
||||
public static void printMergePass(){
|
||||
System.out.println("Passed WriteBatchTest.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestEmptyWriteBatch() {
|
||||
public void emptyWriteBatch() {
|
||||
WriteBatch batch = new WriteBatch();
|
||||
assertThat(batch.count()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestMultipleBatchOperations()
|
||||
public void multipleBatchOperations()
|
||||
throws UnsupportedEncodingException {
|
||||
WriteBatch batch = new WriteBatch();
|
||||
batch.put("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
|
||||
|
@ -66,7 +60,7 @@ public class WriteBatchTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestAppendOperation()
|
||||
public void testAppendOperation()
|
||||
throws UnsupportedEncodingException {
|
||||
WriteBatch b1 = new WriteBatch();
|
||||
WriteBatch b2 = new WriteBatch();
|
||||
|
@ -97,7 +91,7 @@ public class WriteBatchTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestBlobOperation()
|
||||
public void blobOperation()
|
||||
throws UnsupportedEncodingException {
|
||||
WriteBatch batch = new WriteBatch();
|
||||
batch.put("k1".getBytes("US-ASCII"), "v1".getBytes("US-ASCII"));
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.WriteOptions;
|
||||
|
@ -18,13 +17,8 @@ public class WriteOptionsTest {
|
|||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@AfterClass
|
||||
public static void printMessage(){
|
||||
System.out.println("Passed WriteOptionsTest.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestWriteOptions(){
|
||||
public void writeOptions(){
|
||||
WriteOptions writeOptions = new WriteOptions();
|
||||
writeOptions.setDisableWAL(true);
|
||||
assertThat(writeOptions.disableWAL()).isTrue();
|
||||
|
|
|
@ -159,6 +159,7 @@
|
|||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
Loading…
Reference in New Issue