1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2 // This source code is licensed under both the GPLv2 (found in the 3 // COPYING file in the root directory) and Apache 2.0 License 4 // (found in the LICENSE.Apache file in the root directory). 5 package org.rocksdb; 6 7 import org.junit.Rule; 8 import org.junit.Test; 9 import org.junit.rules.TemporaryFolder; 10 import org.rocksdb.util.Environment; 11 12 import java.io.File; 13 import java.io.IOException; 14 import java.nio.file.*; 15 16 import static org.assertj.core.api.Assertions.assertThat; 17 18 public class NativeLibraryLoaderTest { 19 20 @Rule 21 public TemporaryFolder temporaryFolder = new TemporaryFolder(); 22 23 @Test tempFolder()24 public void tempFolder() throws IOException { 25 NativeLibraryLoader.getInstance().loadLibraryFromJarToTemp( 26 temporaryFolder.getRoot().getAbsolutePath()); 27 final Path path = Paths.get(temporaryFolder.getRoot().getAbsolutePath(), 28 Environment.getJniLibraryFileName("rocksdb")); 29 assertThat(Files.exists(path)).isTrue(); 30 assertThat(Files.isReadable(path)).isTrue(); 31 } 32 33 @Test overridesExistingLibrary()34 public void overridesExistingLibrary() throws IOException { 35 File first = NativeLibraryLoader.getInstance().loadLibraryFromJarToTemp( 36 temporaryFolder.getRoot().getAbsolutePath()); 37 NativeLibraryLoader.getInstance().loadLibraryFromJarToTemp( 38 temporaryFolder.getRoot().getAbsolutePath()); 39 assertThat(first.exists()).isTrue(); 40 } 41 } 42