[RocksJava] Rebased + integrated CF tests
This commit is contained in:
parent
cd82beb0cb
commit
e46450da6d
@ -47,8 +47,7 @@ ifeq ($(PLATFORM), OS_MACOSX)
|
||||
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar
|
||||
endif
|
||||
|
||||
JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
|
||||
org.rocksdb.test.BackupableDBTest\
|
||||
JAVA_TESTS = org.rocksdb.test.BackupableDBTest\
|
||||
org.rocksdb.test.BlockBasedTableConfigTest\
|
||||
org.rocksdb.test.ColumnFamilyOptionsTest\
|
||||
org.rocksdb.test.ColumnFamilyTest\
|
||||
@ -71,7 +70,7 @@ JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
|
||||
org.rocksdb.test.RocksIteratorTest\
|
||||
org.rocksdb.test.SnapshotTest\
|
||||
org.rocksdb.test.StatisticsCollectorTest\
|
||||
org.rocksdb.test.WirteBatchHandlerTest\
|
||||
org.rocksdb.test.WriteBatchHandlerTest\
|
||||
org.rocksdb.test.WriteBatchTest\
|
||||
org.rocksdb.test.WriteOptionsTest\
|
||||
|
||||
|
@ -12,6 +12,7 @@ import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
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.intToByte;
|
||||
|
||||
@ -75,13 +76,13 @@ public abstract class AbstractComparatorTest {
|
||||
int count = 0;
|
||||
for (it.seekToFirst(); it.isValid(); it.next()) {
|
||||
final int thisKey = byteToInt(it.key());
|
||||
assert(thisKey > lastKey);
|
||||
assertThat(thisKey).isGreaterThan(lastKey);
|
||||
lastKey = thisKey;
|
||||
count++;
|
||||
}
|
||||
db.close();
|
||||
|
||||
assert(count == ITERATIONS);
|
||||
assertThat(count).isEqualTo(ITERATIONS);
|
||||
|
||||
} catch (final RocksDBException e) {
|
||||
System.err.format("[ERROR]: %s%n", e);
|
||||
|
@ -5,225 +5,584 @@
|
||||
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class ColumnFamilyOptionsTest {
|
||||
static {
|
||||
RocksDB.loadLibrary();
|
||||
}
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public static void testCFOptions(ColumnFamilyOptionsInterface opt) {
|
||||
Random rand = PlatformRandomHelper.
|
||||
public class ColumnFamilyOptionsTest {
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
public static final Random rand = PlatformRandomHelper.
|
||||
getPlatformSpecificRandomFactory();
|
||||
{ // WriteBufferSize test
|
||||
|
||||
@Test
|
||||
public void writeBufferSize() throws RocksDBException {
|
||||
ColumnFamilyOptions opt = null;
|
||||
try {
|
||||
opt = new ColumnFamilyOptions();
|
||||
long longValue = rand.nextLong();
|
||||
opt.setWriteBufferSize(longValue);
|
||||
assert(opt.writeBufferSize() == longValue);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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 {
|
||||
opt = new ColumnFamilyOptions();
|
||||
long longValue = rand.nextLong();
|
||||
opt.setArenaBlockSize(longValue);
|
||||
assert(opt.arenaBlockSize() == longValue);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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 {
|
||||
opt = new ColumnFamilyOptions();
|
||||
long longValue = rand.nextLong();
|
||||
opt.setInplaceUpdateNumLocks(longValue);
|
||||
assert(opt.inplaceUpdateNumLocks() == longValue);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
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();
|
||||
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();
|
||||
opt = new ColumnFamilyOptions();
|
||||
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();
|
||||
opt = new ColumnFamilyOptions();
|
||||
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 {
|
||||
long longValue = rand.nextLong();
|
||||
opt = new ColumnFamilyOptions();
|
||||
opt.setMaxSuccessiveMerges(longValue);
|
||||
assert(opt.maxSuccessiveMerges() == longValue);
|
||||
} catch (RocksDBException e){
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
{ // 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);
|
||||
assertThat(opt.maxSuccessiveMerges()).isEqualTo(longValue);
|
||||
} finally {
|
||||
if (opt != null) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ColumnFamilyTest {
|
||||
|
||||
@ClassRule
|
||||
@ -26,71 +28,85 @@ public class ColumnFamilyTest {
|
||||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void columnFamilies() {
|
||||
String db_path = dbFolder.getRoot().getAbsolutePath();
|
||||
public void listColumnFamilies() throws RocksDBException {
|
||||
RocksDB db = null;
|
||||
Options options = new Options();
|
||||
Options options = null;
|
||||
try {
|
||||
options = new Options();
|
||||
options.setCreateIfMissing(true);
|
||||
|
||||
DBOptions dbOptions = new DBOptions();
|
||||
dbOptions.setCreateIfMissing(true);
|
||||
|
||||
try {
|
||||
db = RocksDB.open(options, db_path);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
}
|
||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
|
||||
// Test listColumnFamilies
|
||||
List<byte[]> columnFamilyNames;
|
||||
try {
|
||||
columnFamilyNames = RocksDB.listColumnFamilies(options, db_path);
|
||||
if (columnFamilyNames != null && columnFamilyNames.size() > 0) {
|
||||
assert(columnFamilyNames.size() == 1);
|
||||
assert(new String(columnFamilyNames.get(0)).equals("default"));
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
// Test createColumnFamily
|
||||
try {
|
||||
db.createColumnFamily(new ColumnFamilyDescriptor("new_cf",
|
||||
new ColumnFamilyOptions()));
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
columnFamilyNames = RocksDB.listColumnFamilies(options, dbFolder.getRoot().getAbsolutePath());
|
||||
assertThat(columnFamilyNames).isNotNull();
|
||||
assertThat(columnFamilyNames.size()).isGreaterThan(0);
|
||||
assertThat(columnFamilyNames.size()).isEqualTo(1);
|
||||
assertThat(new String(columnFamilyNames.get(0))).isEqualTo("default");
|
||||
} finally {
|
||||
if (db != null) {
|
||||
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 {
|
||||
columnFamilyNames = RocksDB.listColumnFamilies(options, db_path);
|
||||
if (columnFamilyNames != null && columnFamilyNames.size() > 0) {
|
||||
assert(columnFamilyNames.size() == 2);
|
||||
assert(new String(columnFamilyNames.get(0)).equals("default"));
|
||||
assert(new String(columnFamilyNames.get(1)).equals("new_cf"));
|
||||
} else {
|
||||
assert(false);
|
||||
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",
|
||||
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
|
||||
List<ColumnFamilyDescriptor> cfNames =
|
||||
new ArrayList<>();
|
||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||
new ArrayList<>();
|
||||
cfNames.add(new ColumnFamilyDescriptor("default"));
|
||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
||||
|
||||
try {
|
||||
db = RocksDB.open(dbOptions, db_path, cfNames, columnFamilyHandleList);
|
||||
assert(columnFamilyHandleList.size() == 2);
|
||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||
cfNames, columnFamilyHandleList);
|
||||
assertThat(columnFamilyHandleList.size()).isEqualTo(2);
|
||||
db.put("dfkey1".getBytes(), "dfvalue".getBytes());
|
||||
db.put(columnFamilyHandleList.get(0), "dfkey2".getBytes(),
|
||||
"dfvalue".getBytes());
|
||||
@ -99,57 +115,118 @@ public class ColumnFamilyTest {
|
||||
|
||||
String retVal = new String(db.get(columnFamilyHandleList.get(1),
|
||||
"newcfkey1".getBytes()));
|
||||
assert(retVal.equals("newcfvalue"));
|
||||
assert( (db.get(columnFamilyHandleList.get(1),
|
||||
"dfkey1".getBytes())) == null);
|
||||
assertThat(retVal).isEqualTo("newcfvalue");
|
||||
assertThat((db.get(columnFamilyHandleList.get(1),
|
||||
"dfkey1".getBytes()))).isNull();
|
||||
db.remove(columnFamilyHandleList.get(1), "newcfkey1".getBytes());
|
||||
assert( (db.get(columnFamilyHandleList.get(1),
|
||||
"newcfkey1".getBytes())) == null);
|
||||
db.remove("dfkey2".getBytes());
|
||||
assert( (db.get(columnFamilyHandleList.get(0),
|
||||
"dfkey2".getBytes())) == null);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
assertThat((db.get(columnFamilyHandleList.get(1),
|
||||
"newcfkey1".getBytes()))).isNull();
|
||||
db.remove(columnFamilyHandleList.get(0), new WriteOptions(),
|
||||
"dfkey2".getBytes());
|
||||
assertThat(db.get(columnFamilyHandleList.get(0), new ReadOptions(),
|
||||
"dfkey2".getBytes())).isNull();
|
||||
} 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;
|
||||
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(
|
||||
new ColumnFamilyDescriptor("tmpCF", new ColumnFamilyOptions()));
|
||||
db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes());
|
||||
db.dropColumnFamily(tmpColumnFamilyHandle);
|
||||
tmpColumnFamilyHandle.dispose();
|
||||
} catch (Exception e) {
|
||||
assert(false);
|
||||
} finally {
|
||||
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 {
|
||||
db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes());
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(true);
|
||||
}
|
||||
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"));
|
||||
|
||||
// Remove to disposed column family tmpColumnFamilyHandle must fail
|
||||
try {
|
||||
db.remove(tmpColumnFamilyHandle, "key".getBytes());
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(true);
|
||||
}
|
||||
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
|
||||
cfNames, columnFamilyHandleList);
|
||||
|
||||
// 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();
|
||||
WriteOptions writeOpt = new WriteOptions();
|
||||
writeBatch.put("key".getBytes(), "value".getBytes());
|
||||
@ -161,135 +238,324 @@ public class ColumnFamilyTest {
|
||||
writeBatch.remove(columnFamilyHandleList.get(1), "xyz".getBytes());
|
||||
db.write(writeOpt, writeBatch);
|
||||
writeBatch.dispose();
|
||||
assert(db.get(columnFamilyHandleList.get(1),
|
||||
assertThat(db.get(columnFamilyHandleList.get(1),
|
||||
"xyz".getBytes()) == null);
|
||||
assert(new String(db.get(columnFamilyHandleList.get(1),
|
||||
"newcfkey".getBytes())).equals("value"));
|
||||
assert(new String(db.get(columnFamilyHandleList.get(1),
|
||||
"newcfkey2".getBytes())).equals("value2"));
|
||||
assert(new String(db.get("key".getBytes())).equals("value"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assert(false);
|
||||
assertThat(new String(db.get(columnFamilyHandleList.get(1),
|
||||
"newcfkey".getBytes()))).isEqualTo("value");
|
||||
assertThat(new String(db.get(columnFamilyHandleList.get(1),
|
||||
"newcfkey2".getBytes()))).isEqualTo("value2");
|
||||
assertThat(new String(db.get("key".getBytes()))).isEqualTo("value");
|
||||
} finally {
|
||||
if (db != null) {
|
||||
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 {
|
||||
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));
|
||||
rocksIterator.seekToFirst();
|
||||
Map<String, String> refMap = new HashMap<String, String>();
|
||||
Map<String, String> refMap = new HashMap<>();
|
||||
refMap.put("newcfkey", "value");
|
||||
refMap.put("newcfkey2", "value2");
|
||||
int i = 0;
|
||||
while (rocksIterator.isValid()) {
|
||||
i++;
|
||||
refMap.get(new String(rocksIterator.key())).equals(
|
||||
new String(rocksIterator.value()));
|
||||
assertThat(refMap.get(new String(rocksIterator.key()))).
|
||||
isEqualTo(new String(rocksIterator.value()));
|
||||
rocksIterator.next();
|
||||
}
|
||||
assert(i == 2);
|
||||
assertThat(i).isEqualTo(2);
|
||||
rocksIterator.dispose();
|
||||
} catch(Exception e) {
|
||||
assert(false);
|
||||
} finally {
|
||||
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 {
|
||||
assert(db.getProperty("rocksdb.estimate-num-keys") != null);
|
||||
assert(db.getProperty("rocksdb.stats") != null);
|
||||
assert(db.getProperty(columnFamilyHandleList.get(0),
|
||||
"rocksdb.sstables") != null);
|
||||
assert(db.getProperty(columnFamilyHandleList.get(1),
|
||||
"rocksdb.estimate-num-keys") != null);
|
||||
assert(db.getProperty(columnFamilyHandleList.get(1),
|
||||
"rocksdb.stats") != null);
|
||||
assert(db.getProperty(columnFamilyHandleList.get(1),
|
||||
"rocksdb.sstables") != null);
|
||||
} catch(Exception e) {
|
||||
assert(false);
|
||||
}
|
||||
options = new DBOptions();
|
||||
options.setCreateIfMissing(true);
|
||||
options.setCreateMissingColumnFamilies(true);
|
||||
List<ColumnFamilyDescriptor> cfDescriptors =
|
||||
new ArrayList<>();
|
||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||
new ArrayList<>();
|
||||
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
|
||||
|
||||
// MultiGet test
|
||||
List<ColumnFamilyHandle> cfCustomList = new ArrayList<ColumnFamilyHandle>();
|
||||
try {
|
||||
List<byte[]> keys = new ArrayList<byte[]>();
|
||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||
cfDescriptors, columnFamilyHandleList);
|
||||
db.put(columnFamilyHandleList.get(0), "key".getBytes(), "value".getBytes());
|
||||
db.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(), "value".getBytes());
|
||||
|
||||
List<byte[]> keys = new ArrayList<>();
|
||||
keys.add("key".getBytes());
|
||||
keys.add("newcfkey".getBytes());
|
||||
Map<byte[], byte[]> retValues = db.multiGet(columnFamilyHandleList, keys);
|
||||
assert(retValues.size() == 2);
|
||||
assert(new String(retValues.get(keys.get(0)))
|
||||
.equals("value"));
|
||||
assert(new String(retValues.get(keys.get(1)))
|
||||
.equals("value"));
|
||||
|
||||
cfCustomList.add(columnFamilyHandleList.get(0));
|
||||
cfCustomList.add(columnFamilyHandleList.get(0));
|
||||
retValues = db.multiGet(cfCustomList, keys);
|
||||
assert(retValues.size() == 1);
|
||||
assert(new String(retValues.get(keys.get(0)))
|
||||
.equals("value"));
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
assertThat(retValues.size()).isEqualTo(2);
|
||||
assertThat(new String(retValues.get(keys.get(0))))
|
||||
.isEqualTo("value");
|
||||
assertThat(new String(retValues.get(keys.get(1))))
|
||||
.isEqualTo("value");
|
||||
retValues = db.multiGet(new ReadOptions(), columnFamilyHandleList, keys);
|
||||
assertThat(retValues.size()).isEqualTo(2);
|
||||
assertThat(new String(retValues.get(keys.get(0))))
|
||||
.isEqualTo("value");
|
||||
assertThat(new String(retValues.get(keys.get(1))))
|
||||
.isEqualTo("value");
|
||||
} finally {
|
||||
if (db != null) {
|
||||
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 {
|
||||
List<byte[]> keys = new ArrayList<byte[]>();
|
||||
keys.add("key".getBytes());
|
||||
keys.add("newcfkey".getBytes());
|
||||
cfCustomList.remove(1);
|
||||
db.multiGet(cfCustomList, keys);
|
||||
assert(false);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
assert(true);
|
||||
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);
|
||||
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 {
|
||||
// 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 =
|
||||
db.newIterators(columnFamilyHandleList);
|
||||
assert(iterators.size() == 2);
|
||||
assertThat(iterators.size()).isEqualTo(2);
|
||||
RocksIterator iter = iterators.get(0);
|
||||
iter.seekToFirst();
|
||||
Map<String,String> defRefMap = new HashMap<String, String>();
|
||||
Map<String, String> defRefMap = new HashMap<>();
|
||||
defRefMap.put("dfkey1", "dfvalue");
|
||||
defRefMap.put("key", "value");
|
||||
while (iter.isValid()) {
|
||||
defRefMap.get(new String(iter.key())).equals(
|
||||
new String(iter.value()));
|
||||
assertThat(defRefMap.get(new String(iter.key()))).
|
||||
isEqualTo(new String(iter.value()));
|
||||
iter.next();
|
||||
}
|
||||
// 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("newcfkey2", "value2");
|
||||
iter = iterators.get(1);
|
||||
iter.seekToFirst();
|
||||
while (iter.isValid()) {
|
||||
cfRefMap.get(new String(iter.key())).equals(
|
||||
new String(iter.value()));
|
||||
assertThat(cfRefMap.get(new String(iter.key()))).
|
||||
isEqualTo(new String(iter.value()));
|
||||
iter.next();
|
||||
}
|
||||
// free iterators
|
||||
for (RocksIterator iterator : iterators) {
|
||||
iterator.dispose();
|
||||
}
|
||||
assert(true);
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
// free cf handles before database close
|
||||
for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) {
|
||||
columnFamilyHandle.dispose();
|
||||
}
|
||||
// close database
|
||||
} finally {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
// be sure to dispose c++ pointers
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class FlushTest {
|
||||
|
||||
@ClassRule
|
||||
@ -20,35 +22,44 @@ public class FlushTest {
|
||||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void flush() {
|
||||
public void flush() throws RocksDBException {
|
||||
RocksDB db = null;
|
||||
Options options = new Options();
|
||||
WriteOptions wOpt = new WriteOptions();
|
||||
FlushOptions flushOptions = new FlushOptions();
|
||||
|
||||
Options options = null;
|
||||
WriteOptions wOpt = null;
|
||||
FlushOptions flushOptions = null;
|
||||
try {
|
||||
options = new Options();
|
||||
// Setup options
|
||||
options.setCreateIfMissing(true);
|
||||
options.setMaxWriteBufferNumber(10);
|
||||
options.setMinWriteBufferNumberToMerge(10);
|
||||
wOpt = new WriteOptions();
|
||||
flushOptions = new FlushOptions();
|
||||
flushOptions.setWaitForFlush(true);
|
||||
wOpt.setDisableWAL(true);
|
||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
|
||||
|
||||
db.put(wOpt, "key1".getBytes(), "value1".getBytes());
|
||||
db.put(wOpt, "key2".getBytes(), "value2".getBytes());
|
||||
db.put(wOpt, "key3".getBytes(), "value3".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);
|
||||
assert(db.getProperty("rocksdb.num-entries-active-mem-table").equals("0"));
|
||||
} catch (RocksDBException e) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
db.close();
|
||||
options.dispose();
|
||||
wOpt.dispose();
|
||||
assertThat(db.getProperty("rocksdb.num-entries-active-mem-table")).
|
||||
isEqualTo("0");
|
||||
} finally {
|
||||
if (flushOptions != null) {
|
||||
flushOptions.dispose();
|
||||
}
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
if (options != null) {
|
||||
options.dispose();
|
||||
}
|
||||
if (wOpt != null) {
|
||||
wOpt.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class KeyMayExistTest {
|
||||
.setCreateMissingColumnFamilies(true);
|
||||
// open database using cf names
|
||||
List<ColumnFamilyDescriptor> cfDescriptors =
|
||||
new ArrayList<ColumnFamilyDescriptor>();
|
||||
new ArrayList<>();
|
||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||
new ArrayList<>();
|
||||
cfDescriptors.add(new ColumnFamilyDescriptor("default"));
|
||||
|
@ -177,11 +177,12 @@ public class MergeTest {
|
||||
|
||||
// Test also with createColumnFamily
|
||||
columnFamilyHandle = db.createColumnFamily(
|
||||
new ColumnFamilyDescriptor("new_cf2"));
|
||||
new ColumnFamilyDescriptor("new_cf2",
|
||||
new ColumnFamilyOptions().setMergeOperator(stringAppendOperator)));
|
||||
// writing xx under cfkey2
|
||||
db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes());
|
||||
// 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());
|
||||
String strValueTmpCf = new String(value);
|
||||
|
||||
|
@ -5,26 +5,33 @@
|
||||
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MixedOptionsTest {
|
||||
static {
|
||||
RocksDB.loadLibrary();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@Test
|
||||
public void mixedOptionsTest(){
|
||||
// Set a table factory and check the names
|
||||
ColumnFamilyOptions cfOptions = new ColumnFamilyOptions();
|
||||
cfOptions.setTableFormatConfig(new BlockBasedTableConfig().
|
||||
setFilter(new BloomFilter()));
|
||||
assert(cfOptions.tableFactoryName().equals(
|
||||
"BlockBasedTable"));
|
||||
assertThat(cfOptions.tableFactoryName()).isEqualTo(
|
||||
"BlockBasedTable");
|
||||
cfOptions.setTableFormatConfig(new PlainTableConfig());
|
||||
assert(cfOptions.tableFactoryName().equals("PlainTable"));
|
||||
assertThat(cfOptions.tableFactoryName()).isEqualTo("PlainTable");
|
||||
// Initialize a dbOptions object from cf options and
|
||||
// db options
|
||||
DBOptions dbOptions = new DBOptions();
|
||||
Options options = new Options(dbOptions, cfOptions);
|
||||
assert(options.tableFactoryName().equals("PlainTable"));
|
||||
assertThat(options.tableFactoryName()).isEqualTo("PlainTable");
|
||||
// Free instances
|
||||
options.dispose();
|
||||
options = null;
|
||||
|
@ -23,196 +23,463 @@ public class OptionsTest {
|
||||
getPlatformSpecificRandomFactory();
|
||||
|
||||
@Test
|
||||
public void options() throws RocksDBException {
|
||||
public void writeBufferSize() throws RocksDBException {
|
||||
Options opt = null;
|
||||
try {
|
||||
opt = new Options();
|
||||
|
||||
{ // WriteBufferSize test
|
||||
long longValue = rand.nextLong();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
opt = new Options();
|
||||
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();
|
||||
opt = new Options();
|
||||
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();
|
||||
opt = new Options();
|
||||
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();
|
||||
opt = new Options();
|
||||
opt.setMinPartialMergeOperands(intValue);
|
||||
assert (opt.minPartialMergeOperands() == intValue);
|
||||
}
|
||||
assertThat(opt.minPartialMergeOperands()).isEqualTo(intValue);
|
||||
} finally {
|
||||
if (opt != null) {
|
||||
opt.dispose();
|
||||
|
@ -75,10 +75,10 @@ public class WriteBatchHandlerTest {
|
||||
|
||||
// compare the results to the test data
|
||||
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++) {
|
||||
assert(equals(testEvents.get(i), actualEvents.get(i)));
|
||||
assertThat(equals(testEvents.get(i), actualEvents.get(i))).isTrue();
|
||||
}
|
||||
|
||||
System.out.println("Passed WriteBatchHandler Test");
|
||||
|
Loading…
Reference in New Issue
Block a user