|
4 | 4 | import static datadog.nativeloader.TestPlatformSpec.LINUX; |
5 | 5 | import static datadog.nativeloader.TestPlatformSpec.UNSUPPORTED_ARCH; |
6 | 6 | import static datadog.nativeloader.TestPlatformSpec.UNSUPPORTED_OS; |
7 | | - |
8 | | - |
9 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; |
10 | 8 | import static org.junit.jupiter.api.Assertions.assertFalse; |
11 | | -import static org.junit.jupiter.api.Assertions.assertNotEquals; |
12 | 9 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
13 | 10 | import static org.junit.jupiter.api.Assertions.assertNull; |
14 | 11 | import static org.junit.jupiter.api.Assertions.assertThrows; |
@@ -77,7 +74,7 @@ public void fromDir() throws LibraryLoadException { |
77 | 74 | try (LibFile lib = loader.resolveDynamic("dummy")) { |
78 | 75 | // loaded directly from directory, so no clean-up required |
79 | 76 | assertRegularFile(lib); |
80 | | - |
| 77 | + |
81 | 78 | // file isn't actually a dynamic library |
82 | 79 | assertThrows(LibraryLoadException.class, () -> lib.load()); |
83 | 80 | } |
@@ -186,27 +183,41 @@ public void fromJarBackedClassLoader() throws IOException, LibraryLoadException |
186 | 183 | assertTempFile(lib); |
187 | 184 | } |
188 | 185 | } |
189 | | - |
| 186 | + |
| 187 | + @Test |
| 188 | + public void fromJarBackedClassLoader_with_tempDir() throws IOException, LibraryLoadException { |
| 189 | + URL[] urls = {new File("test-data/libdummy.jar").toURL()}; |
| 190 | + |
| 191 | + URLClassLoader classLoader = new URLClassLoader(urls); |
| 192 | + |
| 193 | + NativeLoader loader = |
| 194 | + NativeLoader.builder().fromClassLoader(classLoader).tempDir("temp").build(); |
| 195 | + try (LibFile lib = loader.resolveDynamic("dummy")) { |
| 196 | + // loaded from a jar, so copied to temp file |
| 197 | + assertTempFile(lib); |
| 198 | + } |
| 199 | + } |
| 200 | + |
190 | 201 | void assertPreloaded(LibFile lib) { |
191 | | - assertTrue(lib.isPreloaded()); |
192 | | - assertNull(lib.file); |
193 | | - assertNull(lib.getAbsolutePath()); |
194 | | - assertFalse(lib.needsCleanup); |
| 202 | + assertTrue(lib.isPreloaded()); |
| 203 | + assertNull(lib.file); |
| 204 | + assertNull(lib.getAbsolutePath()); |
| 205 | + assertFalse(lib.needsCleanup); |
195 | 206 | } |
196 | 207 |
|
197 | 208 | void assertRegularFile(LibFile lib) { |
198 | | - assertFalse(lib.isPreloaded()); |
199 | | - assertNotNull(lib.file); |
200 | | - assertTrue(lib.file.exists()); |
201 | | - assertEquals(lib.file.getAbsolutePath(), lib.getAbsolutePath()); |
| 209 | + assertFalse(lib.isPreloaded()); |
| 210 | + assertNotNull(lib.file); |
| 211 | + assertTrue(lib.file.exists()); |
| 212 | + assertEquals(lib.file.getAbsolutePath(), lib.getAbsolutePath()); |
202 | 213 | assertFalse(lib.needsCleanup); |
203 | 214 | } |
204 | 215 |
|
205 | 216 | void assertTempFile(LibFile lib) { |
206 | | - assertFalse(lib.isPreloaded()); |
207 | | - assertNotNull(lib.file); |
208 | | - assertTrue(lib.file.exists()); |
209 | | - assertEquals(lib.file.getAbsolutePath(), lib.getAbsolutePath()); |
210 | | - assertTrue(lib.needsCleanup); |
| 217 | + assertFalse(lib.isPreloaded()); |
| 218 | + assertNotNull(lib.file); |
| 219 | + assertTrue(lib.file.exists()); |
| 220 | + assertEquals(lib.file.getAbsolutePath(), lib.getAbsolutePath()); |
| 221 | + assertTrue(lib.needsCleanup); |
211 | 222 | } |
212 | 223 | } |
0 commit comments