Merge pull request #528 from fyrz/RocksJava-NativeLibraryLoader
[RocksJava] Fix NativeLibraryLoader
This commit is contained in:
commit
2c84303aaa
@ -172,7 +172,7 @@ java_test: resolve_test_deps
|
|||||||
javah -cp $(MAIN_CLASSES):$(TEST_CLASSES) -d $(NATIVE_INCLUDE) -jni $(NATIVE_JAVA_TEST_CLASSES)
|
javah -cp $(MAIN_CLASSES):$(TEST_CLASSES) -d $(NATIVE_INCLUDE) -jni $(NATIVE_JAVA_TEST_CLASSES)
|
||||||
|
|
||||||
test: java resolve_test_deps java_test
|
test: java resolve_test_deps java_test
|
||||||
java -ea -Xcheck:jni -Djava.library.path=target -cp "$(MAIN_CLASSES):$(TEST_CLASSES):$(JAVA_TESTCLASSPATH)" org.rocksdb.test.RocksJunitRunner $(JAVA_TESTS)
|
java -ea -Xcheck:jni -Djava.library.path=target -cp "$(MAIN_CLASSES):$(TEST_CLASSES):$(JAVA_TESTCLASSPATH):target/*" org.rocksdb.test.RocksJunitRunner $(JAVA_TESTS)
|
||||||
|
|
||||||
db_bench: java
|
db_bench: java
|
||||||
mkdir -p $(BENCHMARK_MAIN_CLASSES)
|
mkdir -p $(BENCHMARK_MAIN_CLASSES)
|
||||||
|
@ -72,7 +72,7 @@ public class NativeLibraryLoader {
|
|||||||
*
|
*
|
||||||
* @throws java.io.IOException if a filesystem operation fails.
|
* @throws java.io.IOException if a filesystem operation fails.
|
||||||
*/
|
*/
|
||||||
private void loadLibraryFromJar(final String tmpDir)
|
void loadLibraryFromJar(final String tmpDir)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
final File temp;
|
final File temp;
|
||||||
@ -80,6 +80,10 @@ public class NativeLibraryLoader {
|
|||||||
temp = File.createTempFile(tempFilePrefix, tempFileSuffix);
|
temp = File.createTempFile(tempFilePrefix, tempFileSuffix);
|
||||||
} else {
|
} else {
|
||||||
temp = new File(tmpDir, jniLibraryFileName);
|
temp = new File(tmpDir, jniLibraryFileName);
|
||||||
|
if (!temp.createNewFile()) {
|
||||||
|
throw new RuntimeException("File: " + temp.getAbsolutePath()
|
||||||
|
+ " could not be created.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!temp.exists()) {
|
if (!temp.exists()) {
|
||||||
|
@ -4,35 +4,28 @@
|
|||||||
// of patent rights can be found in the PATENTS file in the same directory.
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
package org.rocksdb;
|
package org.rocksdb;
|
||||||
|
|
||||||
import org.junit.ClassRule;
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
import org.rocksdb.util.Environment;
|
import org.rocksdb.util.Environment;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class NativeLibraryLoaderTest {
|
public class NativeLibraryLoaderTest {
|
||||||
|
|
||||||
@ClassRule
|
|
||||||
public static final RocksMemoryResource rocksMemoryResource =
|
|
||||||
new RocksMemoryResource();
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tempFolder() throws IOException {
|
public void tempFolder() throws IOException {
|
||||||
NativeLibraryLoader.getInstance().loadLibrary(
|
NativeLibraryLoader.getInstance().loadLibraryFromJar(
|
||||||
temporaryFolder.getRoot().getAbsolutePath());
|
temporaryFolder.getRoot().getAbsolutePath());
|
||||||
Path path = Paths.get(temporaryFolder.getRoot().getAbsolutePath(),
|
Path path = Paths.get(temporaryFolder.getRoot().getAbsolutePath(),
|
||||||
Environment.getJniLibraryFileName("rocksdb"));
|
Environment.getJniLibraryFileName("rocksdb"));
|
||||||
assertThat(Files.exists(path));
|
assertThat(Files.exists(path)).isTrue();
|
||||||
assertThat(Files.isReadable(path));
|
assertThat(Files.isReadable(path)).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user