[RocksJava] Improved tests within RocksJava
This commit is contained in:
parent
628e39e97d
commit
74057d6d2d
@ -66,6 +66,7 @@ JAVA_TESTS = org.rocksdb.test.AbstractComparatorTest\
|
|||||||
org.rocksdb.test.PlainTableConfigTest\
|
org.rocksdb.test.PlainTableConfigTest\
|
||||||
org.rocksdb.test.ReadOnlyTest\
|
org.rocksdb.test.ReadOnlyTest\
|
||||||
org.rocksdb.test.ReadOptionsTest\
|
org.rocksdb.test.ReadOptionsTest\
|
||||||
|
org.rocksdb.test.RocksDBTest\
|
||||||
org.rocksdb.test.RocksEnvTest\
|
org.rocksdb.test.RocksEnvTest\
|
||||||
org.rocksdb.test.RocksIteratorTest\
|
org.rocksdb.test.RocksIteratorTest\
|
||||||
org.rocksdb.test.SnapshotTest\
|
org.rocksdb.test.SnapshotTest\
|
||||||
|
@ -103,6 +103,7 @@ public class RocksDB extends RocksObject {
|
|||||||
// This allows to use the rocksjni default Options instead of
|
// This allows to use the rocksjni default Options instead of
|
||||||
// the c++ one.
|
// the c++ one.
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
options.setCreateIfMissing(true);
|
||||||
return open(options, path);
|
return open(options, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ public class RocksEnv extends RocksObject {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
default_env_ = new RocksEnv(getDefaultEnvInternal());
|
default_env_ = new RocksEnv(getDefaultEnvInternal());
|
||||||
|
|
||||||
}
|
}
|
||||||
private static native long getDefaultEnvInternal();
|
private static native long getDefaultEnvInternal();
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ public class RocksEnv extends RocksObject {
|
|||||||
* {@link RocksObject} must implement to release their associated C++
|
* {@link RocksObject} must implement to release their associated C++
|
||||||
* resource.
|
* resource.
|
||||||
*/
|
*/
|
||||||
protected void disposeInternal() {
|
@Override protected void disposeInternal() {
|
||||||
disposeInternal(nativeHandle_);
|
disposeInternal(nativeHandle_);
|
||||||
}
|
}
|
||||||
private native void disposeInternal(long handle);
|
private native void disposeInternal(long handle);
|
||||||
|
@ -18,65 +18,145 @@ public class BlockBasedTableConfigTest {
|
|||||||
new RocksMemoryResource();
|
new RocksMemoryResource();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void blockBasedTableConfig() {
|
public void noBlockCache() {
|
||||||
BlockBasedTableConfig blockBasedTableConfig =
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
new BlockBasedTableConfig();
|
|
||||||
blockBasedTableConfig.setNoBlockCache(true);
|
blockBasedTableConfig.setNoBlockCache(true);
|
||||||
assertThat(blockBasedTableConfig.noBlockCache()).isTrue();
|
assertThat(blockBasedTableConfig.noBlockCache()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockCacheSize() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setBlockCacheSize(8 * 1024);
|
blockBasedTableConfig.setBlockCacheSize(8 * 1024);
|
||||||
assertThat(blockBasedTableConfig.blockCacheSize()).
|
assertThat(blockBasedTableConfig.blockCacheSize()).
|
||||||
isEqualTo(8 * 1024);
|
isEqualTo(8 * 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockSizeDeviation() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setBlockSizeDeviation(12);
|
blockBasedTableConfig.setBlockSizeDeviation(12);
|
||||||
assertThat(blockBasedTableConfig.blockSizeDeviation()).
|
assertThat(blockBasedTableConfig.blockSizeDeviation()).
|
||||||
isEqualTo(12);
|
isEqualTo(12);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockRestartInterval() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setBlockRestartInterval(15);
|
blockBasedTableConfig.setBlockRestartInterval(15);
|
||||||
assertThat(blockBasedTableConfig.blockRestartInterval()).
|
assertThat(blockBasedTableConfig.blockRestartInterval()).
|
||||||
isEqualTo(15);
|
isEqualTo(15);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void wholeKeyFiltering() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setWholeKeyFiltering(false);
|
blockBasedTableConfig.setWholeKeyFiltering(false);
|
||||||
assertThat(blockBasedTableConfig.wholeKeyFiltering()).
|
assertThat(blockBasedTableConfig.wholeKeyFiltering()).
|
||||||
isFalse();
|
isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cacheIndexAndFilterBlocks() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setCacheIndexAndFilterBlocks(true);
|
blockBasedTableConfig.setCacheIndexAndFilterBlocks(true);
|
||||||
assertThat(blockBasedTableConfig.cacheIndexAndFilterBlocks()).
|
assertThat(blockBasedTableConfig.cacheIndexAndFilterBlocks()).
|
||||||
isTrue();
|
isTrue();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hashIndexAllowCollision() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setHashIndexAllowCollision(false);
|
blockBasedTableConfig.setHashIndexAllowCollision(false);
|
||||||
assertThat(blockBasedTableConfig.hashIndexAllowCollision()).
|
assertThat(blockBasedTableConfig.hashIndexAllowCollision()).
|
||||||
isFalse();
|
isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockCacheCompressedSize() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setBlockCacheCompressedSize(40);
|
blockBasedTableConfig.setBlockCacheCompressedSize(40);
|
||||||
assertThat(blockBasedTableConfig.blockCacheCompressedSize()).
|
assertThat(blockBasedTableConfig.blockCacheCompressedSize()).
|
||||||
isEqualTo(40);
|
isEqualTo(40);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checksumType() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setChecksumType(ChecksumType.kNoChecksum);
|
blockBasedTableConfig.setChecksumType(ChecksumType.kNoChecksum);
|
||||||
blockBasedTableConfig.setChecksumType(ChecksumType.kxxHash);
|
blockBasedTableConfig.setChecksumType(ChecksumType.kxxHash);
|
||||||
assertThat(blockBasedTableConfig.checksumType().equals(
|
assertThat(blockBasedTableConfig.checksumType().equals(
|
||||||
ChecksumType.kxxHash));
|
ChecksumType.kxxHash));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void indexType() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
|
assertThat(IndexType.values().length).isEqualTo(2);
|
||||||
blockBasedTableConfig.setIndexType(IndexType.kHashSearch);
|
blockBasedTableConfig.setIndexType(IndexType.kHashSearch);
|
||||||
assertThat(blockBasedTableConfig.indexType().equals(
|
assertThat(blockBasedTableConfig.indexType().equals(
|
||||||
IndexType.kHashSearch));
|
IndexType.kHashSearch));
|
||||||
|
assertThat(IndexType.valueOf("kBinarySearch")).isNotNull();
|
||||||
|
blockBasedTableConfig.setIndexType(IndexType.valueOf("kBinarySearch"));
|
||||||
|
assertThat(blockBasedTableConfig.indexType().equals(
|
||||||
|
IndexType.kBinarySearch));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockCacheCompressedNumShardBits() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setBlockCacheCompressedNumShardBits(4);
|
blockBasedTableConfig.setBlockCacheCompressedNumShardBits(4);
|
||||||
assertThat(blockBasedTableConfig.blockCacheCompressedNumShardBits()).
|
assertThat(blockBasedTableConfig.blockCacheCompressedNumShardBits()).
|
||||||
isEqualTo(4);
|
isEqualTo(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cacheNumShardBits() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setCacheNumShardBits(5);
|
blockBasedTableConfig.setCacheNumShardBits(5);
|
||||||
assertThat(blockBasedTableConfig.cacheNumShardBits()).
|
assertThat(blockBasedTableConfig.cacheNumShardBits()).
|
||||||
isEqualTo(5);
|
isEqualTo(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockSize() {
|
||||||
|
BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
|
||||||
blockBasedTableConfig.setBlockSize(10);
|
blockBasedTableConfig.setBlockSize(10);
|
||||||
assertThat(blockBasedTableConfig.blockSize()).isEqualTo(10);
|
assertThat(blockBasedTableConfig.blockSize()).isEqualTo(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void blockBasedTableWithFilter() {
|
public void blockBasedTableWithFilter() {
|
||||||
Options options = new Options();
|
Options options = null;
|
||||||
options.setTableFormatConfig(
|
try {
|
||||||
new BlockBasedTableConfig().setFilter(
|
options = new Options();
|
||||||
new BloomFilter(10)));
|
options.setTableFormatConfig(
|
||||||
assertThat(options.tableFactoryName()).
|
new BlockBasedTableConfig().setFilter(
|
||||||
isEqualTo("BlockBasedTable");
|
new BloomFilter(10)));
|
||||||
|
assertThat(options.tableFactoryName()).
|
||||||
|
isEqualTo("BlockBasedTable");
|
||||||
|
} finally {
|
||||||
|
if (options != null) {
|
||||||
|
options.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void blockBasedTableWithoutFilter() {
|
public void blockBasedTableWithoutFilter() {
|
||||||
Options options = new Options();
|
Options options = null;
|
||||||
options.setTableFormatConfig(
|
try {
|
||||||
new BlockBasedTableConfig().setFilter(null));
|
options = new Options();
|
||||||
assertThat(options.tableFactoryName()).
|
options.setTableFormatConfig(
|
||||||
isEqualTo("BlockBasedTable");
|
new BlockBasedTableConfig().setFilter(null));
|
||||||
|
assertThat(options.tableFactoryName()).
|
||||||
|
isEqualTo("BlockBasedTable");
|
||||||
|
} finally {
|
||||||
|
if (options != null) {
|
||||||
|
options.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,227 +19,508 @@ public class DBOptionsTest {
|
|||||||
public static final RocksMemoryResource rocksMemoryResource =
|
public static final RocksMemoryResource rocksMemoryResource =
|
||||||
new RocksMemoryResource();
|
new RocksMemoryResource();
|
||||||
|
|
||||||
@Test
|
public static final Random rand = PlatformRandomHelper.
|
||||||
public void dbOptions() throws RocksDBException {
|
getPlatformSpecificRandomFactory();
|
||||||
testDBOptions(new DBOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void testDBOptions(DBOptionsInterface opt) throws RocksDBException {
|
@Test
|
||||||
Random rand = PlatformRandomHelper.
|
public void createIfMissing() {
|
||||||
getPlatformSpecificRandomFactory();
|
DBOptions opt = null;
|
||||||
{ // CreateIfMissing test
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setCreateIfMissing(boolValue);
|
opt.setCreateIfMissing(boolValue);
|
||||||
assertThat(opt.createIfMissing()).
|
assertThat(opt.createIfMissing()).
|
||||||
isEqualTo(boolValue);
|
isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // CreateMissingColumnFamilies test
|
@Test
|
||||||
|
public void createMissingColumnFamilies() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setCreateMissingColumnFamilies(boolValue);
|
opt.setCreateMissingColumnFamilies(boolValue);
|
||||||
assertThat(opt.createMissingColumnFamilies()).
|
assertThat(opt.createMissingColumnFamilies()).
|
||||||
isEqualTo(boolValue);
|
isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // ErrorIfExists test
|
@Test
|
||||||
|
public void errorIfExists() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setErrorIfExists(boolValue);
|
opt.setErrorIfExists(boolValue);
|
||||||
assertThat(opt.errorIfExists()).isEqualTo(boolValue);
|
assertThat(opt.errorIfExists()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // ParanoidChecks test
|
@Test
|
||||||
|
public void paranoidChecks() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setParanoidChecks(boolValue);
|
opt.setParanoidChecks(boolValue);
|
||||||
assertThat(opt.paranoidChecks()).
|
assertThat(opt.paranoidChecks()).
|
||||||
isEqualTo(boolValue);
|
isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
@Test
|
||||||
// MaxTotalWalSize test
|
public void maxTotalWalSize() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setMaxTotalWalSize(longValue);
|
opt.setMaxTotalWalSize(longValue);
|
||||||
assertThat(opt.maxTotalWalSize()).
|
assertThat(opt.maxTotalWalSize()).
|
||||||
isEqualTo(longValue);
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // MaxOpenFiles test
|
@Test
|
||||||
|
public void maxOpenFiles() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
int intValue = rand.nextInt();
|
int intValue = rand.nextInt();
|
||||||
opt.setMaxOpenFiles(intValue);
|
opt.setMaxOpenFiles(intValue);
|
||||||
assertThat(opt.maxOpenFiles()).isEqualTo(intValue);
|
assertThat(opt.maxOpenFiles()).isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // DisableDataSync test
|
@Test
|
||||||
|
public void disableDataSync() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setDisableDataSync(boolValue);
|
opt.setDisableDataSync(boolValue);
|
||||||
assertThat(opt.disableDataSync()).
|
assertThat(opt.disableDataSync()).
|
||||||
isEqualTo(boolValue);
|
isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // UseFsync test
|
@Test
|
||||||
|
public void useFsync() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setUseFsync(boolValue);
|
opt.setUseFsync(boolValue);
|
||||||
assertThat(opt.useFsync()).isEqualTo(boolValue);
|
assertThat(opt.useFsync()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // DbLogDir test
|
@Test
|
||||||
|
public void dbLogDir() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
String str = "path/to/DbLogDir";
|
String str = "path/to/DbLogDir";
|
||||||
opt.setDbLogDir(str);
|
opt.setDbLogDir(str);
|
||||||
assertThat(opt.dbLogDir()).isEqualTo(str);
|
assertThat(opt.dbLogDir()).isEqualTo(str);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // WalDir test
|
@Test
|
||||||
|
public void walDir() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
String str = "path/to/WalDir";
|
String str = "path/to/WalDir";
|
||||||
opt.setWalDir(str);
|
opt.setWalDir(str);
|
||||||
assertThat(opt.walDir()).isEqualTo(str);
|
assertThat(opt.walDir()).isEqualTo(str);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // DeleteObsoleteFilesPeriodMicros test
|
@Test
|
||||||
|
public void deleteObsoleteFilesPeriodMicros() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setDeleteObsoleteFilesPeriodMicros(longValue);
|
opt.setDeleteObsoleteFilesPeriodMicros(longValue);
|
||||||
assertThat(opt.deleteObsoleteFilesPeriodMicros()).
|
assertThat(opt.deleteObsoleteFilesPeriodMicros()).
|
||||||
isEqualTo(longValue);
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // MaxBackgroundCompactions test
|
@Test
|
||||||
|
public void maxBackgroundCompactions() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
int intValue = rand.nextInt();
|
int intValue = rand.nextInt();
|
||||||
opt.setMaxBackgroundCompactions(intValue);
|
opt.setMaxBackgroundCompactions(intValue);
|
||||||
assertThat(opt.maxBackgroundCompactions()).
|
assertThat(opt.maxBackgroundCompactions()).
|
||||||
isEqualTo(intValue);
|
isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // MaxBackgroundFlushes test
|
@Test
|
||||||
|
public void maxBackgroundFlushes() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
int intValue = rand.nextInt();
|
int intValue = rand.nextInt();
|
||||||
opt.setMaxBackgroundFlushes(intValue);
|
opt.setMaxBackgroundFlushes(intValue);
|
||||||
assertThat(opt.maxBackgroundFlushes()).
|
assertThat(opt.maxBackgroundFlushes()).
|
||||||
isEqualTo(intValue);
|
isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // MaxLogFileSize test
|
@Test
|
||||||
|
public void maxLogFileSize() throws RocksDBException {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setMaxLogFileSize(longValue);
|
opt.setMaxLogFileSize(longValue);
|
||||||
assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
|
assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // LogFileTimeToRoll test
|
@Test
|
||||||
|
public void logFileTimeToRoll() throws RocksDBException {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setLogFileTimeToRoll(longValue);
|
opt.setLogFileTimeToRoll(longValue);
|
||||||
assertThat(opt.logFileTimeToRoll()).
|
assertThat(opt.logFileTimeToRoll()).
|
||||||
isEqualTo(longValue);
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // KeepLogFileNum test
|
@Test
|
||||||
|
public void keepLogFileNum() throws RocksDBException {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setKeepLogFileNum(longValue);
|
opt.setKeepLogFileNum(longValue);
|
||||||
assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
|
assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // MaxManifestFileSize test
|
@Test
|
||||||
|
public void maxManifestFileSize() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setMaxManifestFileSize(longValue);
|
opt.setMaxManifestFileSize(longValue);
|
||||||
assertThat(opt.maxManifestFileSize()).
|
assertThat(opt.maxManifestFileSize()).
|
||||||
isEqualTo(longValue);
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // TableCacheNumshardbits test
|
@Test
|
||||||
|
public void tableCacheNumshardbits() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
int intValue = rand.nextInt();
|
int intValue = rand.nextInt();
|
||||||
opt.setTableCacheNumshardbits(intValue);
|
opt.setTableCacheNumshardbits(intValue);
|
||||||
assertThat(opt.tableCacheNumshardbits()).
|
assertThat(opt.tableCacheNumshardbits()).
|
||||||
isEqualTo(intValue);
|
isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // TableCacheRemoveScanCountLimit test
|
@Test
|
||||||
|
public void tableCacheRemoveScanCountLimit() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
int intValue = rand.nextInt();
|
int intValue = rand.nextInt();
|
||||||
opt.setTableCacheRemoveScanCountLimit(intValue);
|
opt.setTableCacheRemoveScanCountLimit(intValue);
|
||||||
assertThat(opt.tableCacheRemoveScanCountLimit()).
|
assertThat(opt.tableCacheRemoveScanCountLimit()).
|
||||||
isEqualTo(intValue);
|
isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // WalSizeLimitMB test
|
@Test
|
||||||
|
public void walSizeLimitMB() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setWalSizeLimitMB(longValue);
|
opt.setWalSizeLimitMB(longValue);
|
||||||
assertThat(opt.walSizeLimitMB()).isEqualTo(longValue);
|
assertThat(opt.walSizeLimitMB()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // WalTtlSeconds test
|
@Test
|
||||||
|
public void walTtlSeconds() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setWalTtlSeconds(longValue);
|
opt.setWalTtlSeconds(longValue);
|
||||||
assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
|
assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // ManifestPreallocationSize test
|
@Test
|
||||||
|
public void manifestPreallocationSize() throws RocksDBException {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setManifestPreallocationSize(longValue);
|
opt.setManifestPreallocationSize(longValue);
|
||||||
assertThat(opt.manifestPreallocationSize()).
|
assertThat(opt.manifestPreallocationSize()).
|
||||||
isEqualTo(longValue);
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // AllowOsBuffer test
|
@Test
|
||||||
|
public void allowOsBuffer() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setAllowOsBuffer(boolValue);
|
opt.setAllowOsBuffer(boolValue);
|
||||||
assertThat(opt.allowOsBuffer()).isEqualTo(boolValue);
|
assertThat(opt.allowOsBuffer()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // AllowMmapReads test
|
@Test
|
||||||
|
public void allowMmapReads() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setAllowMmapReads(boolValue);
|
opt.setAllowMmapReads(boolValue);
|
||||||
assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
|
assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // AllowMmapWrites test
|
@Test
|
||||||
|
public void allowMmapWrites() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setAllowMmapWrites(boolValue);
|
opt.setAllowMmapWrites(boolValue);
|
||||||
assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
|
assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // IsFdCloseOnExec test
|
@Test
|
||||||
|
public void isFdCloseOnExec() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setIsFdCloseOnExec(boolValue);
|
opt.setIsFdCloseOnExec(boolValue);
|
||||||
assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
|
assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // SkipLogErrorOnRecovery test
|
@Test
|
||||||
|
public void skipLogErrorOnRecovery() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setSkipLogErrorOnRecovery(boolValue);
|
opt.setSkipLogErrorOnRecovery(boolValue);
|
||||||
assertThat(opt.skipLogErrorOnRecovery()).isEqualTo(boolValue);
|
assertThat(opt.skipLogErrorOnRecovery()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // StatsDumpPeriodSec test
|
@Test
|
||||||
|
public void statsDumpPeriodSec() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
int intValue = rand.nextInt();
|
int intValue = rand.nextInt();
|
||||||
opt.setStatsDumpPeriodSec(intValue);
|
opt.setStatsDumpPeriodSec(intValue);
|
||||||
assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
|
assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // AdviseRandomOnOpen test
|
@Test
|
||||||
|
public void adviseRandomOnOpen() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setAdviseRandomOnOpen(boolValue);
|
opt.setAdviseRandomOnOpen(boolValue);
|
||||||
assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
|
assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // UseAdaptiveMutex test
|
@Test
|
||||||
|
public void useAdaptiveMutex() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
boolean boolValue = rand.nextBoolean();
|
boolean boolValue = rand.nextBoolean();
|
||||||
opt.setUseAdaptiveMutex(boolValue);
|
opt.setUseAdaptiveMutex(boolValue);
|
||||||
assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
|
assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // BytesPerSync test
|
@Test
|
||||||
|
public void bytesPerSync() {
|
||||||
|
DBOptions opt = null;
|
||||||
|
try {
|
||||||
|
opt = new DBOptions();
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
opt.setBytesPerSync(longValue);
|
opt.setBytesPerSync(longValue);
|
||||||
assertThat(opt.bytesPerSync()).isEqualTo(longValue);
|
assertThat(opt.bytesPerSync()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rateLimiterConfig() {
|
public void rateLimiterConfig() {
|
||||||
DBOptions options = new DBOptions();
|
DBOptions options = null;
|
||||||
RateLimiterConfig rateLimiterConfig =
|
DBOptions anotherOptions = null;
|
||||||
new GenericRateLimiterConfig(1000, 0, 1);
|
try {
|
||||||
options.setRateLimiterConfig(rateLimiterConfig);
|
options = new DBOptions();
|
||||||
options.dispose();
|
RateLimiterConfig rateLimiterConfig =
|
||||||
// Test with parameter initialization
|
new GenericRateLimiterConfig(1000, 0, 1);
|
||||||
DBOptions anotherOptions = new DBOptions();
|
options.setRateLimiterConfig(rateLimiterConfig);
|
||||||
anotherOptions.setRateLimiterConfig(
|
// Test with parameter initialization
|
||||||
new GenericRateLimiterConfig(1000));
|
anotherOptions = new DBOptions();
|
||||||
anotherOptions.dispose();
|
anotherOptions.setRateLimiterConfig(
|
||||||
|
new GenericRateLimiterConfig(1000));
|
||||||
|
} finally {
|
||||||
|
if (options != null) {
|
||||||
|
options.dispose();
|
||||||
|
}
|
||||||
|
if (anotherOptions != null) {
|
||||||
|
anotherOptions.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
package org.rocksdb.test;
|
package org.rocksdb.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -17,6 +21,7 @@ public class EnvironmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void mac32() {
|
public void mac32() {
|
||||||
setEnvironmentClassFields("mac", "32");
|
setEnvironmentClassFields("mac", "32");
|
||||||
|
assertThat(Environment.isWindows()).isFalse();
|
||||||
assertThat(Environment.getJniLibraryExtension()).
|
assertThat(Environment.getJniLibraryExtension()).
|
||||||
isEqualTo(".jnilib");
|
isEqualTo(".jnilib");
|
||||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||||
@ -28,6 +33,7 @@ public class EnvironmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void mac64() {
|
public void mac64() {
|
||||||
setEnvironmentClassFields("mac", "64");
|
setEnvironmentClassFields("mac", "64");
|
||||||
|
assertThat(Environment.isWindows()).isFalse();
|
||||||
assertThat(Environment.getJniLibraryExtension()).
|
assertThat(Environment.getJniLibraryExtension()).
|
||||||
isEqualTo(".jnilib");
|
isEqualTo(".jnilib");
|
||||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||||
@ -40,6 +46,7 @@ public class EnvironmentTest {
|
|||||||
public void nix32() {
|
public void nix32() {
|
||||||
// Linux
|
// Linux
|
||||||
setEnvironmentClassFields("Linux", "32");
|
setEnvironmentClassFields("Linux", "32");
|
||||||
|
assertThat(Environment.isWindows()).isFalse();
|
||||||
assertThat(Environment.getJniLibraryExtension()).
|
assertThat(Environment.getJniLibraryExtension()).
|
||||||
isEqualTo(".so");
|
isEqualTo(".so");
|
||||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||||
@ -48,6 +55,7 @@ public class EnvironmentTest {
|
|||||||
isEqualTo("librocksdbjni.so");
|
isEqualTo("librocksdbjni.so");
|
||||||
// UNIX
|
// UNIX
|
||||||
setEnvironmentClassFields("Unix", "32");
|
setEnvironmentClassFields("Unix", "32");
|
||||||
|
assertThat(Environment.isWindows()).isFalse();
|
||||||
assertThat(Environment.getJniLibraryExtension()).
|
assertThat(Environment.getJniLibraryExtension()).
|
||||||
isEqualTo(".so");
|
isEqualTo(".so");
|
||||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||||
@ -56,6 +64,7 @@ public class EnvironmentTest {
|
|||||||
isEqualTo("librocksdbjni.so");
|
isEqualTo("librocksdbjni.so");
|
||||||
// AIX
|
// AIX
|
||||||
setEnvironmentClassFields("aix", "32");
|
setEnvironmentClassFields("aix", "32");
|
||||||
|
assertThat(Environment.isWindows()).isFalse();
|
||||||
assertThat(Environment.getJniLibraryExtension()).
|
assertThat(Environment.getJniLibraryExtension()).
|
||||||
isEqualTo(".so");
|
isEqualTo(".so");
|
||||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||||
@ -67,6 +76,7 @@ public class EnvironmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void nix64() {
|
public void nix64() {
|
||||||
setEnvironmentClassFields("Linux", "x64");
|
setEnvironmentClassFields("Linux", "x64");
|
||||||
|
assertThat(Environment.isWindows()).isFalse();
|
||||||
assertThat(Environment.getJniLibraryExtension()).
|
assertThat(Environment.getJniLibraryExtension()).
|
||||||
isEqualTo(".so");
|
isEqualTo(".so");
|
||||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||||
@ -75,6 +85,7 @@ public class EnvironmentTest {
|
|||||||
isEqualTo("librocksdbjni.so");
|
isEqualTo("librocksdbjni.so");
|
||||||
// UNIX
|
// UNIX
|
||||||
setEnvironmentClassFields("Unix", "x64");
|
setEnvironmentClassFields("Unix", "x64");
|
||||||
|
assertThat(Environment.isWindows()).isFalse();
|
||||||
assertThat(Environment.getJniLibraryExtension()).
|
assertThat(Environment.getJniLibraryExtension()).
|
||||||
isEqualTo(".so");
|
isEqualTo(".so");
|
||||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||||
@ -83,6 +94,7 @@ public class EnvironmentTest {
|
|||||||
isEqualTo("librocksdbjni.so");
|
isEqualTo("librocksdbjni.so");
|
||||||
// AIX
|
// AIX
|
||||||
setEnvironmentClassFields("aix", "x64");
|
setEnvironmentClassFields("aix", "x64");
|
||||||
|
assertThat(Environment.isWindows()).isFalse();
|
||||||
assertThat(Environment.getJniLibraryExtension()).
|
assertThat(Environment.getJniLibraryExtension()).
|
||||||
isEqualTo(".so");
|
isEqualTo(".so");
|
||||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||||
@ -91,8 +103,14 @@ public class EnvironmentTest {
|
|||||||
isEqualTo("librocksdbjni.so");
|
isEqualTo("librocksdbjni.so");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void detectWindows(){
|
||||||
|
setEnvironmentClassFields("win", "x64");
|
||||||
|
assertThat(Environment.isWindows()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = UnsupportedOperationException.class)
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
public void failLinuxJniLibraryName(){
|
public void failWinJniLibraryName(){
|
||||||
setEnvironmentClassFields("win", "x64");
|
setEnvironmentClassFields("win", "x64");
|
||||||
Environment.getJniLibraryName("rocksdb");
|
Environment.getJniLibraryName("rocksdb");
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@ public class OptionsTest {
|
|||||||
public static final RocksMemoryResource rocksMemoryResource =
|
public static final RocksMemoryResource rocksMemoryResource =
|
||||||
new RocksMemoryResource();
|
new RocksMemoryResource();
|
||||||
|
|
||||||
|
public static final Random rand = PlatformRandomHelper.
|
||||||
|
getPlatformSpecificRandomFactory();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void options() throws RocksDBException {
|
public void options() throws RocksDBException {
|
||||||
Options opt = null;
|
Options opt = null;
|
||||||
try {
|
try {
|
||||||
opt = new Options();
|
opt = new Options();
|
||||||
Random rand = PlatformRandomHelper.
|
|
||||||
getPlatformSpecificRandomFactory();
|
|
||||||
DBOptionsTest.testDBOptions(opt);
|
|
||||||
|
|
||||||
{ // WriteBufferSize test
|
{ // WriteBufferSize test
|
||||||
long longValue = rand.nextLong();
|
long longValue = rand.nextLong();
|
||||||
@ -220,6 +220,484 @@ public class OptionsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createIfMissing() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setCreateIfMissing(boolValue);
|
||||||
|
assertThat(opt.createIfMissing()).
|
||||||
|
isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createMissingColumnFamilies() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setCreateMissingColumnFamilies(boolValue);
|
||||||
|
assertThat(opt.createMissingColumnFamilies()).
|
||||||
|
isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void errorIfExists() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setErrorIfExists(boolValue);
|
||||||
|
assertThat(opt.errorIfExists()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void paranoidChecks() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setParanoidChecks(boolValue);
|
||||||
|
assertThat(opt.paranoidChecks()).
|
||||||
|
isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void maxTotalWalSize() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setMaxTotalWalSize(longValue);
|
||||||
|
assertThat(opt.maxTotalWalSize()).
|
||||||
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void maxOpenFiles() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
int intValue = rand.nextInt();
|
||||||
|
opt.setMaxOpenFiles(intValue);
|
||||||
|
assertThat(opt.maxOpenFiles()).isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void disableDataSync() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setDisableDataSync(boolValue);
|
||||||
|
assertThat(opt.disableDataSync()).
|
||||||
|
isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void useFsync() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setUseFsync(boolValue);
|
||||||
|
assertThat(opt.useFsync()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dbLogDir() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
String str = "path/to/DbLogDir";
|
||||||
|
opt.setDbLogDir(str);
|
||||||
|
assertThat(opt.dbLogDir()).isEqualTo(str);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void walDir() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
String str = "path/to/WalDir";
|
||||||
|
opt.setWalDir(str);
|
||||||
|
assertThat(opt.walDir()).isEqualTo(str);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteObsoleteFilesPeriodMicros() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setDeleteObsoleteFilesPeriodMicros(longValue);
|
||||||
|
assertThat(opt.deleteObsoleteFilesPeriodMicros()).
|
||||||
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void maxBackgroundCompactions() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
int intValue = rand.nextInt();
|
||||||
|
opt.setMaxBackgroundCompactions(intValue);
|
||||||
|
assertThat(opt.maxBackgroundCompactions()).
|
||||||
|
isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void maxBackgroundFlushes() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
int intValue = rand.nextInt();
|
||||||
|
opt.setMaxBackgroundFlushes(intValue);
|
||||||
|
assertThat(opt.maxBackgroundFlushes()).
|
||||||
|
isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void maxLogFileSize() throws RocksDBException {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setMaxLogFileSize(longValue);
|
||||||
|
assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void logFileTimeToRoll() throws RocksDBException {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setLogFileTimeToRoll(longValue);
|
||||||
|
assertThat(opt.logFileTimeToRoll()).
|
||||||
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void keepLogFileNum() throws RocksDBException {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setKeepLogFileNum(longValue);
|
||||||
|
assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void maxManifestFileSize() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setMaxManifestFileSize(longValue);
|
||||||
|
assertThat(opt.maxManifestFileSize()).
|
||||||
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tableCacheNumshardbits() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
int intValue = rand.nextInt();
|
||||||
|
opt.setTableCacheNumshardbits(intValue);
|
||||||
|
assertThat(opt.tableCacheNumshardbits()).
|
||||||
|
isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tableCacheRemoveScanCountLimit() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
int intValue = rand.nextInt();
|
||||||
|
opt.setTableCacheRemoveScanCountLimit(intValue);
|
||||||
|
assertThat(opt.tableCacheRemoveScanCountLimit()).
|
||||||
|
isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void walSizeLimitMB() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setWalSizeLimitMB(longValue);
|
||||||
|
assertThat(opt.walSizeLimitMB()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void walTtlSeconds() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setWalTtlSeconds(longValue);
|
||||||
|
assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void manifestPreallocationSize() throws RocksDBException {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setManifestPreallocationSize(longValue);
|
||||||
|
assertThat(opt.manifestPreallocationSize()).
|
||||||
|
isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void allowOsBuffer() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setAllowOsBuffer(boolValue);
|
||||||
|
assertThat(opt.allowOsBuffer()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void allowMmapReads() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setAllowMmapReads(boolValue);
|
||||||
|
assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void allowMmapWrites() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setAllowMmapWrites(boolValue);
|
||||||
|
assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isFdCloseOnExec() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setIsFdCloseOnExec(boolValue);
|
||||||
|
assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void skipLogErrorOnRecovery() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setSkipLogErrorOnRecovery(boolValue);
|
||||||
|
assertThat(opt.skipLogErrorOnRecovery()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void statsDumpPeriodSec() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
int intValue = rand.nextInt();
|
||||||
|
opt.setStatsDumpPeriodSec(intValue);
|
||||||
|
assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void adviseRandomOnOpen() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setAdviseRandomOnOpen(boolValue);
|
||||||
|
assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void useAdaptiveMutex() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
boolean boolValue = rand.nextBoolean();
|
||||||
|
opt.setUseAdaptiveMutex(boolValue);
|
||||||
|
assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bytesPerSync() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
long longValue = rand.nextLong();
|
||||||
|
opt.setBytesPerSync(longValue);
|
||||||
|
assertThat(opt.bytesPerSync()).isEqualTo(longValue);
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rocksEnv() {
|
public void rocksEnv() {
|
||||||
Options options = null;
|
Options options = null;
|
||||||
@ -263,6 +741,8 @@ public class OptionsTest {
|
|||||||
options.setCompressionType(compressionType);
|
options.setCompressionType(compressionType);
|
||||||
assertThat(options.compressionType()).
|
assertThat(options.compressionType()).
|
||||||
isEqualTo(compressionType);
|
isEqualTo(compressionType);
|
||||||
|
assertThat(CompressionType.valueOf("NO_COMPRESSION")).
|
||||||
|
isEqualTo(CompressionType.NO_COMPRESSION);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
@ -281,6 +761,8 @@ public class OptionsTest {
|
|||||||
options.setCompactionStyle(compactionStyle);
|
options.setCompactionStyle(compactionStyle);
|
||||||
assertThat(options.compactionStyle()).
|
assertThat(options.compactionStyle()).
|
||||||
isEqualTo(compactionStyle);
|
isEqualTo(compactionStyle);
|
||||||
|
assertThat(CompactionStyle.valueOf("FIFO")).
|
||||||
|
isEqualTo(CompactionStyle.FIFO);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
|
@ -8,6 +8,7 @@ package org.rocksdb.test;
|
|||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.rocksdb.EncodingType;
|
import org.rocksdb.EncodingType;
|
||||||
|
import org.rocksdb.Options;
|
||||||
import org.rocksdb.PlainTableConfig;
|
import org.rocksdb.PlainTableConfig;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@ -19,30 +20,79 @@ public class PlainTableConfigTest {
|
|||||||
new RocksMemoryResource();
|
new RocksMemoryResource();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void plainTableConfig() {
|
public void keySize() {
|
||||||
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
plainTableConfig.setKeySize(5);
|
plainTableConfig.setKeySize(5);
|
||||||
assertThat(plainTableConfig.keySize()).
|
assertThat(plainTableConfig.keySize()).
|
||||||
isEqualTo(5);
|
isEqualTo(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bloomBitsPerKey() {
|
||||||
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
plainTableConfig.setBloomBitsPerKey(11);
|
plainTableConfig.setBloomBitsPerKey(11);
|
||||||
assertThat(plainTableConfig.bloomBitsPerKey()).
|
assertThat(plainTableConfig.bloomBitsPerKey()).
|
||||||
isEqualTo(11);
|
isEqualTo(11);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hashTableRatio() {
|
||||||
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
plainTableConfig.setHashTableRatio(0.95);
|
plainTableConfig.setHashTableRatio(0.95);
|
||||||
assertThat(plainTableConfig.hashTableRatio()).
|
assertThat(plainTableConfig.hashTableRatio()).
|
||||||
isEqualTo(0.95);
|
isEqualTo(0.95);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void indexSparseness() {
|
||||||
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
plainTableConfig.setIndexSparseness(18);
|
plainTableConfig.setIndexSparseness(18);
|
||||||
assertThat(plainTableConfig.indexSparseness()).
|
assertThat(plainTableConfig.indexSparseness()).
|
||||||
isEqualTo(18);
|
isEqualTo(18);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hugePageTlbSize() {
|
||||||
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
plainTableConfig.setHugePageTlbSize(1);
|
plainTableConfig.setHugePageTlbSize(1);
|
||||||
assertThat(plainTableConfig.hugePageTlbSize()).
|
assertThat(plainTableConfig.hugePageTlbSize()).
|
||||||
isEqualTo(1);
|
isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void encodingType() {
|
||||||
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
plainTableConfig.setEncodingType(EncodingType.kPrefix);
|
plainTableConfig.setEncodingType(EncodingType.kPrefix);
|
||||||
assertThat(plainTableConfig.encodingType()).isEqualTo(
|
assertThat(plainTableConfig.encodingType()).isEqualTo(
|
||||||
EncodingType.kPrefix);
|
EncodingType.kPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fullScanMode() {
|
||||||
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
plainTableConfig.setFullScanMode(true);
|
plainTableConfig.setFullScanMode(true);
|
||||||
assertThat(plainTableConfig.fullScanMode()).isTrue();
|
assertThat(plainTableConfig.fullScanMode()).isTrue(); }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void storeIndexInFile() {
|
||||||
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
plainTableConfig.setStoreIndexInFile(true);
|
plainTableConfig.setStoreIndexInFile(true);
|
||||||
assertThat(plainTableConfig.storeIndexInFile()).
|
assertThat(plainTableConfig.storeIndexInFile()).
|
||||||
isTrue();
|
isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void plainTableConfig() {
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
opt = new Options();
|
||||||
|
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||||
|
opt.setTableFormatConfig(plainTableConfig);
|
||||||
|
assertThat(opt.tableFactoryName()).isEqualTo("PlainTable");
|
||||||
|
} finally {
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@ public class ReadOptionsTest {
|
|||||||
ReadOptions opt = null;
|
ReadOptions opt = null;
|
||||||
try {
|
try {
|
||||||
opt = new ReadOptions();
|
opt = new ReadOptions();
|
||||||
Random rand = new Random();
|
|
||||||
opt.setSnapshot(null);
|
opt.setSnapshot(null);
|
||||||
assertThat(opt.snapshot()).isNull();
|
assertThat(opt.snapshot()).isNull();
|
||||||
} finally {
|
} finally {
|
||||||
@ -88,12 +87,19 @@ public class ReadOptionsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void failVerifyChecksumUninitialized(){
|
public void failSetVerifyChecksumUninitialized(){
|
||||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||||
exception);
|
exception);
|
||||||
readOptions.setVerifyChecksums(true);
|
readOptions.setVerifyChecksums(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void failVerifyChecksumUninitialized(){
|
||||||
|
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||||
|
exception);
|
||||||
|
readOptions.verifyChecksums();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void failSetFillCacheUninitialized(){
|
public void failSetFillCacheUninitialized(){
|
||||||
ReadOptions readOptions = setupUninitializedReadOptions(
|
ReadOptions readOptions = setupUninitializedReadOptions(
|
||||||
|
282
java/org/rocksdb/test/RocksDBTest.java
Normal file
282
java/org/rocksdb/test/RocksDBTest.java
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
package org.rocksdb.test;
|
||||||
|
|
||||||
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
import org.rocksdb.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class RocksDBTest {
|
||||||
|
|
||||||
|
@ClassRule
|
||||||
|
public static final RocksMemoryResource rocksMemoryResource =
|
||||||
|
new RocksMemoryResource();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void open() throws RocksDBException {
|
||||||
|
RocksDB db = null;
|
||||||
|
Options opt = null;
|
||||||
|
try {
|
||||||
|
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
|
||||||
|
db.close();
|
||||||
|
opt = new Options();
|
||||||
|
opt.setCreateIfMissing(true);
|
||||||
|
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath());
|
||||||
|
} finally {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void put() throws RocksDBException {
|
||||||
|
RocksDB db = null;
|
||||||
|
WriteOptions opt = null;
|
||||||
|
try {
|
||||||
|
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
|
||||||
|
db.put("key1".getBytes(), "value".getBytes());
|
||||||
|
opt = new WriteOptions();
|
||||||
|
db.put(opt, "key2".getBytes(), "12345678".getBytes());
|
||||||
|
assertThat(db.get("key1".getBytes())).isEqualTo(
|
||||||
|
"value".getBytes());
|
||||||
|
assertThat(db.get("key2".getBytes())).isEqualTo(
|
||||||
|
"12345678".getBytes());
|
||||||
|
} finally {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void write() throws RocksDBException {
|
||||||
|
RocksDB db = null;
|
||||||
|
Options options = null;
|
||||||
|
WriteBatch wb1 = null;
|
||||||
|
WriteBatch wb2 = null;
|
||||||
|
WriteOptions opts = null;
|
||||||
|
try {
|
||||||
|
options = new Options().
|
||||||
|
setMergeOperator(new StringAppendOperator()).
|
||||||
|
setCreateIfMissing(true);
|
||||||
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
|
||||||
|
opts = new WriteOptions();
|
||||||
|
wb1 = new WriteBatch();
|
||||||
|
wb1.put("key1".getBytes(), "aa".getBytes());
|
||||||
|
wb1.merge("key1".getBytes(), "bb".getBytes());
|
||||||
|
wb2 = new WriteBatch();
|
||||||
|
wb2.put("key2".getBytes(), "xx".getBytes());
|
||||||
|
wb2.merge("key2".getBytes(), "yy".getBytes());
|
||||||
|
db.write(opts, wb1);
|
||||||
|
db.write(opts, wb2);
|
||||||
|
assertThat(db.get("key1".getBytes())).isEqualTo(
|
||||||
|
"aa,bb".getBytes());
|
||||||
|
assertThat(db.get("key2".getBytes())).isEqualTo(
|
||||||
|
"xx,yy".getBytes());
|
||||||
|
} finally {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
if (wb1 != null) {
|
||||||
|
wb1.dispose();
|
||||||
|
}
|
||||||
|
if (wb2 != null) {
|
||||||
|
wb2.dispose();
|
||||||
|
}
|
||||||
|
if (options != null) {
|
||||||
|
options.dispose();
|
||||||
|
}
|
||||||
|
if (opts != null) {
|
||||||
|
opts.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWithOutValue() throws RocksDBException {
|
||||||
|
RocksDB db = null;
|
||||||
|
try {
|
||||||
|
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
|
||||||
|
db.put("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("key1".getBytes(), outValue);
|
||||||
|
assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
|
||||||
|
assertThat(outValue).isEqualTo("value".getBytes());
|
||||||
|
// found value which fits partially
|
||||||
|
getResult = db.get("key2".getBytes(), outValue);
|
||||||
|
assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
|
||||||
|
assertThat(outValue).isEqualTo("12345".getBytes());
|
||||||
|
} finally {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWithOutValueReadOptions() throws RocksDBException {
|
||||||
|
RocksDB db = null;
|
||||||
|
ReadOptions rOpt = null;
|
||||||
|
try {
|
||||||
|
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
|
||||||
|
rOpt = new ReadOptions();
|
||||||
|
db.put("key1".getBytes(), "value".getBytes());
|
||||||
|
db.put("key2".getBytes(), "12345678".getBytes());
|
||||||
|
byte[] outValue = new byte[5];
|
||||||
|
// not found value
|
||||||
|
int getResult = db.get(rOpt, "keyNotFound".getBytes(),
|
||||||
|
outValue);
|
||||||
|
assertThat(getResult).isEqualTo(RocksDB.NOT_FOUND);
|
||||||
|
// found value which fits in outValue
|
||||||
|
getResult = db.get(rOpt, "key1".getBytes(), outValue);
|
||||||
|
assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
|
||||||
|
assertThat(outValue).isEqualTo("value".getBytes());
|
||||||
|
// found value which fits partially
|
||||||
|
getResult = db.get(rOpt, "key2".getBytes(), outValue);
|
||||||
|
assertThat(getResult).isNotEqualTo(RocksDB.NOT_FOUND);
|
||||||
|
assertThat(outValue).isEqualTo("12345".getBytes());
|
||||||
|
} finally {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
if (rOpt != null) {
|
||||||
|
rOpt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multiGet() throws RocksDBException {
|
||||||
|
RocksDB db = null;
|
||||||
|
ReadOptions rOpt = null;
|
||||||
|
try {
|
||||||
|
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
|
||||||
|
rOpt = new ReadOptions();
|
||||||
|
db.put("key1".getBytes(), "value".getBytes());
|
||||||
|
db.put("key2".getBytes(), "12345678".getBytes());
|
||||||
|
List<byte[]> lookupKeys = new ArrayList<byte[]>() {{
|
||||||
|
add("key1".getBytes());
|
||||||
|
add("key2".getBytes());
|
||||||
|
}};
|
||||||
|
Map<byte[], byte[]> results = db.multiGet(lookupKeys);
|
||||||
|
assertThat(results).isNotNull();
|
||||||
|
assertThat(results.values()).isNotNull();
|
||||||
|
assertThat(results.values()).
|
||||||
|
contains("value".getBytes(), "12345678".getBytes());
|
||||||
|
// test same method with ReadOptions
|
||||||
|
results = db.multiGet(rOpt, lookupKeys);
|
||||||
|
assertThat(results).isNotNull();
|
||||||
|
assertThat(results.values()).isNotNull();
|
||||||
|
assertThat(results.values()).
|
||||||
|
contains("value".getBytes(), "12345678".getBytes());
|
||||||
|
|
||||||
|
// remove existing key
|
||||||
|
lookupKeys.remove("key2".getBytes());
|
||||||
|
// add non existing key
|
||||||
|
lookupKeys.add("key3".getBytes());
|
||||||
|
results = db.multiGet(lookupKeys);
|
||||||
|
assertThat(results).isNotNull();
|
||||||
|
assertThat(results.values()).isNotNull();
|
||||||
|
assertThat(results.values()).
|
||||||
|
contains("value".getBytes());
|
||||||
|
// test same call with readOptions
|
||||||
|
results = db.multiGet(rOpt, lookupKeys);
|
||||||
|
assertThat(results).isNotNull();
|
||||||
|
assertThat(results.values()).isNotNull();
|
||||||
|
assertThat(results.values()).
|
||||||
|
contains("value".getBytes());
|
||||||
|
} finally {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
if (rOpt != null) {
|
||||||
|
rOpt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void merge() throws RocksDBException {
|
||||||
|
RocksDB db = null;
|
||||||
|
Options opt = null;
|
||||||
|
WriteOptions wOpt;
|
||||||
|
try {
|
||||||
|
opt = new Options().
|
||||||
|
setCreateIfMissing(true).
|
||||||
|
setMergeOperator(new StringAppendOperator());
|
||||||
|
wOpt = new WriteOptions();
|
||||||
|
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath());
|
||||||
|
db.put("key1".getBytes(), "value".getBytes());
|
||||||
|
assertThat(db.get("key1".getBytes())).isEqualTo(
|
||||||
|
"value".getBytes());
|
||||||
|
// merge key1 with another value portion
|
||||||
|
db.merge("key1".getBytes(), "value2".getBytes());
|
||||||
|
assertThat(db.get("key1".getBytes())).isEqualTo(
|
||||||
|
"value,value2".getBytes());
|
||||||
|
// merge key1 with another value portion
|
||||||
|
db.merge(wOpt, "key1".getBytes(), "value3".getBytes());
|
||||||
|
assertThat(db.get("key1".getBytes())).isEqualTo(
|
||||||
|
"value,value2,value3".getBytes());
|
||||||
|
// merge on non existent key shall insert the value
|
||||||
|
db.merge(wOpt, "key2".getBytes(), "xxxx".getBytes());
|
||||||
|
assertThat(db.get("key2".getBytes())).isEqualTo(
|
||||||
|
"xxxx".getBytes());
|
||||||
|
} finally {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void remove() throws RocksDBException {
|
||||||
|
RocksDB db = null;
|
||||||
|
WriteOptions wOpt;
|
||||||
|
try {
|
||||||
|
wOpt = new WriteOptions();
|
||||||
|
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
|
||||||
|
db.put("key1".getBytes(), "value".getBytes());
|
||||||
|
db.put("key2".getBytes(), "12345678".getBytes());
|
||||||
|
assertThat(db.get("key1".getBytes())).isEqualTo(
|
||||||
|
"value".getBytes());
|
||||||
|
assertThat(db.get("key2".getBytes())).isEqualTo(
|
||||||
|
"12345678".getBytes());
|
||||||
|
db.remove("key1".getBytes());
|
||||||
|
db.remove(wOpt, "key2".getBytes());
|
||||||
|
assertThat(db.get("key1".getBytes())).isNull();
|
||||||
|
assertThat(db.get("key2".getBytes())).isNull();
|
||||||
|
} finally {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
java/org/rocksdb/test/SizeUnitTest.java
Normal file
28
java/org/rocksdb/test/SizeUnitTest.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
package org.rocksdb.test;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.rocksdb.util.SizeUnit;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class SizeUnitTest {
|
||||||
|
|
||||||
|
public static final long COMPUTATION_UNIT = 1024L;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sizeUnit() {
|
||||||
|
assertThat(SizeUnit.KB).isEqualTo(COMPUTATION_UNIT);
|
||||||
|
assertThat(SizeUnit.MB).isEqualTo(
|
||||||
|
SizeUnit.KB * COMPUTATION_UNIT);
|
||||||
|
assertThat(SizeUnit.GB).isEqualTo(
|
||||||
|
SizeUnit.MB * COMPUTATION_UNIT);
|
||||||
|
assertThat(SizeUnit.TB).isEqualTo(
|
||||||
|
SizeUnit.GB * COMPUTATION_UNIT);
|
||||||
|
assertThat(SizeUnit.PB).isEqualTo(
|
||||||
|
SizeUnit.TB * COMPUTATION_UNIT);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user