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));
}
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));
}
Aggregations