[RocksJava] Extended Testcases
This commit is contained in:
parent
36f3a0bb8e
commit
a4b28c1ae7
125
java/org/rocksdb/test/EnvironmentTest.java
Normal file
125
java/org/rocksdb/test/EnvironmentTest.java
Normal file
@ -0,0 +1,125 @@
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.util.Environment;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EnvironmentTest {
|
||||
|
||||
// Init static context
|
||||
private static Environment environment =
|
||||
new Environment();
|
||||
|
||||
@Test
|
||||
public void mac32() {
|
||||
setEnvironmentClassFields("mac", "32");
|
||||
assertThat(Environment.getJniLibraryExtension()).
|
||||
isEqualTo(".jnilib");
|
||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni-osx.jnilib");
|
||||
assertThat(Environment.getSharedLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni.dylib");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mac64() {
|
||||
setEnvironmentClassFields("mac", "64");
|
||||
assertThat(Environment.getJniLibraryExtension()).
|
||||
isEqualTo(".jnilib");
|
||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni-osx.jnilib");
|
||||
assertThat(Environment.getSharedLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni.dylib");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nix32() {
|
||||
// Linux
|
||||
setEnvironmentClassFields("Linux", "32");
|
||||
assertThat(Environment.getJniLibraryExtension()).
|
||||
isEqualTo(".so");
|
||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni-linux32.so");
|
||||
assertThat(Environment.getSharedLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni.so");
|
||||
// UNIX
|
||||
setEnvironmentClassFields("Unix", "32");
|
||||
assertThat(Environment.getJniLibraryExtension()).
|
||||
isEqualTo(".so");
|
||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni-linux32.so");
|
||||
assertThat(Environment.getSharedLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni.so");
|
||||
// AIX
|
||||
setEnvironmentClassFields("aix", "32");
|
||||
assertThat(Environment.getJniLibraryExtension()).
|
||||
isEqualTo(".so");
|
||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni-linux32.so");
|
||||
assertThat(Environment.getSharedLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni.so");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nix64() {
|
||||
setEnvironmentClassFields("Linux", "x64");
|
||||
assertThat(Environment.getJniLibraryExtension()).
|
||||
isEqualTo(".so");
|
||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni-linux64.so");
|
||||
assertThat(Environment.getSharedLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni.so");
|
||||
// UNIX
|
||||
setEnvironmentClassFields("Unix", "x64");
|
||||
assertThat(Environment.getJniLibraryExtension()).
|
||||
isEqualTo(".so");
|
||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni-linux64.so");
|
||||
assertThat(Environment.getSharedLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni.so");
|
||||
// AIX
|
||||
setEnvironmentClassFields("aix", "x64");
|
||||
assertThat(Environment.getJniLibraryExtension()).
|
||||
isEqualTo(".so");
|
||||
assertThat(Environment.getJniLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni-linux64.so");
|
||||
assertThat(Environment.getSharedLibraryName("rocksdb")).
|
||||
isEqualTo("librocksdbjni.so");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void failLinuxJniLibraryName(){
|
||||
setEnvironmentClassFields("win", "x64");
|
||||
Environment.getJniLibraryName("rocksdb");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void failWinSharedLibrary(){
|
||||
setEnvironmentClassFields("win", "x64");
|
||||
Environment.getSharedLibraryName("rocksdb");
|
||||
}
|
||||
|
||||
private void setEnvironmentClassFields(String osName,
|
||||
String osArch) {
|
||||
setEnvironmentClassField("OS", osName);
|
||||
setEnvironmentClassField("ARCH", osArch);
|
||||
}
|
||||
|
||||
private void setEnvironmentClassField(String fieldName, String value) {
|
||||
final Field field;
|
||||
try {
|
||||
field = Environment.class.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
final Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(null, value);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ import org.rocksdb.RocksDB;
|
||||
import org.rocksdb.RocksDBException;
|
||||
import org.rocksdb.RocksIterator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class RocksIteratorTest {
|
||||
|
||||
@ClassRule
|
||||
@ -22,6 +24,42 @@ public class RocksIteratorTest {
|
||||
@Rule
|
||||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void rocksIterator() throws RocksDBException {
|
||||
RocksDB db;
|
||||
Options options = new Options();
|
||||
options.setCreateIfMissing(true)
|
||||
.setCreateMissingColumnFamilies(true);
|
||||
db = RocksDB.open(options,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
db.put("key1".getBytes(), "value1".getBytes());
|
||||
db.put("key2".getBytes(), "value2".getBytes());
|
||||
|
||||
RocksIterator iterator = db.newIterator();
|
||||
|
||||
iterator.seekToFirst();
|
||||
assertThat(iterator.isValid()).isTrue();
|
||||
assertThat(iterator.key()).isEqualTo("key1".getBytes());
|
||||
assertThat(iterator.value()).isEqualTo("value1".getBytes());
|
||||
iterator.next();
|
||||
assertThat(iterator.isValid()).isTrue();
|
||||
assertThat(iterator.key()).isEqualTo("key2".getBytes());
|
||||
assertThat(iterator.value()).isEqualTo("value2".getBytes());
|
||||
iterator.next();
|
||||
assertThat(iterator.isValid()).isFalse();
|
||||
iterator.seekToLast();
|
||||
iterator.prev();
|
||||
assertThat(iterator.isValid()).isTrue();
|
||||
assertThat(iterator.key()).isEqualTo("key1".getBytes());
|
||||
assertThat(iterator.value()).isEqualTo("value1".getBytes());
|
||||
iterator.seekToFirst();
|
||||
iterator.seekToLast();
|
||||
assertThat(iterator.isValid()).isTrue();
|
||||
assertThat(iterator.key()).isEqualTo("key2".getBytes());
|
||||
assertThat(iterator.value()).isEqualTo("value2".getBytes());
|
||||
iterator.status();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rocksIteratorGc()
|
||||
throws RocksDBException {
|
||||
|
Loading…
Reference in New Issue
Block a user