[RocksJava] Testcase improvements

This commit is contained in:
fyrz 2014-11-02 23:39:01 +01:00
parent 1fe7a4c62f
commit f617135d5f
4 changed files with 137 additions and 24 deletions

View File

@ -155,7 +155,6 @@ public class ReadOptions extends RocksObject {
@Override protected void disposeInternal() {
assert(isInitialized());
disposeInternal(nativeHandle_);
}
private native void disposeInternal(long handle);

View File

@ -5,49 +5,85 @@
package org.rocksdb.test;
import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.BlockBasedTableConfig;
import org.rocksdb.ChecksumType;
import org.rocksdb.IndexType;
import org.rocksdb.*;
import static org.assertj.core.api.Assertions.assertThat;
public class BlockBasedTableConfigTest {
@ClassRule
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
@AfterClass
public static void printMessage(){
System.out.println("Passed BlockBasedTableConfigTst.");
}
@Test
public void shouldTestBlockBasedTableConfig() {
BlockBasedTableConfig blockBasedTableConfig =
new BlockBasedTableConfig();
blockBasedTableConfig.setNoBlockCache(true);
assert(blockBasedTableConfig.noBlockCache());
blockBasedTableConfig.setBlockCacheSize(8*1024);
assert(blockBasedTableConfig.blockCacheSize() == (8*1024));
assertThat(blockBasedTableConfig.noBlockCache()).isTrue();
blockBasedTableConfig.setBlockCacheSize(8 * 1024);
assertThat(blockBasedTableConfig.blockCacheSize()).
isEqualTo(8 * 1024);
blockBasedTableConfig.setBlockSizeDeviation(12);
assert(blockBasedTableConfig.blockSizeDeviation() == 12);
assertThat(blockBasedTableConfig.blockSizeDeviation()).
isEqualTo(12);
blockBasedTableConfig.setBlockRestartInterval(15);
assert(blockBasedTableConfig.blockRestartInterval() == 15);
assertThat(blockBasedTableConfig.blockRestartInterval()).
isEqualTo(15);
blockBasedTableConfig.setWholeKeyFiltering(false);
assert(!blockBasedTableConfig.wholeKeyFiltering());
assertThat(blockBasedTableConfig.wholeKeyFiltering()).
isFalse();
blockBasedTableConfig.setCacheIndexAndFilterBlocks(true);
assert(blockBasedTableConfig.cacheIndexAndFilterBlocks());
assertThat(blockBasedTableConfig.cacheIndexAndFilterBlocks()).
isTrue();
blockBasedTableConfig.setHashIndexAllowCollision(false);
assert(!blockBasedTableConfig.hashIndexAllowCollision());
assertThat(blockBasedTableConfig.hashIndexAllowCollision()).
isFalse();
blockBasedTableConfig.setBlockCacheCompressedSize(40);
assert(blockBasedTableConfig.blockCacheCompressedSize() == 40);
assertThat(blockBasedTableConfig.blockCacheCompressedSize()).
isEqualTo(40);
blockBasedTableConfig.setChecksumType(ChecksumType.kNoChecksum);
blockBasedTableConfig.setChecksumType(ChecksumType.kxxHash);
assert(blockBasedTableConfig.checksumType().equals(
assertThat(blockBasedTableConfig.checksumType().equals(
ChecksumType.kxxHash));
blockBasedTableConfig.setIndexType(IndexType.kHashSearch);
assert(blockBasedTableConfig.indexType().equals(
assertThat(blockBasedTableConfig.indexType().equals(
IndexType.kHashSearch));
blockBasedTableConfig.setBlockCacheCompressedNumShardBits(4);
assert(blockBasedTableConfig.blockCacheCompressedNumShardBits()
== 4);
assertThat(blockBasedTableConfig.blockCacheCompressedNumShardBits()).
isEqualTo(4);
blockBasedTableConfig.setCacheNumShardBits(5);
assert(blockBasedTableConfig.cacheNumShardBits() == 5);
assertThat(blockBasedTableConfig.cacheNumShardBits()).
isEqualTo(5);
blockBasedTableConfig.setBlockSize(10);
assertThat(blockBasedTableConfig.blockSize()).isEqualTo(10);
System.out.println("Passed BlockBasedTableConfigTest.");
}
@Test
public void shouldTestBlockBasedTableWithFilter() {
Options options = new Options();
options.setTableFormatConfig(
new BlockBasedTableConfig().setFilter(
new BloomFilter(10)));
assertThat(options.tableFactoryName()).
isEqualTo("BlockBasedTable");
}
@Test
public void shouldTestBlockBasedTableWithoutFilter() {
Options options = new Options();
options.setTableFormatConfig(
new BlockBasedTableConfig().setFilter(null));
assertThat(options.tableFactoryName()).
isEqualTo("BlockBasedTable");
}
}

View File

@ -5,6 +5,7 @@
package org.rocksdb.test;
import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.rocksdb.EncodingType;
@ -16,6 +17,11 @@ public class PlainTableConfigTest {
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
@AfterClass
public static void printMessage(){
System.out.println("Passed PlainTableConfigTest.");
}
@Test
public void shouldTestPlainTableConfig() {
PlainTableConfig plainTableConfig = new PlainTableConfig();
@ -36,6 +42,5 @@ public class PlainTableConfigTest {
assert(plainTableConfig.fullScanMode());
plainTableConfig.setStoreIndexInFile(true);
assert(plainTableConfig.storeIndexInFile());
System.out.println("Passed PlainTableConfigTest.");
}
}

View File

@ -7,17 +7,29 @@ package org.rocksdb.test;
import java.util.Random;
import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.rocksdb.RocksDB;
import org.junit.rules.ExpectedException;
import org.rocksdb.ReadOptions;
import static org.assertj.core.api.Assertions.assertThat;
public class ReadOptionsTest {
@ClassRule
public static final RocksMemoryResource rocksMemoryResource =
new RocksMemoryResource();
@Rule
public ExpectedException exception = ExpectedException.none();
@AfterClass
public static void printMessage(){
System.out.println("Passed ReadOptionsTest.");
}
@Test
public void shouldTestReadOptions() {
ReadOptions opt = new ReadOptions();
@ -25,21 +37,82 @@ public class ReadOptionsTest {
{ // VerifyChecksums test
boolean boolValue = rand.nextBoolean();
opt.setVerifyChecksums(boolValue);
assert(opt.verifyChecksums() == boolValue);
assertThat(opt.verifyChecksums()).isEqualTo(boolValue);
}
{ // FillCache test
boolean boolValue = rand.nextBoolean();
opt.setFillCache(boolValue);
assert(opt.fillCache() == boolValue);
assertThat(opt.fillCache()).isEqualTo(boolValue);
}
{ // Tailing test
boolean boolValue = rand.nextBoolean();
opt.setTailing(boolValue);
assert(opt.tailing() == boolValue);
assertThat(opt.tailing()).isEqualTo(boolValue);
}
{ // Snapshot null test
opt.setSnapshot(null);
assertThat(opt.snapshot()).isNull();
}
opt.dispose();
System.out.println("Passed ReadOptionsTest.");
}
@Test
public void shouldFailVerifyChecksumUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setVerifyChecksums(true);
}
@Test
public void shouldFailSetFillCacheUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setFillCache(true);
}
@Test
public void shouldFailFillCacheUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.fillCache();
}
@Test
public void shouldFailSetTailingUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setTailing(true);
}
@Test
public void shouldFailTailingUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.tailing();
}
@Test
public void shouldFailSetSnapshotUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.setSnapshot(null);
}
@Test
public void shouldFailSnapshotUninitialized(){
ReadOptions readOptions = setupUninitializedReadOptions(
exception);
readOptions.snapshot();
}
private ReadOptions setupUninitializedReadOptions(
ExpectedException exception) {
ReadOptions readOptions = new ReadOptions();
readOptions.dispose();
exception.expect(AssertionError.class);
return readOptions;
}
}