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