|
1 | 1 | package org.rocksdb;
|
2 | 2 |
|
3 |
| - |
4 |
| -import org.junit.Test; |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.fail; |
5 | 5 |
|
6 | 6 | import java.lang.reflect.Method;
|
7 | 7 | import java.net.URL;
|
8 | 8 | import java.net.URLClassLoader;
|
9 | 9 | import java.nio.file.Path;
|
10 | 10 | import java.nio.file.Paths;
|
11 |
| - |
12 |
| -import static org.assertj.core.api.Assertions.assertThat; |
13 |
| -import static org.assertj.core.api.Assertions.fail; |
14 |
| - |
15 |
| - |
| 11 | +import org.junit.Test; |
16 | 12 |
|
17 | 13 | /**
|
18 | 14 | * Only this class can be on default classpath.
|
19 | 15 | * It loads rocksDB code with custom classloader and then test that all
|
20 | 16 | * event data for event listener can be instantiated.
|
21 | 17 | */
|
22 | 18 | public class EventListenerClassloaderTest {
|
| 19 | + @Test |
| 20 | + public void testCallback() throws Exception { |
| 21 | + try { |
| 22 | + this.getClass().getClassLoader().loadClass("org.rocksdb.RocksDB"); |
| 23 | + fail("It looks like RocksDB is on classpath. This test must load RocksDB via custom " |
| 24 | + + "classLoader" |
| 25 | + + " to verify that callback cache all class instances."); |
| 26 | + } catch (ClassNotFoundException e) { |
| 27 | + ; |
| 28 | + } |
23 | 29 |
|
| 30 | + String jarPath = System.getProperty("rocks-jar"); |
| 31 | + assertThat(jarPath).isNotNull().as("Java property 'rocks-jar' was not setup properly"); |
24 | 32 |
|
25 |
| - @Test |
26 |
| - public void testCallback() throws Exception { |
27 |
| - |
28 |
| - try { |
29 |
| - this.getClass().getClassLoader().loadClass("org.rocksdb.RocksDB"); |
30 |
| - fail("It looks like RocksDB is on classpath. This test must load RocksDB via custom classLoader" + |
31 |
| - " to verify callback cache all class instances."); |
32 |
| - }catch (ClassNotFoundException e) { |
33 |
| - ; |
34 |
| - } |
35 |
| - |
36 |
| - String jarPath = System.getProperty("rocks-jar"); |
37 |
| - assertThat(jarPath).isNotNull().as("Java property 'rocks-jar' was not setup properly"); |
38 |
| - |
39 |
| - Path classesDir = Paths.get(jarPath); |
40 |
| - ClassLoader cl = new URLClassLoader(new URL[]{ |
41 |
| - classesDir.toAbsolutePath().toUri().toURL() |
42 |
| - }); |
43 |
| - |
44 |
| - Class rocksDBclazz = cl.loadClass("org.rocksdb.RocksDB"); |
45 |
| - Method loadLibrary = rocksDBclazz.getMethod("loadLibrary"); |
46 |
| - loadLibrary.invoke(null); |
47 |
| - |
48 |
| - Class testableEventListenerClazz = cl.loadClass("org.rocksdb.test.TestableEventListener"); |
49 |
| - Method invokeAllCallbacksInThread = testableEventListenerClazz.getMethod("invokeAllCallbacksInThread"); |
50 |
| - Object instance = testableEventListenerClazz.getDeclaredConstructor().newInstance(); |
51 |
| - invokeAllCallbacksInThread.invoke(instance); |
| 33 | + Path classesDir = Paths.get(jarPath); |
| 34 | + ClassLoader cl = new URLClassLoader(new URL[] {classesDir.toAbsolutePath().toUri().toURL()}); |
52 | 35 |
|
| 36 | + Class rocksDBclazz = cl.loadClass("org.rocksdb.RocksDB"); |
| 37 | + Method loadLibrary = rocksDBclazz.getMethod("loadLibrary"); |
| 38 | + loadLibrary.invoke(null); |
53 | 39 |
|
54 |
| - } |
| 40 | + Class testableEventListenerClazz = cl.loadClass("org.rocksdb.test.TestableEventListener"); |
| 41 | + Method invokeAllCallbacksInThread = |
| 42 | + testableEventListenerClazz.getMethod("invokeAllCallbacksInThread"); |
| 43 | + Object instance = testableEventListenerClazz.getDeclaredConstructor().newInstance(); |
| 44 | + invokeAllCallbacksInThread.invoke(instance); |
| 45 | + } |
55 | 46 | }
|
0 commit comments