[RocksJava] Rebased + integrated CF tests

main
fyrz 10 years ago
parent cd82beb0cb
commit e46450da6d
  1. 5
      java/Makefile
  2. 5
      java/org/rocksdb/test/AbstractComparatorTest.java
  3. 545
      java/org/rocksdb/test/ColumnFamilyOptionsTest.java
  4. 610
      java/org/rocksdb/test/ColumnFamilyTest.java
  5. 41
      java/org/rocksdb/test/FlushTest.java
  6. 2
      java/org/rocksdb/test/KeyMayExistTest.java
  7. 5
      java/org/rocksdb/test/MergeTest.java
  8. 23
      java/org/rocksdb/test/MixedOptionsTest.java
  9. 521
      java/org/rocksdb/test/OptionsTest.java
  10. 4
      java/org/rocksdb/test/WriteBatchHandlerTest.java

@ -47,8 +47,7 @@ ifeq ($(PLATFORM), OS_MACOSX)
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar
endif endif
JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\ JAVA_TESTS = org.rocksdb.test.BackupableDBTest\
org.rocksdb.test.BackupableDBTest\
org.rocksdb.test.BlockBasedTableConfigTest\ org.rocksdb.test.BlockBasedTableConfigTest\
org.rocksdb.test.ColumnFamilyOptionsTest\ org.rocksdb.test.ColumnFamilyOptionsTest\
org.rocksdb.test.ColumnFamilyTest\ org.rocksdb.test.ColumnFamilyTest\
@ -71,7 +70,7 @@ JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
org.rocksdb.test.RocksIteratorTest\ org.rocksdb.test.RocksIteratorTest\
org.rocksdb.test.SnapshotTest\ org.rocksdb.test.SnapshotTest\
org.rocksdb.test.StatisticsCollectorTest\ org.rocksdb.test.StatisticsCollectorTest\
org.rocksdb.test.WirteBatchHandlerTest\ org.rocksdb.test.WriteBatchHandlerTest\
org.rocksdb.test.WriteBatchTest\ org.rocksdb.test.WriteBatchTest\
org.rocksdb.test.WriteOptionsTest\ org.rocksdb.test.WriteOptionsTest\

@ -12,6 +12,7 @@ import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.Random; import java.util.Random;
import static org.assertj.core.api.Assertions.assertThat;
import static org.rocksdb.test.Types.byteToInt; import static org.rocksdb.test.Types.byteToInt;
import static org.rocksdb.test.Types.intToByte; import static org.rocksdb.test.Types.intToByte;
@ -75,13 +76,13 @@ public abstract class AbstractComparatorTest {
int count = 0; int count = 0;
for (it.seekToFirst(); it.isValid(); it.next()) { for (it.seekToFirst(); it.isValid(); it.next()) {
final int thisKey = byteToInt(it.key()); final int thisKey = byteToInt(it.key());
assert(thisKey > lastKey); assertThat(thisKey).isGreaterThan(lastKey);
lastKey = thisKey; lastKey = thisKey;
count++; count++;
} }
db.close(); db.close();
assert(count == ITERATIONS); assertThat(count).isEqualTo(ITERATIONS);
} catch (final RocksDBException e) { } catch (final RocksDBException e) {
System.err.format("[ERROR]: %s%n", e); System.err.format("[ERROR]: %s%n", e);

@ -5,225 +5,584 @@
package org.rocksdb.test; package org.rocksdb.test;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.*; import org.rocksdb.*;
import java.util.Random; import java.util.Random;
import static org.assertj.core.api.Assertions.assertThat;
public class ColumnFamilyOptionsTest { public class ColumnFamilyOptionsTest {
static {
RocksDB.loadLibrary();
}
public static void testCFOptions(ColumnFamilyOptionsInterface opt) { @ClassRule
Random rand = PlatformRandomHelper. public static final RocksMemoryResource rocksMemoryResource =
getPlatformSpecificRandomFactory(); new RocksMemoryResource();
{ // WriteBufferSize test
try { public static final Random rand = PlatformRandomHelper.
long longValue = rand.nextLong(); getPlatformSpecificRandomFactory();
opt.setWriteBufferSize(longValue);
assert(opt.writeBufferSize() == longValue); @Test
} catch (RocksDBException e) { public void writeBufferSize() throws RocksDBException {
assert(false); ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
long longValue = rand.nextLong();
opt.setWriteBufferSize(longValue);
assertThat(opt.writeBufferSize()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
} }
}
{ // MaxWriteBufferNumber test @Test
public void maxWriteBufferNumber() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMaxWriteBufferNumber(intValue); opt.setMaxWriteBufferNumber(intValue);
assert(opt.maxWriteBufferNumber() == intValue); assertThat(opt.maxWriteBufferNumber()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // MinWriteBufferNumberToMerge test @Test
public void minWriteBufferNumberToMerge() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMinWriteBufferNumberToMerge(intValue); opt.setMinWriteBufferNumberToMerge(intValue);
assert(opt.minWriteBufferNumberToMerge() == intValue); assertThat(opt.minWriteBufferNumberToMerge()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // NumLevels test @Test
public void numLevels() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setNumLevels(intValue); opt.setNumLevels(intValue);
assert(opt.numLevels() == intValue); assertThat(opt.numLevels()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // LevelFileNumCompactionTrigger test @Test
public void levelZeroFileNumCompactionTrigger() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setLevelZeroFileNumCompactionTrigger(intValue); opt.setLevelZeroFileNumCompactionTrigger(intValue);
assert(opt.levelZeroFileNumCompactionTrigger() == intValue); assertThat(opt.levelZeroFileNumCompactionTrigger()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // LevelSlowdownWritesTrigger test @Test
public void levelZeroSlowdownWritesTrigger() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setLevelZeroSlowdownWritesTrigger(intValue); opt.setLevelZeroSlowdownWritesTrigger(intValue);
assert(opt.levelZeroSlowdownWritesTrigger() == intValue); assertThat(opt.levelZeroSlowdownWritesTrigger()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // LevelStopWritesTrigger test @Test
public void levelZeroStopWritesTrigger() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setLevelZeroStopWritesTrigger(intValue); opt.setLevelZeroStopWritesTrigger(intValue);
assert(opt.levelZeroStopWritesTrigger() == intValue); assertThat(opt.levelZeroStopWritesTrigger()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // MaxMemCompactionLevel test @Test
public void maxMemCompactionLevel() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMaxMemCompactionLevel(intValue); opt.setMaxMemCompactionLevel(intValue);
assert(opt.maxMemCompactionLevel() == intValue); assertThat(opt.maxMemCompactionLevel()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // TargetFileSizeBase test @Test
public void targetFileSizeBase() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setTargetFileSizeBase(longValue); opt.setTargetFileSizeBase(longValue);
assert(opt.targetFileSizeBase() == longValue); assertThat(opt.targetFileSizeBase()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // TargetFileSizeMultiplier test @Test
public void targetFileSizeMultiplier() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setTargetFileSizeMultiplier(intValue); opt.setTargetFileSizeMultiplier(intValue);
assert(opt.targetFileSizeMultiplier() == intValue); assertThat(opt.targetFileSizeMultiplier()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // MaxBytesForLevelBase test @Test
public void maxBytesForLevelBase() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setMaxBytesForLevelBase(longValue); opt.setMaxBytesForLevelBase(longValue);
assert(opt.maxBytesForLevelBase() == longValue); assertThat(opt.maxBytesForLevelBase()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // MaxBytesForLevelMultiplier test @Test
public void maxBytesForLevelMultiplier() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMaxBytesForLevelMultiplier(intValue); opt.setMaxBytesForLevelMultiplier(intValue);
assert(opt.maxBytesForLevelMultiplier() == intValue); assertThat(opt.maxBytesForLevelMultiplier()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // ExpandedCompactionFactor test @Test
public void expandedCompactionFactor() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setExpandedCompactionFactor(intValue); opt.setExpandedCompactionFactor(intValue);
assert(opt.expandedCompactionFactor() == intValue); assertThat(opt.expandedCompactionFactor()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // SourceCompactionFactor test @Test
public void sourceCompactionFactor() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setSourceCompactionFactor(intValue); opt.setSourceCompactionFactor(intValue);
assert(opt.sourceCompactionFactor() == intValue); assertThat(opt.sourceCompactionFactor()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // MaxGrandparentOverlapFactor test @Test
public void maxGrandparentOverlapFactor() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMaxGrandparentOverlapFactor(intValue); opt.setMaxGrandparentOverlapFactor(intValue);
assert(opt.maxGrandparentOverlapFactor() == intValue); assertThat(opt.maxGrandparentOverlapFactor()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // SoftRateLimit test @Test
public void softRateLimit() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
double doubleValue = rand.nextDouble(); double doubleValue = rand.nextDouble();
opt.setSoftRateLimit(doubleValue); opt.setSoftRateLimit(doubleValue);
assert(opt.softRateLimit() == doubleValue); assertThat(opt.softRateLimit()).isEqualTo(doubleValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // HardRateLimit test @Test
public void hardRateLimit() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
double doubleValue = rand.nextDouble(); double doubleValue = rand.nextDouble();
opt.setHardRateLimit(doubleValue); opt.setHardRateLimit(doubleValue);
assert(opt.hardRateLimit() == doubleValue); assertThat(opt.hardRateLimit()).isEqualTo(doubleValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // RateLimitDelayMaxMilliseconds test @Test
public void rateLimitDelayMaxMilliseconds() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setRateLimitDelayMaxMilliseconds(intValue); opt.setRateLimitDelayMaxMilliseconds(intValue);
assert(opt.rateLimitDelayMaxMilliseconds() == intValue); assertThat(opt.rateLimitDelayMaxMilliseconds()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // ArenaBlockSize test @Test
try { public void arenaBlockSize() throws RocksDBException {
long longValue = rand.nextLong(); ColumnFamilyOptions opt = null;
opt.setArenaBlockSize(longValue); try {
assert(opt.arenaBlockSize() == longValue); opt = new ColumnFamilyOptions();
} catch (RocksDBException e) { long longValue = rand.nextLong();
assert(false); opt.setArenaBlockSize(longValue);
assertThat(opt.arenaBlockSize()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
} }
}
{ // DisableAutoCompactions test @Test
public void disableAutoCompactions() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setDisableAutoCompactions(boolValue); opt.setDisableAutoCompactions(boolValue);
assert(opt.disableAutoCompactions() == boolValue); assertThat(opt.disableAutoCompactions()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // PurgeRedundantKvsWhileFlush test @Test
public void purgeRedundantKvsWhileFlush() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setPurgeRedundantKvsWhileFlush(boolValue); opt.setPurgeRedundantKvsWhileFlush(boolValue);
assert(opt.purgeRedundantKvsWhileFlush() == boolValue); assertThat(opt.purgeRedundantKvsWhileFlush()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // VerifyChecksumsInCompaction test @Test
public void verifyChecksumsInCompaction() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setVerifyChecksumsInCompaction(boolValue); opt.setVerifyChecksumsInCompaction(boolValue);
assert(opt.verifyChecksumsInCompaction() == boolValue); assertThat(opt.verifyChecksumsInCompaction()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // FilterDeletes test @Test
public void filterDeletes() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setFilterDeletes(boolValue); opt.setFilterDeletes(boolValue);
assert(opt.filterDeletes() == boolValue); assertThat(opt.filterDeletes()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // MaxSequentialSkipInIterations test @Test
public void maxSequentialSkipInIterations() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setMaxSequentialSkipInIterations(longValue); opt.setMaxSequentialSkipInIterations(longValue);
assert(opt.maxSequentialSkipInIterations() == longValue); assertThat(opt.maxSequentialSkipInIterations()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // InplaceUpdateSupport test @Test
public void inplaceUpdateSupport() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean(); boolean boolValue = rand.nextBoolean();
opt.setInplaceUpdateSupport(boolValue); opt.setInplaceUpdateSupport(boolValue);
assert(opt.inplaceUpdateSupport() == boolValue); assertThat(opt.inplaceUpdateSupport()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // InplaceUpdateNumLocks test @Test
try { public void inplaceUpdateNumLocks() throws RocksDBException {
long longValue = rand.nextLong(); ColumnFamilyOptions opt = null;
opt.setInplaceUpdateNumLocks(longValue); try {
assert(opt.inplaceUpdateNumLocks() == longValue); opt = new ColumnFamilyOptions();
} catch (RocksDBException e) { long longValue = rand.nextLong();
assert(false); opt.setInplaceUpdateNumLocks(longValue);
assertThat(opt.inplaceUpdateNumLocks()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
} }
}
{ // MemtablePrefixBloomBits test @Test
public void memtablePrefixBloomBits() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt.setMemtablePrefixBloomBits(intValue); opt.setMemtablePrefixBloomBits(intValue);
assert(opt.memtablePrefixBloomBits() == intValue); assertThat(opt.memtablePrefixBloomBits()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // MemtablePrefixBloomProbes test @Test
public void memtablePrefixBloomProbes() {
ColumnFamilyOptions opt = null;
try {
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt = new ColumnFamilyOptions();
opt.setMemtablePrefixBloomProbes(intValue); opt.setMemtablePrefixBloomProbes(intValue);
assert(opt.memtablePrefixBloomProbes() == intValue); assertThat(opt.memtablePrefixBloomProbes()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // BloomLocality test @Test
public void bloomLocality() {
ColumnFamilyOptions opt = null;
try {
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt = new ColumnFamilyOptions();
opt.setBloomLocality(intValue); opt.setBloomLocality(intValue);
assert(opt.bloomLocality() == intValue); assertThat(opt.bloomLocality()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
} }
}
{ // MaxSuccessiveMerges test @Test
try { public void maxSuccessiveMerges() throws RocksDBException {
long longValue = rand.nextLong(); ColumnFamilyOptions opt = null;
opt.setMaxSuccessiveMerges(longValue); try {
assert(opt.maxSuccessiveMerges() == longValue); long longValue = rand.nextLong();
} catch (RocksDBException e){ opt = new ColumnFamilyOptions();
assert(false); opt.setMaxSuccessiveMerges(longValue);
assertThat(opt.maxSuccessiveMerges()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
} }
}
{ // MinPartialMergeOperands test @Test
public void minPartialMergeOperands() {
ColumnFamilyOptions opt = null;
try {
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt = new ColumnFamilyOptions();
opt.setMinPartialMergeOperands(intValue); opt.setMinPartialMergeOperands(intValue);
assert(opt.minPartialMergeOperands() == intValue); assertThat(opt.minPartialMergeOperands()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
}
}
@Test
public void memTable() throws RocksDBException {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
opt.setMemTableConfig(new HashLinkedListMemTableConfig());
assertThat(opt.memTableFactoryName()).
isEqualTo("HashLinkedListRepFactory");
} finally {
if (opt != null) {
opt.dispose();
}
}
}
@Test
public void comparator() throws RocksDBException {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
opt.setComparator(BuiltinComparator.BYTEWISE_COMPARATOR);
} finally {
if (opt != null) {
opt.dispose();
}
}
}
@Test
public void linkageOfPrepMethods() {
ColumnFamilyOptions options = null;
try {
options = new ColumnFamilyOptions();
options.optimizeUniversalStyleCompaction();
options.optimizeUniversalStyleCompaction(4000);
options.optimizeLevelStyleCompaction();
options.optimizeLevelStyleCompaction(3000);
options.optimizeForPointLookup(10);
} finally {
if (options != null) {
options.dispose();
}
}
}
@Test
public void shouldSetTestPrefixExtractor() {
ColumnFamilyOptions options = null;
try {
options = new ColumnFamilyOptions();
options.useFixedLengthPrefixExtractor(100);
options.useFixedLengthPrefixExtractor(10);
} finally {
if (options != null) {
options.dispose();
}
} }
} }
public static void main(String[] args) { @Test
ColumnFamilyOptions opt = new ColumnFamilyOptions(); public void compressionTypes() {
testCFOptions(opt); ColumnFamilyOptions ColumnFamilyOptions = null;
opt.dispose(); try {
System.out.println("Passed DBOptionsTest"); ColumnFamilyOptions = new ColumnFamilyOptions();
for (CompressionType compressionType :
CompressionType.values()) {
ColumnFamilyOptions.setCompressionType(compressionType);
assertThat(ColumnFamilyOptions.compressionType()).
isEqualTo(compressionType);
assertThat(CompressionType.valueOf("NO_COMPRESSION")).
isEqualTo(CompressionType.NO_COMPRESSION);
}
} finally {
if (ColumnFamilyOptions != null) {
ColumnFamilyOptions.dispose();
}
}
}
@Test
public void compactionStyles() {
ColumnFamilyOptions ColumnFamilyOptions = null;
try {
ColumnFamilyOptions = new ColumnFamilyOptions();
for (CompactionStyle compactionStyle :
CompactionStyle.values()) {
ColumnFamilyOptions.setCompactionStyle(compactionStyle);
assertThat(ColumnFamilyOptions.compactionStyle()).
isEqualTo(compactionStyle);
assertThat(CompactionStyle.valueOf("FIFO")).
isEqualTo(CompactionStyle.FIFO);
}
} finally {
if (ColumnFamilyOptions != null) {
ColumnFamilyOptions.dispose();
}
}
} }
} }

@ -16,6 +16,8 @@ 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 ColumnFamilyTest { public class ColumnFamilyTest {
@ClassRule @ClassRule
@ -26,71 +28,85 @@ public class ColumnFamilyTest {
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@Test @Test
public void columnFamilies() { public void listColumnFamilies() throws RocksDBException {
String db_path = dbFolder.getRoot().getAbsolutePath();
RocksDB db = null; RocksDB db = null;
Options options = new Options(); Options options = null;
options.setCreateIfMissing(true); try {
options = new Options();
options.setCreateIfMissing(true);
DBOptions dbOptions = new DBOptions(); DBOptions dbOptions = new DBOptions();
dbOptions.setCreateIfMissing(true); dbOptions.setCreateIfMissing(true);
try { db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
db = RocksDB.open(options, db_path); // Test listColumnFamilies
} catch (RocksDBException e) { List<byte[]> columnFamilyNames;
assert(false); columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath());
} assertThat(columnFamilyNames).isNotNull();
// Test listColumnFamilies assertThat(columnFamilyNames.size()).isGreaterThan(0);
List<byte[]> columnFamilyNames; assertThat(columnFamilyNames.size()).isEqualTo(1);
try { assertThat(new String(columnFamilyNames.get(0))).isEqualTo("default");
columnFamilyNames = RocksDB.listColumnFamilies(options, db_path); } finally {
if (columnFamilyNames != null && columnFamilyNames.size() > 0) { if (db != null) {
assert(columnFamilyNames.size() == 1); db.close();
assert(new String(columnFamilyNames.get(0)).equals("default")); }
} else { if (options != null) {
assert(false); options.dispose();
} }
} catch (RocksDBException e) {
assert(false);
} }
}
// Test createColumnFamily @Test
public void createColumnFamily() throws RocksDBException {
RocksDB db = null;
Options options = null;
try { try {
options = new Options();
options.setCreateIfMissing(true);
DBOptions dbOptions = new DBOptions();
dbOptions.setCreateIfMissing(true);
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
db.createColumnFamily(new ColumnFamilyDescriptor("new_cf", db.createColumnFamily(new ColumnFamilyDescriptor("new_cf",
new ColumnFamilyOptions())); new ColumnFamilyOptions()));
} catch (RocksDBException e) {
assert(false);
}
if (db != null) {
db.close(); db.close();
List<byte[]> columnFamilyNames;
columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath());
assertThat(columnFamilyNames).isNotNull();
assertThat(columnFamilyNames.size()).isGreaterThan(0);
assertThat(columnFamilyNames.size()).isEqualTo(2);
assertThat(new String(columnFamilyNames.get(0))).isEqualTo("default");
assertThat(new String(columnFamilyNames.get(1))).isEqualTo("new_cf");
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
} }
}
// Test listColumnFamilies after create "new_cf" @Test
public void openWithColumnFamilies() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try { try {
columnFamilyNames = RocksDB.listColumnFamilies(options, db_path); options = new DBOptions();
if (columnFamilyNames != null && columnFamilyNames.size() > 0) { options.setCreateIfMissing(true);
assert(columnFamilyNames.size() == 2); options.setCreateMissingColumnFamilies(true);
assert(new String(columnFamilyNames.get(0)).equals("default")); // Test open database with column family names
assert(new String(columnFamilyNames.get(1)).equals("new_cf")); List<ColumnFamilyDescriptor> cfNames =
} else { new ArrayList<>();
assert(false); List<ColumnFamilyHandle> columnFamilyHandleList =
} new ArrayList<>();
} catch (RocksDBException e) { cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
assert(false); cfNames.add(new ColumnFamilyDescriptor("new_cf"));
}
// Test open database with column family names
List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor("default"));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
try { db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
db = RocksDB.open(dbOptions, db_path, cfNames, columnFamilyHandleList); cfNames, columnFamilyHandleList);
assert(columnFamilyHandleList.size() == 2); assertThat(columnFamilyHandleList.size()).isEqualTo(2);
db.put("dfkey1".getBytes(), "dfvalue".getBytes()); db.put("dfkey1".getBytes(), "dfvalue".getBytes());
db.put(columnFamilyHandleList.get(0), "dfkey2".getBytes(), db.put(columnFamilyHandleList.get(0), "dfkey2".getBytes(),
"dfvalue".getBytes()); "dfvalue".getBytes());
@ -99,57 +115,118 @@ public class ColumnFamilyTest {
String retVal = new String(db.get(columnFamilyHandleList.get(1), String retVal = new String(db.get(columnFamilyHandleList.get(1),
"newcfkey1".getBytes())); "newcfkey1".getBytes()));
assert(retVal.equals("newcfvalue")); assertThat(retVal).isEqualTo("newcfvalue");
assert( (db.get(columnFamilyHandleList.get(1), assertThat((db.get(columnFamilyHandleList.get(1),
"dfkey1".getBytes())) == null); "dfkey1".getBytes()))).isNull();
db.remove(columnFamilyHandleList.get(1), "newcfkey1".getBytes()); db.remove(columnFamilyHandleList.get(1), "newcfkey1".getBytes());
assert( (db.get(columnFamilyHandleList.get(1), assertThat((db.get(columnFamilyHandleList.get(1),
"newcfkey1".getBytes())) == null); "newcfkey1".getBytes()))).isNull();
db.remove("dfkey2".getBytes()); db.remove(columnFamilyHandleList.get(0), new WriteOptions(),
assert( (db.get(columnFamilyHandleList.get(0), "dfkey2".getBytes());
"dfkey2".getBytes())) == null); assertThat(db.get(columnFamilyHandleList.get(0), new ReadOptions(),
} catch (RocksDBException e) { "dfkey2".getBytes())).isNull();
assert(false); } finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
}
}
@Test
public void getWithOutValueAndCf() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try {
options = new DBOptions();
options.setCreateIfMissing(true);
options.setCreateMissingColumnFamilies(true);
// Test open database with column family names
List<ColumnFamilyDescriptor> cfDescriptors =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfDescriptors, columnFamilyHandleList);
db.put(columnFamilyHandleList.get(0), new WriteOptions(), "key1".getBytes(), "value".getBytes());
db.put("key2".getBytes(), "12345678".getBytes());
byte[] outValue = new byte[5];
// not found value
int getResult = db.get("keyNotFound".getBytes(), outValue);
assertThat(getResult).isEqualTo(RocksDB.NOT_FOUND);
// found value which fits in outValue
getResult = db.get(columnFamilyHandleList.get(0), "key1".getBytes(), outValue);
assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
assertThat(outValue).isEqualTo("value".getBytes());
// found value which fits partially
getResult = db.get(columnFamilyHandleList.get(0), new ReadOptions(),
"key2".getBytes(), outValue);
assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
assertThat(outValue).isEqualTo("12345".getBytes());
} finally {
if (db != null) {
db.close();
}
} }
}
// Test create write to and drop ColumnFamily @Test
public void createWriteDropColumnFamily() throws RocksDBException {
RocksDB db = null;
DBOptions opt = null;
ColumnFamilyHandle tmpColumnFamilyHandle = null; ColumnFamilyHandle tmpColumnFamilyHandle = null;
try { try {
opt = new DBOptions();
opt.setCreateIfMissing(true);
opt.setCreateMissingColumnFamilies(true);
List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList);
tmpColumnFamilyHandle = db.createColumnFamily( tmpColumnFamilyHandle = db.createColumnFamily(
new ColumnFamilyDescriptor("tmpCF", new ColumnFamilyOptions())); new ColumnFamilyDescriptor("tmpCF", new ColumnFamilyOptions()));
db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes()); db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes());
db.dropColumnFamily(tmpColumnFamilyHandle); db.dropColumnFamily(tmpColumnFamilyHandle);
tmpColumnFamilyHandle.dispose(); tmpColumnFamilyHandle.dispose();
} catch (Exception e) { } finally {
assert(false); if (tmpColumnFamilyHandle != null) {
} tmpColumnFamilyHandle.dispose();
}
// Put to disposed column family tmpColumnFamilyHandle must fail if (db != null) {
try { db.close();
db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes()); }
assert(false); if (opt != null) {
} catch (RocksDBException e) { opt.dispose();
assert(true); }
} }
}
// Remove to disposed column family tmpColumnFamilyHandle must fail @Test
public void writeBatch() throws RocksDBException {
RocksDB db = null;
DBOptions opt = null;
try { try {
db.remove(tmpColumnFamilyHandle, "key".getBytes()); opt = new DBOptions();
assert(false); opt.setCreateIfMissing(true);
} catch (RocksDBException e) { opt.setCreateMissingColumnFamilies(true);
assert(true); List<ColumnFamilyDescriptor> cfNames =
} new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
// Get on a disposed column family tmpColumnFamilyHandle must fail db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
try { cfNames, columnFamilyHandleList);
db.get(tmpColumnFamilyHandle, "key".getBytes());
assert(false);
} catch (RocksDBException e) {
assert(true);
}
// Test WriteBatch
try {
WriteBatch writeBatch = new WriteBatch(); WriteBatch writeBatch = new WriteBatch();
WriteOptions writeOpt = new WriteOptions(); WriteOptions writeOpt = new WriteOptions();
writeBatch.put("key".getBytes(), "value".getBytes()); writeBatch.put("key".getBytes(), "value".getBytes());
@ -161,135 +238,324 @@ public class ColumnFamilyTest {
writeBatch.remove(columnFamilyHandleList.get(1), "xyz".getBytes()); writeBatch.remove(columnFamilyHandleList.get(1), "xyz".getBytes());
db.write(writeOpt, writeBatch); db.write(writeOpt, writeBatch);
writeBatch.dispose(); writeBatch.dispose();
assert(db.get(columnFamilyHandleList.get(1), assertThat(db.get(columnFamilyHandleList.get(1),
"xyz".getBytes()) == null); "xyz".getBytes()) == null);
assert(new String(db.get(columnFamilyHandleList.get(1), assertThat(new String(db.get(columnFamilyHandleList.get(1),
"newcfkey".getBytes())).equals("value")); "newcfkey".getBytes()))).isEqualTo("value");
assert(new String(db.get(columnFamilyHandleList.get(1), assertThat(new String(db.get(columnFamilyHandleList.get(1),
"newcfkey2".getBytes())).equals("value2")); "newcfkey2".getBytes()))).isEqualTo("value2");
assert(new String(db.get("key".getBytes())).equals("value")); assertThat(new String(db.get("key".getBytes()))).isEqualTo("value");
} catch (Exception e) { } finally {
e.printStackTrace(); if (db != null) {
assert(false); db.close();
}
if (opt != null) {
opt.dispose();
}
} }
}
// Test iterator on column family @Test
public void iteratorOnColumnFamily() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
RocksIterator rocksIterator = null;
try { try {
RocksIterator rocksIterator = db.newIterator( options = new DBOptions();
options.setCreateIfMissing(true);
options.setCreateMissingColumnFamilies(true);
List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList);
db.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(),
"value".getBytes());
db.put(columnFamilyHandleList.get(1), "newcfkey2".getBytes(),
"value2".getBytes());
rocksIterator = db.newIterator(
columnFamilyHandleList.get(1)); columnFamilyHandleList.get(1));
rocksIterator.seekToFirst(); rocksIterator.seekToFirst();
Map<String, String> refMap = new HashMap<String, String>(); Map<String, String> refMap = new HashMap<>();
refMap.put("newcfkey", "value"); refMap.put("newcfkey", "value");
refMap.put("newcfkey2", "value2"); refMap.put("newcfkey2", "value2");
int i = 0; int i = 0;
while(rocksIterator.isValid()) { while (rocksIterator.isValid()) {
i++; i++;
refMap.get(new String(rocksIterator.key())).equals( assertThat(refMap.get(new String(rocksIterator.key()))).
new String(rocksIterator.value())); isEqualTo(new String(rocksIterator.value()));
rocksIterator.next(); rocksIterator.next();
} }
assert(i == 2); assertThat(i).isEqualTo(2);
rocksIterator.dispose(); rocksIterator.dispose();
} catch(Exception e) { } finally {
assert(false); if (rocksIterator != null) {
rocksIterator.dispose();
}
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
} }
}
// Test property handling on column families @Test
public void multiGet() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try { try {
assert(db.getProperty("rocksdb.estimate-num-keys") != null); options = new DBOptions();
assert(db.getProperty("rocksdb.stats") != null); options.setCreateIfMissing(true);
assert(db.getProperty(columnFamilyHandleList.get(0), options.setCreateMissingColumnFamilies(true);
"rocksdb.sstables") != null); List<ColumnFamilyDescriptor> cfDescriptors =
assert(db.getProperty(columnFamilyHandleList.get(1), new ArrayList<>();
"rocksdb.estimate-num-keys") != null); List<ColumnFamilyHandle> columnFamilyHandleList =
assert(db.getProperty(columnFamilyHandleList.get(1), new ArrayList<>();
"rocksdb.stats") != null); cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
assert(db.getProperty(columnFamilyHandleList.get(1), cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
"rocksdb.sstables") != null);
} catch(Exception e) {
assert(false);
}
// MultiGet test db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
List<ColumnFamilyHandle> cfCustomList = new ArrayList<ColumnFamilyHandle>(); cfDescriptors, columnFamilyHandleList);
try { db.put(columnFamilyHandleList.get(0), "key".getBytes(), "value".getBytes());
List<byte[]> keys = new ArrayList<byte[]>(); db.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(), "value".getBytes());
List<byte[]> keys = new ArrayList<>();
keys.add("key".getBytes()); keys.add("key".getBytes());
keys.add("newcfkey".getBytes()); keys.add("newcfkey".getBytes());
Map<byte[], byte[]> retValues = db.multiGet(columnFamilyHandleList,keys); Map<byte[], byte[]> retValues = db.multiGet(columnFamilyHandleList, keys);
assert(retValues.size() == 2); assertThat(retValues.size()).isEqualTo(2);
assert(new String(retValues.get(keys.get(0))) assertThat(new String(retValues.get(keys.get(0))))
.equals("value")); .isEqualTo("value");
assert(new String(retValues.get(keys.get(1))) assertThat(new String(retValues.get(keys.get(1))))
.equals("value")); .isEqualTo("value");
retValues = db.multiGet(new ReadOptions(), columnFamilyHandleList, keys);
cfCustomList.add(columnFamilyHandleList.get(0)); assertThat(retValues.size()).isEqualTo(2);
cfCustomList.add(columnFamilyHandleList.get(0)); assertThat(new String(retValues.get(keys.get(0))))
retValues = db.multiGet(cfCustomList, keys); .isEqualTo("value");
assert(retValues.size() == 1); assertThat(new String(retValues.get(keys.get(1))))
assert(new String(retValues.get(keys.get(0))) .isEqualTo("value");
.equals("value")); } finally {
} catch (RocksDBException e) { if (db != null) {
assert(false); db.close();
}
if (options != null) {
options.dispose();
}
} }
}
// Test multiget without correct number of column @Test
// families public void properties() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try { try {
List<byte[]> keys = new ArrayList<byte[]>(); options = new DBOptions();
keys.add("key".getBytes()); options.setCreateIfMissing(true);
keys.add("newcfkey".getBytes()); options.setCreateMissingColumnFamilies(true);
cfCustomList.remove(1); List<ColumnFamilyDescriptor> cfNames =
db.multiGet(cfCustomList, keys); new ArrayList<>();
assert(false); List<ColumnFamilyHandle> columnFamilyHandleList =
} catch (RocksDBException e) { new ArrayList<>();
assert(false); cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
} catch (IllegalArgumentException e) { cfNames.add(new ColumnFamilyDescriptor("new_cf"));
assert(true);
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList);
assertThat(db.getProperty("rocksdb.estimate-num-keys")).
isNotNull();
assertThat(db.getProperty("rocksdb.stats")).isNotNull();
assertThat(db.getProperty(columnFamilyHandleList.get(0),
"rocksdb.sstables")).isNotNull();
assertThat(db.getProperty(columnFamilyHandleList.get(1),
"rocksdb.estimate-num-keys")).isNotNull();
assertThat(db.getProperty(columnFamilyHandleList.get(1),
"rocksdb.stats")).isNotNull();
assertThat(db.getProperty(columnFamilyHandleList.get(1),
"rocksdb.sstables")).isNotNull();
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
} }
}
@Test
public void iterators() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try { try {
// iterate over default key/value pairs options = new DBOptions();
options.setCreateIfMissing(true);
options.setCreateMissingColumnFamilies(true);
List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList);
List<RocksIterator> iterators = List<RocksIterator> iterators =
db.newIterators(columnFamilyHandleList); db.newIterators(columnFamilyHandleList);
assert(iterators.size() == 2); assertThat(iterators.size()).isEqualTo(2);
RocksIterator iter = iterators.get(0); RocksIterator iter = iterators.get(0);
iter.seekToFirst(); iter.seekToFirst();
Map<String,String> defRefMap = new HashMap<String, String>(); Map<String, String> defRefMap = new HashMap<>();
defRefMap.put("dfkey1", "dfvalue"); defRefMap.put("dfkey1", "dfvalue");
defRefMap.put("key", "value"); defRefMap.put("key", "value");
while (iter.isValid()) { while (iter.isValid()) {
defRefMap.get(new String(iter.key())).equals( assertThat(defRefMap.get(new String(iter.key()))).
new String(iter.value())); isEqualTo(new String(iter.value()));
iter.next(); iter.next();
} }
// iterate over new_cf key/value pairs // iterate over new_cf key/value pairs
Map<String,String> cfRefMap = new HashMap<String, String>(); Map<String, String> cfRefMap = new HashMap<>();
cfRefMap.put("newcfkey", "value"); cfRefMap.put("newcfkey", "value");
cfRefMap.put("newcfkey2", "value2"); cfRefMap.put("newcfkey2", "value2");
iter = iterators.get(1); iter = iterators.get(1);
iter.seekToFirst(); iter.seekToFirst();
while (iter.isValid()) { while (iter.isValid()) {
cfRefMap.get(new String(iter.key())).equals( assertThat(cfRefMap.get(new String(iter.key()))).
new String(iter.value())); isEqualTo(new String(iter.value()));
iter.next(); iter.next();
} }
// free iterators } finally {
for (RocksIterator iterator : iterators) { if (db != null) {
iterator.dispose(); db.close();
}
if (options != null) {
options.dispose();
}
}
}
@Test(expected = RocksDBException.class)
public void failPutDisposedCF() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try {
options = new DBOptions();
options.setCreateIfMissing(true);
List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList);
db.dropColumnFamily(columnFamilyHandleList.get(1));
db.put(columnFamilyHandleList.get(1), "key".getBytes(), "value".getBytes());
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
}
}
@Test(expected = RocksDBException.class)
public void failRemoveDisposedCF() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try {
options = new DBOptions();
options.setCreateIfMissing(true);
List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList);
db.dropColumnFamily(columnFamilyHandleList.get(1));
db.remove(columnFamilyHandleList.get(1), "key".getBytes());
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
}
}
@Test(expected = RocksDBException.class)
public void failGetDisposedCF() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try {
options = new DBOptions();
options.setCreateIfMissing(true);
List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList);
db.dropColumnFamily(columnFamilyHandleList.get(1));
db.get(columnFamilyHandleList.get(1), "key".getBytes());
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
} }
assert(true);
} catch (RocksDBException e) {
assert(false);
} }
}
@Test(expected = RocksDBException.class)
public void failMultiGetWithoutCorrectNumberOfCF() throws RocksDBException {
RocksDB db = null;
DBOptions options = null;
try {
options = new DBOptions();
options.setCreateIfMissing(true);
List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
// free cf handles before database close db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) { cfNames, columnFamilyHandleList);
columnFamilyHandle.dispose(); List<byte[]> keys = new ArrayList<>();
keys.add("key".getBytes());
keys.add("newcfkey".getBytes());
List<ColumnFamilyHandle> cfCustomList = new ArrayList<>();
db.multiGet(cfCustomList, keys);
} finally {
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
} }
// close database
db.close();
// be sure to dispose c++ pointers
options.dispose();
} }
} }

@ -10,6 +10,8 @@ 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 FlushTest { public class FlushTest {
@ClassRule @ClassRule
@ -20,35 +22,44 @@ public class FlushTest {
public TemporaryFolder dbFolder = new TemporaryFolder(); public TemporaryFolder dbFolder = new TemporaryFolder();
@Test @Test
public void flush() { public void flush() throws RocksDBException {
RocksDB db = null; RocksDB db = null;
Options options = new Options(); Options options = null;
WriteOptions wOpt = new WriteOptions(); WriteOptions wOpt = null;
FlushOptions flushOptions = new FlushOptions(); FlushOptions flushOptions = null;
try { try {
options = new Options();
// Setup options // Setup options
options.setCreateIfMissing(true); options.setCreateIfMissing(true);
options.setMaxWriteBufferNumber(10); options.setMaxWriteBufferNumber(10);
options.setMinWriteBufferNumberToMerge(10); options.setMinWriteBufferNumberToMerge(10);
wOpt = new WriteOptions();
flushOptions = new FlushOptions();
flushOptions.setWaitForFlush(true); flushOptions.setWaitForFlush(true);
wOpt.setDisableWAL(true); wOpt.setDisableWAL(true);
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
db.put(wOpt, "key1".getBytes(), "value1".getBytes()); db.put(wOpt, "key1".getBytes(), "value1".getBytes());
db.put(wOpt, "key2".getBytes(), "value2".getBytes()); db.put(wOpt, "key2".getBytes(), "value2".getBytes());
db.put(wOpt, "key3".getBytes(), "value3".getBytes()); db.put(wOpt, "key3".getBytes(), "value3".getBytes());
db.put(wOpt, "key4".getBytes(), "value4".getBytes()); db.put(wOpt, "key4".getBytes(), "value4".getBytes());
assert(db.getProperty("rocksdb.num-entries-active-mem-table").equals("4")); assertThat(db.getProperty("rocksdb.num-entries-active-mem-table")).isEqualTo("4");
db.flush(flushOptions); db.flush(flushOptions);
assert(db.getProperty("rocksdb.num-entries-active-mem-table").equals("0")); assertThat(db.getProperty("rocksdb.num-entries-active-mem-table")).
} catch (RocksDBException e) { isEqualTo("0");
assert(false); } finally {
} if (flushOptions != null) {
flushOptions.dispose();
}
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
if (wOpt != null) {
wOpt.dispose();
}
db.close(); }
options.dispose();
wOpt.dispose();
flushOptions.dispose();
} }
} }

@ -34,7 +34,7 @@ public class KeyMayExistTest {
.setCreateMissingColumnFamilies(true); .setCreateMissingColumnFamilies(true);
// open database using cf names // open database using cf names
List<ColumnFamilyDescriptor> cfDescriptors = List<ColumnFamilyDescriptor> cfDescriptors =
new ArrayList<ColumnFamilyDescriptor>(); new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList = List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>(); new ArrayList<>();
cfDescriptors.add(new ColumnFamilyDescriptor("default")); cfDescriptors.add(new ColumnFamilyDescriptor("default"));

@ -177,11 +177,12 @@ public class MergeTest {
// Test also with createColumnFamily // Test also with createColumnFamily
columnFamilyHandle = db.createColumnFamily( columnFamilyHandle = db.createColumnFamily(
new ColumnFamilyDescriptor("new_cf2")); new ColumnFamilyDescriptor("new_cf2",
new ColumnFamilyOptions().setMergeOperator(stringAppendOperator)));
// writing xx under cfkey2 // writing xx under cfkey2
db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes()); db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes());
// merge yy under cfkey2 // merge yy under cfkey2
db.merge(columnFamilyHandle, "cfkey2".getBytes(), "yy".getBytes()); db.merge(columnFamilyHandle, new WriteOptions(), "cfkey2".getBytes(), "yy".getBytes());
value = db.get(columnFamilyHandle, "cfkey2".getBytes()); value = db.get(columnFamilyHandle, "cfkey2".getBytes());
String strValueTmpCf = new String(value); String strValueTmpCf = new String(value);

@ -5,26 +5,33 @@
package org.rocksdb.test; package org.rocksdb.test;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.*; import org.rocksdb.*;
import static org.assertj.core.api.Assertions.assertThat;
public class MixedOptionsTest { public class MixedOptionsTest {
static {
RocksDB.loadLibrary(); @ClassRule
} public static final RocksMemoryResource rocksMemoryResource =
public static void main(String[] args) { new RocksMemoryResource();
@Test
public void mixedOptionsTest(){
// Set a table factory and check the names // Set a table factory and check the names
ColumnFamilyOptions cfOptions = new ColumnFamilyOptions(); ColumnFamilyOptions cfOptions = new ColumnFamilyOptions();
cfOptions.setTableFormatConfig(new BlockBasedTableConfig(). cfOptions.setTableFormatConfig(new BlockBasedTableConfig().
setFilter(new BloomFilter())); setFilter(new BloomFilter()));
assert(cfOptions.tableFactoryName().equals( assertThat(cfOptions.tableFactoryName()).isEqualTo(
"BlockBasedTable")); "BlockBasedTable");
cfOptions.setTableFormatConfig(new PlainTableConfig()); cfOptions.setTableFormatConfig(new PlainTableConfig());
assert(cfOptions.tableFactoryName().equals("PlainTable")); assertThat(cfOptions.tableFactoryName()).isEqualTo("PlainTable");
// Initialize a dbOptions object from cf options and // Initialize a dbOptions object from cf options and
// db options // db options
DBOptions dbOptions = new DBOptions(); DBOptions dbOptions = new DBOptions();
Options options = new Options(dbOptions, cfOptions); Options options = new Options(dbOptions, cfOptions);
assert(options.tableFactoryName().equals("PlainTable")); assertThat(options.tableFactoryName()).isEqualTo("PlainTable");
// Free instances // Free instances
options.dispose(); options.dispose();
options = null; options = null;

@ -23,196 +23,463 @@ public class OptionsTest {
getPlatformSpecificRandomFactory(); getPlatformSpecificRandomFactory();
@Test @Test
public void options() throws RocksDBException { public void writeBufferSize() throws RocksDBException {
Options opt = null; Options opt = null;
try { try {
opt = new Options(); opt = new Options();
long longValue = rand.nextLong();
{ // WriteBufferSize test opt.setWriteBufferSize(longValue);
long longValue = rand.nextLong(); assertThat(opt.writeBufferSize()).isEqualTo(longValue);
opt.setWriteBufferSize(longValue); } finally {
assert (opt.writeBufferSize() == longValue); if (opt != null) {
opt.dispose();
} }
}
}
{ // MaxWriteBufferNumber test @Test
int intValue = rand.nextInt(); public void maxWriteBufferNumber() {
opt.setMaxWriteBufferNumber(intValue); Options opt = null;
assert (opt.maxWriteBufferNumber() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setMaxWriteBufferNumber(intValue);
assertThat(opt.maxWriteBufferNumber()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MinWriteBufferNumberToMerge test @Test
int intValue = rand.nextInt(); public void minWriteBufferNumberToMerge() {
opt.setMinWriteBufferNumberToMerge(intValue); Options opt = null;
assert (opt.minWriteBufferNumberToMerge() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setMinWriteBufferNumberToMerge(intValue);
assertThat(opt.minWriteBufferNumberToMerge()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // NumLevels test @Test
int intValue = rand.nextInt(); public void numLevels() {
opt.setNumLevels(intValue); Options opt = null;
assert (opt.numLevels() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setNumLevels(intValue);
assertThat(opt.numLevels()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // LevelFileNumCompactionTrigger test @Test
int intValue = rand.nextInt(); public void levelZeroFileNumCompactionTrigger() {
opt.setLevelZeroFileNumCompactionTrigger(intValue); Options opt = null;
assert (opt.levelZeroFileNumCompactionTrigger() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setLevelZeroFileNumCompactionTrigger(intValue);
assertThat(opt.levelZeroFileNumCompactionTrigger()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // LevelSlowdownWritesTrigger test @Test
int intValue = rand.nextInt(); public void levelZeroSlowdownWritesTrigger() {
opt.setLevelZeroSlowdownWritesTrigger(intValue); Options opt = null;
assert (opt.levelZeroSlowdownWritesTrigger() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setLevelZeroSlowdownWritesTrigger(intValue);
assertThat(opt.levelZeroSlowdownWritesTrigger()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // LevelStopWritesTrigger test @Test
int intValue = rand.nextInt(); public void levelZeroStopWritesTrigger() {
opt.setLevelZeroStopWritesTrigger(intValue); Options opt = null;
assert (opt.levelZeroStopWritesTrigger() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setLevelZeroStopWritesTrigger(intValue);
assertThat(opt.levelZeroStopWritesTrigger()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MaxMemCompactionLevel test @Test
int intValue = rand.nextInt(); public void maxMemCompactionLevel() {
opt.setMaxMemCompactionLevel(intValue); Options opt = null;
assert (opt.maxMemCompactionLevel() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setMaxMemCompactionLevel(intValue);
assertThat(opt.maxMemCompactionLevel()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // TargetFileSizeBase test @Test
long longValue = rand.nextLong(); public void targetFileSizeBase() {
opt.setTargetFileSizeBase(longValue); Options opt = null;
assert (opt.targetFileSizeBase() == longValue); try {
opt = new Options();
long longValue = rand.nextLong();
opt.setTargetFileSizeBase(longValue);
assertThat(opt.targetFileSizeBase()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // TargetFileSizeMultiplier test @Test
int intValue = rand.nextInt(); public void targetFileSizeMultiplier() {
opt.setTargetFileSizeMultiplier(intValue); Options opt = null;
assert (opt.targetFileSizeMultiplier() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setTargetFileSizeMultiplier(intValue);
assertThat(opt.targetFileSizeMultiplier()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MaxBytesForLevelBase test @Test
long longValue = rand.nextLong(); public void maxBytesForLevelBase() {
opt.setMaxBytesForLevelBase(longValue); Options opt = null;
assert (opt.maxBytesForLevelBase() == longValue); try {
opt = new Options();
long longValue = rand.nextLong();
opt.setMaxBytesForLevelBase(longValue);
assertThat(opt.maxBytesForLevelBase()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MaxBytesForLevelMultiplier test @Test
int intValue = rand.nextInt(); public void maxBytesForLevelMultiplier() {
opt.setMaxBytesForLevelMultiplier(intValue); Options opt = null;
assert (opt.maxBytesForLevelMultiplier() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setMaxBytesForLevelMultiplier(intValue);
assertThat(opt.maxBytesForLevelMultiplier()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // ExpandedCompactionFactor test @Test
int intValue = rand.nextInt(); public void expandedCompactionFactor() {
opt.setExpandedCompactionFactor(intValue); Options opt = null;
assert (opt.expandedCompactionFactor() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setExpandedCompactionFactor(intValue);
assertThat(opt.expandedCompactionFactor()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // SourceCompactionFactor test @Test
int intValue = rand.nextInt(); public void sourceCompactionFactor() {
opt.setSourceCompactionFactor(intValue); Options opt = null;
assert (opt.sourceCompactionFactor() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setSourceCompactionFactor(intValue);
assertThat(opt.sourceCompactionFactor()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MaxGrandparentOverlapFactor test @Test
int intValue = rand.nextInt(); public void maxGrandparentOverlapFactor() {
opt.setMaxGrandparentOverlapFactor(intValue); Options opt = null;
assert (opt.maxGrandparentOverlapFactor() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setMaxGrandparentOverlapFactor(intValue);
assertThat(opt.maxGrandparentOverlapFactor()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // SoftRateLimit test @Test
double doubleValue = rand.nextDouble(); public void softRateLimit() {
opt.setSoftRateLimit(doubleValue); Options opt = null;
assert (opt.softRateLimit() == doubleValue); try {
opt = new Options();
double doubleValue = rand.nextDouble();
opt.setSoftRateLimit(doubleValue);
assertThat(opt.softRateLimit()).isEqualTo(doubleValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // HardRateLimit test @Test
double doubleValue = rand.nextDouble(); public void hardRateLimit() {
opt.setHardRateLimit(doubleValue); Options opt = null;
assert (opt.hardRateLimit() == doubleValue); try {
opt = new Options();
double doubleValue = rand.nextDouble();
opt.setHardRateLimit(doubleValue);
assertThat(opt.hardRateLimit()).isEqualTo(doubleValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // RateLimitDelayMaxMilliseconds test @Test
int intValue = rand.nextInt(); public void rateLimitDelayMaxMilliseconds() {
opt.setRateLimitDelayMaxMilliseconds(intValue); Options opt = null;
assert (opt.rateLimitDelayMaxMilliseconds() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setRateLimitDelayMaxMilliseconds(intValue);
assertThat(opt.rateLimitDelayMaxMilliseconds()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // ArenaBlockSize test @Test
long longValue = rand.nextLong(); public void arenaBlockSize() throws RocksDBException {
opt.setArenaBlockSize(longValue); Options opt = null;
assert (opt.arenaBlockSize() == longValue); try {
opt = new Options();
long longValue = rand.nextLong();
opt.setArenaBlockSize(longValue);
assertThat(opt.arenaBlockSize()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // DisableAutoCompactions test @Test
boolean boolValue = rand.nextBoolean(); public void disableAutoCompactions() {
opt.setDisableAutoCompactions(boolValue); Options opt = null;
assert (opt.disableAutoCompactions() == boolValue); try {
opt = new Options();
boolean boolValue = rand.nextBoolean();
opt.setDisableAutoCompactions(boolValue);
assertThat(opt.disableAutoCompactions()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // PurgeRedundantKvsWhileFlush test @Test
boolean boolValue = rand.nextBoolean(); public void purgeRedundantKvsWhileFlush() {
opt.setPurgeRedundantKvsWhileFlush(boolValue); Options opt = null;
assert (opt.purgeRedundantKvsWhileFlush() == boolValue); try {
opt = new Options();
boolean boolValue = rand.nextBoolean();
opt.setPurgeRedundantKvsWhileFlush(boolValue);
assertThat(opt.purgeRedundantKvsWhileFlush()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // VerifyChecksumsInCompaction test @Test
boolean boolValue = rand.nextBoolean(); public void verifyChecksumsInCompaction() {
opt.setVerifyChecksumsInCompaction(boolValue); Options opt = null;
assert (opt.verifyChecksumsInCompaction() == boolValue); try {
opt = new Options();
boolean boolValue = rand.nextBoolean();
opt.setVerifyChecksumsInCompaction(boolValue);
assertThat(opt.verifyChecksumsInCompaction()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // FilterDeletes test @Test
boolean boolValue = rand.nextBoolean(); public void filterDeletes() {
opt.setFilterDeletes(boolValue); Options opt = null;
assert (opt.filterDeletes() == boolValue); try {
opt = new Options();
boolean boolValue = rand.nextBoolean();
opt.setFilterDeletes(boolValue);
assertThat(opt.filterDeletes()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MaxSequentialSkipInIterations test @Test
long longValue = rand.nextLong(); public void maxSequentialSkipInIterations() {
opt.setMaxSequentialSkipInIterations(longValue); Options opt = null;
assert (opt.maxSequentialSkipInIterations() == longValue); try {
opt = new Options();
long longValue = rand.nextLong();
opt.setMaxSequentialSkipInIterations(longValue);
assertThat(opt.maxSequentialSkipInIterations()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // InplaceUpdateSupport test @Test
boolean boolValue = rand.nextBoolean(); public void inplaceUpdateSupport() {
opt.setInplaceUpdateSupport(boolValue); Options opt = null;
assert (opt.inplaceUpdateSupport() == boolValue); try {
opt = new Options();
boolean boolValue = rand.nextBoolean();
opt.setInplaceUpdateSupport(boolValue);
assertThat(opt.inplaceUpdateSupport()).isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // InplaceUpdateNumLocks test @Test
long longValue = rand.nextLong(); public void inplaceUpdateNumLocks() throws RocksDBException {
opt.setInplaceUpdateNumLocks(longValue); Options opt = null;
assert (opt.inplaceUpdateNumLocks() == longValue); try {
opt = new Options();
long longValue = rand.nextLong();
opt.setInplaceUpdateNumLocks(longValue);
assertThat(opt.inplaceUpdateNumLocks()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MemtablePrefixBloomBits test @Test
int intValue = rand.nextInt(); public void memtablePrefixBloomBits() {
opt.setMemtablePrefixBloomBits(intValue); Options opt = null;
assert (opt.memtablePrefixBloomBits() == intValue); try {
opt = new Options();
int intValue = rand.nextInt();
opt.setMemtablePrefixBloomBits(intValue);
assertThat(opt.memtablePrefixBloomBits()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MemtablePrefixBloomProbes test @Test
int intValue = rand.nextInt(); public void memtablePrefixBloomProbes() {
opt.setMemtablePrefixBloomProbes(intValue); Options opt = null;
assert (opt.memtablePrefixBloomProbes() == intValue); try {
int intValue = rand.nextInt();
opt = new Options();
opt.setMemtablePrefixBloomProbes(intValue);
assertThat(opt.memtablePrefixBloomProbes()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // BloomLocality test @Test
int intValue = rand.nextInt(); public void bloomLocality() {
opt.setBloomLocality(intValue); Options opt = null;
assert (opt.bloomLocality() == intValue); try {
int intValue = rand.nextInt();
opt = new Options();
opt.setBloomLocality(intValue);
assertThat(opt.bloomLocality()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MaxSuccessiveMerges test @Test
long longValue = rand.nextLong(); public void maxSuccessiveMerges() throws RocksDBException {
opt.setMaxSuccessiveMerges(longValue); Options opt = null;
assert (opt.maxSuccessiveMerges() == longValue); try {
long longValue = rand.nextLong();
opt = new Options();
opt.setMaxSuccessiveMerges(longValue);
assertThat(opt.maxSuccessiveMerges()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
} }
}
}
{ // MinPartialMergeOperands test @Test
int intValue = rand.nextInt(); public void minPartialMergeOperands() {
opt.setMinPartialMergeOperands(intValue); Options opt = null;
assert (opt.minPartialMergeOperands() == intValue); try {
} int intValue = rand.nextInt();
opt = new Options();
opt.setMinPartialMergeOperands(intValue);
assertThat(opt.minPartialMergeOperands()).isEqualTo(intValue);
} finally { } finally {
if (opt != null) { if (opt != null) {
opt.dispose(); opt.dispose();

@ -75,10 +75,10 @@ public class WriteBatchHandlerTest {
// compare the results to the test data // compare the results to the test data
final List<Tuple<Action, Tuple<byte[], byte[]>>> actualEvents = handler.getEvents(); final List<Tuple<Action, Tuple<byte[], byte[]>>> actualEvents = handler.getEvents();
assert(testEvents.size() == actualEvents.size()); assertThat(testEvents.size()).isSameAs(actualEvents.size());
for(int i = 0; i < testEvents.size(); i++) { for(int i = 0; i < testEvents.size(); i++) {
assert(equals(testEvents.get(i), actualEvents.get(i))); assertThat(equals(testEvents.get(i), actualEvents.get(i))).isTrue();
} }
System.out.println("Passed WriteBatchHandler Test"); System.out.println("Passed WriteBatchHandler Test");

Loading…
Cancel
Save