use of org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader 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.MuleArtifactClassLoader in project mule by mulesoft.
the class ArtifactAwareContextSelectorTestCase method returnsMuleLoggerContextForInternalArtifactClassLoader.
@Test
public void returnsMuleLoggerContextForInternalArtifactClassLoader() {
ArtifactClassLoader serviceClassLoader = new MuleArtifactClassLoader("test", new ApplicationDescriptor("test"), new URL[0], this.getClass().getClassLoader(), mock(ClassLoaderLookupPolicy.class));
LoggerContext systemContext = selector.getContext("", this.getClass().getClassLoader(), true);
LoggerContext serviceCtx = selector.getContext("", serviceClassLoader.getClassLoader(), true);
assertThat(serviceCtx, instanceOf(MuleLoggerContext.class));
assertThat(serviceCtx, sameInstance(systemContext));
}
use of org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader in project mule by mulesoft.
the class ServiceClassLoaderFactoryTestCase method usesClassLoaderLookupPolicy.
@Test
public void usesClassLoaderLookupPolicy() throws Exception {
final ArtifactClassLoader artifactClassLoader = factory.create(SERVICE_ID, descriptor, getClass().getClassLoader(), lookupPolicy);
final MuleArtifactClassLoader classLoader = (MuleArtifactClassLoader) artifactClassLoader.getClassLoader();
final String className = "com.dummy.Foo";
try {
classLoader.loadClass(className);
fail("Able to load an un-existent class");
} catch (ClassNotFoundException e) {
// Expected
}
verify(lookupPolicy).getClassLookupStrategy(className);
}
use of org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader in project mule by mulesoft.
the class ServiceClassLoaderFactoryTestCase method createsEmptyClassLoader.
@Test
public void createsEmptyClassLoader() throws Exception {
final ArtifactClassLoader artifactClassLoader = factory.create(SERVICE_ID, descriptor, getClass().getClassLoader(), lookupPolicy);
final MuleArtifactClassLoader classLoader = (MuleArtifactClassLoader) artifactClassLoader.getClassLoader();
assertThat(classLoader.getURLs(), equalTo(new URL[0]));
}
use of org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader in project mule by mulesoft.
the class IsolatedClassLoaderFactory method createTestRunnerPlugin.
private void createTestRunnerPlugin(ArtifactsUrlClassification artifactsUrlClassification, Map<String, LookupStrategy> appExportedLookupStrategies, ClassLoaderLookupPolicy childClassLoaderLookupPolicy, RegionClassLoader regionClassLoader, List<ArtifactClassLoader> filteredPluginsArtifactClassLoaders, List<ArtifactClassLoader> pluginsArtifactClassLoaders, List<ArtifactClassLoaderFilter> pluginArtifactClassLoaderFilters, DefaultModuleRepository moduleRepository, TestContainerClassLoaderFactory testContainerClassLoaderFactory, Set<String> parentExportedPackages) {
JarInfo testRunnerJarInfo = getTestRunnerJarInfo(artifactsUrlClassification);
String testRunnerArtifactId = getArtifactPluginId(regionClassLoader.getArtifactId(), "test-runner");
List<String> pluginDependencies = artifactsUrlClassification.getPluginUrlClassifications().stream().map(p -> p.getName()).collect(toList());
PluginUrlClassification testRunnerPluginClassification = new PluginUrlClassification(TEST_RUNNER_ARTIFACT_ID + ":", artifactsUrlClassification.getTestRunnerLibUrls(), emptyList(), pluginDependencies, testRunnerJarInfo.getPackages(), testRunnerJarInfo.getResources(), emptySet(), emptySet());
ClassLoaderLookupPolicy pluginLookupPolicy = extendLookupPolicyForPrivilegedAccess(childClassLoaderLookupPolicy, moduleRepository, testContainerClassLoaderFactory, testRunnerPluginClassification);
pluginLookupPolicy = pluginLookupPolicy.extend(appExportedLookupStrategies);
MuleArtifactClassLoader pluginCL = new MuleArtifactClassLoader(testRunnerArtifactId, new ArtifactDescriptor(testRunnerPluginClassification.getName()), testRunnerPluginClassification.getUrls().toArray(new URL[0]), regionClassLoader, pluginLookupPolicyGenerator.createLookupPolicy(testRunnerPluginClassification, artifactsUrlClassification.getPluginUrlClassifications(), pluginLookupPolicy, pluginsArtifactClassLoaders));
pluginsArtifactClassLoaders.add(pluginCL);
ArtifactClassLoaderFilter filter = createArtifactClassLoaderFilter(testRunnerPluginClassification, parentExportedPackages, childClassLoaderLookupPolicy);
pluginArtifactClassLoaderFilters.add(filter);
filteredPluginsArtifactClassLoaders.add(new FilteringArtifactClassLoader(pluginCL, filter, emptyList()));
logClassLoaderUrls("PLUGIN (" + testRunnerPluginClassification.getName() + ")", testRunnerPluginClassification.getUrls());
}
Aggregations