Search in sources :

Example 1 with ResourceReleaser

use of org.mule.runtime.module.artifact.api.classloader.ResourceReleaser in project mule by mulesoft.

the class ResourceReleaserTestCase method ensureResourceReleaserIsCreatedByCorrectClassLoader.

private void ensureResourceReleaserIsCreatedByCorrectClassLoader(MuleArtifactClassLoader classLoader) throws Exception {
    assertThat(classLoader.getClass().getClassLoader(), is(Thread.currentThread().getContextClassLoader()));
    classLoader.setResourceReleaserClassLocation(TEST_RESOURCE_RELEASER_CLASS_LOCATION);
    classLoader.dispose();
    // We must call the getClassLoader method from TestResourceReleaser dynamically in order to not load the
    // class by the current class loader, if not a java.lang.LinkageError is raised.
    ResourceReleaser resourceReleaserInstance = ((KeepResourceReleaserInstance) classLoader).getResourceReleaserInstance();
    Method getClassLoaderMethod = resourceReleaserInstance.getClass().getMethod("getClassLoader");
    ClassLoader resourceReleaserInstanceClassLoader = (ClassLoader) getClassLoaderMethod.invoke(resourceReleaserInstance);
    assertThat(resourceReleaserInstanceClassLoader, is((ClassLoader) classLoader));
}
Also used : DefaultResourceReleaser(org.mule.module.artifact.classloader.DefaultResourceReleaser) ResourceReleaser(org.mule.runtime.module.artifact.api.classloader.ResourceReleaser) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) Method(java.lang.reflect.Method)

Example 2 with ResourceReleaser

use of org.mule.runtime.module.artifact.api.classloader.ResourceReleaser in project mule by mulesoft.

the class ResourceReleaserTestCase method createsInstanceOnlyOnce.

@Test
public void createsInstanceOnlyOnce() {
    TestArtifactClassLoader testArtifactClassLoader = new TestArtifactClassLoader(Thread.currentThread().getContextClassLoader());
    ResourceReleaser firstInstance = testArtifactClassLoader.createResourceReleaserInstance();
    ResourceReleaser secondInstance = testArtifactClassLoader.createResourceReleaserInstance();
    assertThat(firstInstance, sameInstance(secondInstance));
}
Also used : DefaultResourceReleaser(org.mule.module.artifact.classloader.DefaultResourceReleaser) ResourceReleaser(org.mule.runtime.module.artifact.api.classloader.ResourceReleaser) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

DefaultResourceReleaser (org.mule.module.artifact.classloader.DefaultResourceReleaser)2 ResourceReleaser (org.mule.runtime.module.artifact.api.classloader.ResourceReleaser)2 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)1 SmallTest (org.mule.tck.size.SmallTest)1