[RocksJava] Rebased + integrated CF tests

This commit is contained in:
fyrz 2014-11-13 22:27:58 +01:00
parent cd82beb0cb
commit e46450da6d
10 changed files with 1393 additions and 482 deletions

View File

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

View File

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

View File

@ -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;
public class ColumnFamilyOptionsTest { import static org.assertj.core.api.Assertions.assertThat;
static {
RocksDB.loadLibrary();
}
public static void testCFOptions(ColumnFamilyOptionsInterface opt) { public class ColumnFamilyOptionsTest {
Random rand = PlatformRandomHelper.
@ClassRule
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
public static final Random rand = PlatformRandomHelper.
getPlatformSpecificRandomFactory(); getPlatformSpecificRandomFactory();
{ // WriteBufferSize test
@Test
public void writeBufferSize() throws RocksDBException {
ColumnFamilyOptions opt = null;
try { try {
opt = new ColumnFamilyOptions();
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setWriteBufferSize(longValue); opt.setWriteBufferSize(longValue);
assert(opt.writeBufferSize() == longValue); assertThat(opt.writeBufferSize()).isEqualTo(longValue);
} catch (RocksDBException e) { } finally {
assert(false); 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
public void arenaBlockSize() throws RocksDBException {
ColumnFamilyOptions opt = null;
try { try {
opt = new ColumnFamilyOptions();
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setArenaBlockSize(longValue); opt.setArenaBlockSize(longValue);
assert(opt.arenaBlockSize() == longValue); assertThat(opt.arenaBlockSize()).isEqualTo(longValue);
} catch (RocksDBException e) { } finally {
assert(false); 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
public void inplaceUpdateNumLocks() throws RocksDBException {
ColumnFamilyOptions opt = null;
try { try {
opt = new ColumnFamilyOptions();
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setInplaceUpdateNumLocks(longValue); opt.setInplaceUpdateNumLocks(longValue);
assert(opt.inplaceUpdateNumLocks() == longValue); assertThat(opt.inplaceUpdateNumLocks()).isEqualTo(longValue);
} catch (RocksDBException e) { } finally {
assert(false); 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
public void maxSuccessiveMerges() throws RocksDBException {
ColumnFamilyOptions opt = null;
try { try {
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt = new ColumnFamilyOptions();
opt.setMaxSuccessiveMerges(longValue); opt.setMaxSuccessiveMerges(longValue);
assert(opt.maxSuccessiveMerges() == longValue); assertThat(opt.maxSuccessiveMerges()).isEqualTo(longValue);
} catch (RocksDBException e){ } finally {
assert(false); if (opt != null) {
}
}
{ // MinPartialMergeOperands test
int intValue = rand.nextInt();
opt.setMinPartialMergeOperands(intValue);
assert(opt.minPartialMergeOperands() == intValue);
}
}
public static void main(String[] args) {
ColumnFamilyOptions opt = new ColumnFamilyOptions();
testCFOptions(opt);
opt.dispose(); opt.dispose();
System.out.println("Passed DBOptionsTest"); }
}
}
@Test
public void minPartialMergeOperands() {
ColumnFamilyOptions opt = null;
try {
int intValue = rand.nextInt();
opt = new ColumnFamilyOptions();
opt.setMinPartialMergeOperands(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();
}
}
}
@Test
public void compressionTypes() {
ColumnFamilyOptions ColumnFamilyOptions = null;
try {
ColumnFamilyOptions = new ColumnFamilyOptions();
for (CompressionType compressionType :
CompressionType.values()) {
ColumnFamilyOptions.setCompressionType(compressionType);
assertThat(ColumnFamilyOptions.compressionType()).
isEqualTo(compressionType);
assertThat(CompressionType.valueOf("NO_COMPRESSION")).
isEqualTo(CompressionType.NO_COMPRESSION);
}
} finally {
if (ColumnFamilyOptions != null) {
ColumnFamilyOptions.dispose();
}
}
}
@Test
public void compactionStyles() {
ColumnFamilyOptions ColumnFamilyOptions = null;
try {
ColumnFamilyOptions = new ColumnFamilyOptions();
for (CompactionStyle compactionStyle :
CompactionStyle.values()) {
ColumnFamilyOptions.setCompactionStyle(compactionStyle);
assertThat(ColumnFamilyOptions.compactionStyle()).
isEqualTo(compactionStyle);
assertThat(CompactionStyle.valueOf("FIFO")).
isEqualTo(CompactionStyle.FIFO);
}
} finally {
if (ColumnFamilyOptions != null) {
ColumnFamilyOptions.dispose();
}
}
} }
} }

View File

@ -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;
try {
options = new Options();
options.setCreateIfMissing(true); 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);
} catch (RocksDBException e) {
assert(false);
}
// Test listColumnFamilies // Test listColumnFamilies
List<byte[]> columnFamilyNames; List<byte[]> columnFamilyNames;
try { columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath());
columnFamilyNames = RocksDB.listColumnFamilies(options, db_path); assertThat(columnFamilyNames).isNotNull();
if (columnFamilyNames != null && columnFamilyNames.size() > 0) { assertThat(columnFamilyNames.size()).isGreaterThan(0);
assert(columnFamilyNames.size() == 1); assertThat(columnFamilyNames.size()).isEqualTo(1);
assert(new String(columnFamilyNames.get(0)).equals("default")); assertThat(new String(columnFamilyNames.get(0))).isEqualTo("default");
} else { } finally {
assert(false);
}
} catch (RocksDBException e) {
assert(false);
}
// Test createColumnFamily
try {
db.createColumnFamily(new ColumnFamilyDescriptor("new_cf",
new ColumnFamilyOptions()));
} catch (RocksDBException e) {
assert(false);
}
if (db != null) { if (db != null) {
db.close(); db.close();
} }
if (options != null) {
options.dispose();
}
}
}
// Test listColumnFamilies after create "new_cf" @Test
public void createColumnFamily() throws RocksDBException {
RocksDB db = null;
Options options = null;
try { try {
columnFamilyNames = RocksDB.listColumnFamilies(options, db_path); options = new Options();
if (columnFamilyNames != null && columnFamilyNames.size() > 0) { options.setCreateIfMissing(true);
assert(columnFamilyNames.size() == 2);
assert(new String(columnFamilyNames.get(0)).equals("default")); DBOptions dbOptions = new DBOptions();
assert(new String(columnFamilyNames.get(1)).equals("new_cf")); dbOptions.setCreateIfMissing(true);
} else {
assert(false); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
db.createColumnFamily(new ColumnFamilyDescriptor("new_cf",
new ColumnFamilyOptions()));
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();
}
} }
} catch (RocksDBException e) {
assert(false);
} }
@Test
public void openWithColumnFamilies() 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 // Test open database with column family names
List<ColumnFamilyDescriptor> cfNames = List<ColumnFamilyDescriptor> cfNames =
new ArrayList<>(); new ArrayList<>();
List<ColumnFamilyHandle> columnFamilyHandleList = List<ColumnFamilyHandle> columnFamilyHandleList =
new ArrayList<>(); new ArrayList<>();
cfNames.add(new ColumnFamilyDescriptor("default")); cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf")); 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 create write to and drop ColumnFamily @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
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();
}
if (db != null) {
db.close();
}
if (opt != null) {
opt.dispose();
}
}
} }
// Put to disposed column family tmpColumnFamilyHandle must fail @Test
public void writeBatch() throws RocksDBException {
RocksDB db = null;
DBOptions opt = null;
try { try {
db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".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"));
// Remove to disposed column family tmpColumnFamilyHandle must fail db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
try { cfNames, columnFamilyHandleList);
db.remove(tmpColumnFamilyHandle, "key".getBytes());
assert(false);
} catch (RocksDBException e) {
assert(true);
}
// Get on a disposed column family tmpColumnFamilyHandle must fail
try {
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
// families @Test
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();
}
assert(true);
} catch (RocksDBException e) {
assert(false);
}
// free cf handles before database close
for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) {
columnFamilyHandle.dispose();
}
// close database
db.close(); db.close();
// be sure to dispose c++ pointers }
if (options != null) {
options.dispose(); 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();
}
}
}
@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"));
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
cfNames, columnFamilyHandleList);
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();
}
}
}
}

View File

@ -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) {
db.close();
options.dispose();
wOpt.dispose();
flushOptions.dispose(); flushOptions.dispose();
} }
if (db != null) {
db.close();
}
if (options != null) {
options.dispose();
}
if (wOpt != null) {
wOpt.dispose();
}
}
}
} }

View File

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

View File

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

View File

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

View File

@ -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();
{ // WriteBufferSize test
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setWriteBufferSize(longValue); opt.setWriteBufferSize(longValue);
assert (opt.writeBufferSize() == longValue); assertThat(opt.writeBufferSize()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
}
}
} }
{ // MaxWriteBufferNumber test @Test
public void maxWriteBufferNumber() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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
public void arenaBlockSize() throws RocksDBException {
Options opt = null;
try {
opt = new Options();
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setArenaBlockSize(longValue); opt.setArenaBlockSize(longValue);
assert (opt.arenaBlockSize() == longValue); assertThat(opt.arenaBlockSize()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
}
}
} }
{ // DisableAutoCompactions test @Test
public void disableAutoCompactions() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
opt = new Options();
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
public void inplaceUpdateNumLocks() throws RocksDBException {
Options opt = null;
try {
opt = new Options();
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt.setInplaceUpdateNumLocks(longValue); opt.setInplaceUpdateNumLocks(longValue);
assert (opt.inplaceUpdateNumLocks() == longValue); assertThat(opt.inplaceUpdateNumLocks()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
}
}
} }
{ // MemtablePrefixBloomBits test @Test
public void memtablePrefixBloomBits() {
Options opt = null;
try {
opt = new Options();
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() {
Options opt = null;
try {
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt = new Options();
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() {
Options opt = null;
try {
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt = new Options();
opt.setBloomLocality(intValue); opt.setBloomLocality(intValue);
assert (opt.bloomLocality() == intValue); assertThat(opt.bloomLocality()).isEqualTo(intValue);
} finally {
if (opt != null) {
opt.dispose();
}
}
} }
{ // MaxSuccessiveMerges test @Test
public void maxSuccessiveMerges() throws RocksDBException {
Options opt = null;
try {
long longValue = rand.nextLong(); long longValue = rand.nextLong();
opt = new Options();
opt.setMaxSuccessiveMerges(longValue); opt.setMaxSuccessiveMerges(longValue);
assert (opt.maxSuccessiveMerges() == longValue); assertThat(opt.maxSuccessiveMerges()).isEqualTo(longValue);
} finally {
if (opt != null) {
opt.dispose();
}
}
} }
{ // MinPartialMergeOperands test @Test
public void minPartialMergeOperands() {
Options opt = null;
try {
int intValue = rand.nextInt(); int intValue = rand.nextInt();
opt = new Options();
opt.setMinPartialMergeOperands(intValue); opt.setMinPartialMergeOperands(intValue);
assert (opt.minPartialMergeOperands() == intValue); assertThat(opt.minPartialMergeOperands()).isEqualTo(intValue);
}
} finally { } finally {
if (opt != null) { if (opt != null) {
opt.dispose(); opt.dispose();

View File

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