[RocksJava] RocksJava Testcases
- NativeLibraryLoader Test - EnvironmentTest Bugfix
This commit is contained in:
parent
62247ffa3b
commit
9fcf1a7b00
@ -74,6 +74,7 @@ JAVA_TESTS = org.rocksdb.BackupableDBOptionsTest\
|
||||
org.rocksdb.MemTableTest\
|
||||
org.rocksdb.MergeTest\
|
||||
org.rocksdb.MixedOptionsTest\
|
||||
org.rocksdb.NativeLibraryLoaderTest\
|
||||
org.rocksdb.OptionsTest\
|
||||
org.rocksdb.PlainTableConfigTest\
|
||||
org.rocksdb.ReadOnlyTest\
|
||||
|
38
java/src/test/java/org/rocksdb/NativeLibraryLoaderTest.java
Normal file
38
java/src/test/java/org/rocksdb/NativeLibraryLoaderTest.java
Normal file
@ -0,0 +1,38 @@
|
||||
// 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;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.rocksdb.util.Environment;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class NativeLibraryLoaderTest {
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void tempFolder() throws IOException {
|
||||
NativeLibraryLoader.getInstance().loadLibrary(
|
||||
temporaryFolder.getRoot().getAbsolutePath());
|
||||
Path path = Paths.get(temporaryFolder.getRoot().getAbsolutePath(),
|
||||
Environment.getJniLibraryFileName("rocksdb"));
|
||||
assertThat(Files.exists(path));
|
||||
assertThat(Files.isReadable(path));
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
package org.rocksdb.util;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -12,10 +14,17 @@ import java.lang.reflect.Modifier;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EnvironmentTest {
|
||||
private final static String ARCH_FIELD_NAME = "ARCH";
|
||||
private final static String OS_FIELD_NAME = "OS";
|
||||
|
||||
// Init static context
|
||||
private static Environment environment =
|
||||
new Environment();
|
||||
private static String INITIAL_OS;
|
||||
private static String INITIAL_ARCH;
|
||||
|
||||
@BeforeClass
|
||||
public static void saveState() {
|
||||
INITIAL_ARCH = getEnvironmentClassField(ARCH_FIELD_NAME);
|
||||
INITIAL_OS = getEnvironmentClassField(OS_FIELD_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mac32() {
|
||||
@ -122,11 +131,31 @@ public class EnvironmentTest {
|
||||
|
||||
private void setEnvironmentClassFields(String osName,
|
||||
String osArch) {
|
||||
setEnvironmentClassField("OS", osName);
|
||||
setEnvironmentClassField("ARCH", osArch);
|
||||
setEnvironmentClassField(OS_FIELD_NAME, osName);
|
||||
setEnvironmentClassField(ARCH_FIELD_NAME, osArch);
|
||||
}
|
||||
|
||||
private void setEnvironmentClassField(String fieldName, String value) {
|
||||
@AfterClass
|
||||
public static void restoreState() {
|
||||
setEnvironmentClassField(OS_FIELD_NAME, INITIAL_OS);
|
||||
setEnvironmentClassField(ARCH_FIELD_NAME, INITIAL_ARCH);
|
||||
}
|
||||
|
||||
private static String getEnvironmentClassField(String fieldName) {
|
||||
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);
|
||||
return (String)field.get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setEnvironmentClassField(String fieldName, String value) {
|
||||
final Field field;
|
||||
try {
|
||||
field = Environment.class.getDeclaredField(fieldName);
|
||||
|
Loading…
Reference in New Issue
Block a user