Search in sources :

Example 11 with MuleArtifactClassLoader

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

the class PolicyTemplateClassLoaderFactoryTestCase method usesClassLoaderLookupPolicy.

@Test
public void usesClassLoaderLookupPolicy() throws Exception {
    final ArtifactClassLoader artifactClassLoader = factory.create(POLICY_ID, parentClassLoader, descriptor, emptyList());
    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) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) Matchers.anyString(org.mockito.Matchers.anyString) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 12 with MuleArtifactClassLoader

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

the class TestContainerClassLoaderFactory method createArtifactClassLoader.

/**
 * Overrides the method in order to create a {@link ArtifactClassLoader} that will have a CHILD_FIRST
 * {@link ClassLoaderLookupPolicy}, it is needed due to as difference from a mule standalone container where the parent
 * {@link ClassLoader} for the container only has bootstrap jars plugins mule modules and third-party libraries when the runner
 * runs this tests using has a full class path with all the artifacts declared as dependencies for the artifact so we have to
 * change that and change the look strategy to be CHILD_FIRST for the container.
 * <p/>
 * The {@code muleModules} parameter will be ignored due to it has all the modules in classpath, instead they are discovered
 * once again but using a {@link URLClassLoader} that has the {@link URL}'s classified for the container {@link ClassLoader}.
 *
 * @param parentClassLoader the parent {@link ClassLoader} to delegate PARENT look ups
 * @param muleModules {@link MuleModule} discovered from the launcher {@link ClassLoader} but will be not considered here due to
 *        it has all the class path
 * @param containerLookupPolicy the default {@link ClassLoaderLookupPolicy} defined for a container but will be ignored due to
 *        it has to be different when running with a full class path as parent {@link ClassLoader}
 * @param artifactDescriptor
 * @return the {@link ArtifactClassLoader} to be used for the container
 */
@Override
protected ArtifactClassLoader createArtifactClassLoader(final ClassLoader parentClassLoader, final List<MuleModule> muleModules, final ClassLoaderLookupPolicy containerLookupPolicy, ArtifactDescriptor artifactDescriptor) {
    final ArtifactDescriptor containerDescriptor = new ArtifactDescriptor("mule");
    containerClassLoader = new MuleArtifactClassLoader(containerDescriptor.getName(), containerDescriptor, urls, parentClassLoader, containerLookupPolicy);
    return createContainerFilteringClassLoader(withContextClassLoader(classLoader, () -> testContainerModuleRepository.getModules()), containerClassLoader);
}
Also used : ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)

Example 13 with MuleArtifactClassLoader

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

the class ArtifactAwareContextSelectorTestCase method returnsParentContextForPolicyClassloader.

@Test
public void returnsParentContextForPolicyClassloader() throws MalformedURLException {
    ClassLoader childClassLoader = new URLClassLoader(new URL[0], regionClassLoader);
    PolicyTemplateDescriptor policyTemplateDescriptor = new PolicyTemplateDescriptor(POLICY_TEMPLATE_NAME, empty());
    RegionClassLoader policyRegionClassLoader = spy(getPolicyRegionClassLoader(policyTemplateDescriptor));
    MuleArtifactClassLoader policyClassLoader = getPolicyArtifactClassLoader(policyTemplateDescriptor, policyRegionClassLoader);
    LoggerContext appCtx = selector.getContext("", childClassLoader, true);
    LoggerContext policyCtx = selector.getContext("", policyClassLoader, true);
    assertThat(policyCtx, sameInstance(appCtx));
}
Also used : URLClassLoader(java.net.URLClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) URLClassLoader(java.net.URLClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) LoggerContext(org.apache.logging.log4j.core.LoggerContext) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

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