Home / Class/ NativeLibraryLoaderTest Class — netty Architecture

NativeLibraryLoaderTest Class — netty Architecture

Architecture documentation for the NativeLibraryLoaderTest class in NativeLibraryLoaderTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9022161d_835d_6545_8d58_577531ba9962["NativeLibraryLoaderTest"]
  862275ce_e281_638b_6ecd_11ab447ddbc8["NativeLibraryLoaderTest.java"]
  9022161d_835d_6545_8d58_577531ba9962 -->|defined in| 862275ce_e281_638b_6ecd_11ab447ddbc8
  f418a68b_cdf4_fc70_3f33_f5c02cb0635e["is_x86_64()"]
  9022161d_835d_6545_8d58_577531ba9962 -->|method| f418a68b_cdf4_fc70_3f33_f5c02cb0635e
  cc6011d2_401b_96a6_2499_c8f40559f7ae["testFileNotFound()"]
  9022161d_835d_6545_8d58_577531ba9962 -->|method| cc6011d2_401b_96a6_2499_c8f40559f7ae
  8a38fdd9_2046_bbba_06e6_8c508406f22d["testFileNotFoundWithNullClassLoader()"]
  9022161d_835d_6545_8d58_577531ba9962 -->|method| 8a38fdd9_2046_bbba_06e6_8c508406f22d
  977e8b08_c2ee_bc0c_3c19_10f1f257cb7f["testMultipleResourcesWithSameContentInTheClassLoader()"]
  9022161d_835d_6545_8d58_577531ba9962 -->|method| 977e8b08_c2ee_bc0c_3c19_10f1f257cb7f
  f7852746_d84d_00a9_4e7c_ac32d912b0c5["testMultipleResourcesInTheClassLoader()"]
  9022161d_835d_6545_8d58_577531ba9962 -->|method| f7852746_d84d_00a9_4e7c_ac32d912b0c5
  36cab0b1_1c27_000e_19c5_1b5da6706e2e["testSingleResourceInTheClassLoader()"]
  9022161d_835d_6545_8d58_577531ba9962 -->|method| 36cab0b1_1c27_000e_19c5_1b5da6706e2e
  16ab795c_038b_768e_7f5a_8ded66ddd4af["verifySuppressedException()"]
  9022161d_835d_6545_8d58_577531ba9962 -->|method| 16ab795c_038b_768e_7f5a_8ded66ddd4af

Relationship Graph

Source Code

common/src/test/java/io/netty/util/internal/NativeLibraryLoaderTest.java lines 35–122

class NativeLibraryLoaderTest {

    private static final String OS_ARCH = System.getProperty("os.arch");
    private boolean is_x86_64() {
        return "x86_64".equals(OS_ARCH) || "amd64".equals(OS_ARCH);
    }

    @Test
    void testFileNotFound() {
        try {
            NativeLibraryLoader.load(UUID.randomUUID().toString(), NativeLibraryLoaderTest.class.getClassLoader());
            fail();
        } catch (UnsatisfiedLinkError error) {
            assertTrue(error.getCause() instanceof FileNotFoundException);
            verifySuppressedException(error, UnsatisfiedLinkError.class);
        }
    }

    @Test
    void testFileNotFoundWithNullClassLoader() {
        try {
            NativeLibraryLoader.load(UUID.randomUUID().toString(), null);
            fail();
        } catch (UnsatisfiedLinkError error) {
            assertTrue(error.getCause() instanceof FileNotFoundException);
            verifySuppressedException(error, ClassNotFoundException.class);
        }
    }

    @Test
    @EnabledOnOs(LINUX)
    @EnabledIf("is_x86_64")
    void testMultipleResourcesWithSameContentInTheClassLoader() throws MalformedURLException {
        URL url1 = new File("src/test/data/NativeLibraryLoader/1").toURI().toURL();
        URL url2 = new File("src/test/data/NativeLibraryLoader/2").toURI().toURL();
        final URLClassLoader loader = new URLClassLoader(new URL[] {url1, url2});
        final String resourceName = "test3";

        NativeLibraryLoader.load(resourceName, loader);
        assertTrue(true);
    }

    @Test
    @EnabledOnOs(LINUX)
    @EnabledIf("is_x86_64")
    void testMultipleResourcesInTheClassLoader() throws MalformedURLException {
        URL url1 = new File("src/test/data/NativeLibraryLoader/1").toURI().toURL();
        URL url2 = new File("src/test/data/NativeLibraryLoader/2").toURI().toURL();
        final URLClassLoader loader = new URLClassLoader(new URL[] {url1, url2});
        final String resourceName = "test1";

        Exception ise = assertThrows(IllegalStateException.class, new Executable() {
            @Override
            public void execute() {
                NativeLibraryLoader.load(resourceName, loader);
            }
        });
        assertTrue(ise.getMessage()
                    .contains("Multiple resources found for 'META-INF/native/lib" + resourceName + ".so'"));
    }

    @Test
    @EnabledOnOs(LINUX)
    @EnabledIf("is_x86_64")
    void testSingleResourceInTheClassLoader() throws MalformedURLException {
        URL url1 = new File("src/test/data/NativeLibraryLoader/1").toURI().toURL();
        URL url2 = new File("src/test/data/NativeLibraryLoader/2").toURI().toURL();
        URLClassLoader loader = new URLClassLoader(new URL[] {url1, url2});
        String resourceName = "test2";

        NativeLibraryLoader.load(resourceName, loader);
        assertTrue(true);
    }

    private static void verifySuppressedException(UnsatisfiedLinkError error,
            Class<?> expectedSuppressedExceptionClass) {
        try {
            Throwable[] suppressed = error.getCause().getSuppressed();
            assertTrue(suppressed.length == 1);
            assertTrue(suppressed[0] instanceof UnsatisfiedLinkError);
            suppressed = (suppressed[0]).getSuppressed();

Frequently Asked Questions

What is the NativeLibraryLoaderTest class?
NativeLibraryLoaderTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/internal/NativeLibraryLoaderTest.java.
Where is NativeLibraryLoaderTest defined?
NativeLibraryLoaderTest is defined in common/src/test/java/io/netty/util/internal/NativeLibraryLoaderTest.java at line 35.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free