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