Search in sources :

Example 1 with MuleArtifactClassLoader

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

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));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) LoggerContext(org.apache.logging.log4j.core.LoggerContext) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with MuleArtifactClassLoader

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);
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with MuleArtifactClassLoader

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]));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 5 with MuleArtifactClassLoader

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());
}
Also used : TEST_RUNNER_ARTIFACT_ID(org.mule.test.runner.RunnerConfiguration.TEST_RUNNER_ARTIFACT_ID) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) PARENT_FIRST(org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST) MuleModule(org.mule.runtime.container.api.MuleModule) DefaultArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) ContainerClassLoaderFilterFactory(org.mule.runtime.container.internal.ContainerClassLoaderFilterFactory) FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) ClassLoaderFilterFactory(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilterFactory) Map(java.util.Map) System.getProperty(java.lang.System.getProperty) JarExplorer(org.mule.runtime.module.artifact.internal.util.JarExplorer) URI(java.net.URI) MULE_LOG_VERBOSE_CLASSLOADING(org.mule.runtime.core.api.config.MuleProperties.MULE_LOG_VERBOSE_CLASSLOADING) Collectors.toSet(java.util.stream.Collectors.toSet) ArtifactClassLoaderHolder(org.mule.test.runner.api.ArtifactClassLoaderHolder) ClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) Collections.emptyList(java.util.Collections.emptyList) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) Collection(java.util.Collection) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) DefaultModuleRepository(org.mule.runtime.container.internal.DefaultModuleRepository) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) ChildFirstLookupStrategy(org.mule.runtime.module.artifact.api.classloader.ChildFirstLookupStrategy) ModuleRepository(org.mule.runtime.container.api.ModuleRepository) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) DefaultNativeLibraryFinderFactory(org.mule.runtime.deployment.model.internal.nativelib.DefaultNativeLibraryFinderFactory) ArtifactUrlClassification(org.mule.test.runner.api.ArtifactUrlClassification) ContainerClassLoaderFactory(org.mule.runtime.container.internal.ContainerClassLoaderFactory) HashMap(java.util.HashMap) MuleClassLoaderLookupPolicy(org.mule.runtime.container.internal.MuleClassLoaderLookupPolicy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PluginUrlClassification(org.mule.test.runner.api.PluginUrlClassification) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) Collections.emptyMap(java.util.Collections.emptyMap) SYSTEM_PACKAGES(org.mule.runtime.container.internal.ContainerClassLoaderFactory.SYSTEM_PACKAGES) ArtifactClassLoaderFilterFactory(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilterFactory) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) MalformedURLException(java.net.MalformedURLException) Boolean.valueOf(java.lang.Boolean.valueOf) File(java.io.File) DefaultRegionPluginClassLoadersFactory.getArtifactPluginId(org.mule.runtime.deployment.model.internal.DefaultRegionPluginClassLoadersFactory.getArtifactPluginId) Collectors.toList(java.util.stream.Collectors.toList) MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) ArtifactsUrlClassification(org.mule.test.runner.api.ArtifactsUrlClassification) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) MuleClassLoaderLookupPolicy(org.mule.runtime.container.internal.MuleClassLoaderLookupPolicy) FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) DefaultArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter) ArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter) PluginUrlClassification(org.mule.test.runner.api.PluginUrlClassification) URL(java.net.URL)

Aggregations

MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)13 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)10 Test (org.junit.Test)7 URL (java.net.URL)6 ArtifactDescriptor (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor)5 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)4 FilteringArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader)4 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)3 DefaultArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter)3 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)3 SmallTest (org.mule.tck.size.SmallTest)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MuleModule (org.mule.runtime.container.api.MuleModule)2 ContainerClassLoaderFactory (org.mule.runtime.container.internal.ContainerClassLoaderFactory)2 ContainerClassLoaderFilterFactory (org.mule.runtime.container.internal.ContainerClassLoaderFilterFactory)2 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)2 DefaultModuleRepository (org.mule.runtime.container.internal.DefaultModuleRepository)2