use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class MuleServiceManagerTestCase method stopsServicesAfterStartFail.
@Test
public void stopsServicesAfterStartFail() throws Exception {
StartableStoppableService firstService = mock(StartableStoppableService.class);
StartableStoppableService secondService = mock(StartableStoppableService.class);
Exception firstStartFailure = new RuntimeException();
doThrow(firstStartFailure).when(firstService).start();
final ServiceDiscoverer serviceDiscoverer = mock(ServiceDiscoverer.class);
final List<Pair<ArtifactClassLoader, Service>> services = new ArrayList<>();
Pair<ArtifactClassLoader, Service> service1Pairs = new Pair(mock(ArtifactClassLoader.class), firstService);
Pair<ArtifactClassLoader, Service> service2Pairs = new Pair(mock(ArtifactClassLoader.class), secondService);
services.add(service1Pairs);
services.add(service2Pairs);
when(serviceDiscoverer.discoverServices()).thenReturn(services);
final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
try {
muleServiceManager.start();
fail();
} catch (Exception e) {
assertThat(e.getCause(), sameInstance(firstStartFailure));
}
muleServiceManager.stop();
verify(secondService, never()).stop();
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class MuleServiceManagerTestCase method startServices.
@Test
public void startServices() throws Exception {
final ServiceDiscoverer serviceDiscoverer = mock(ServiceDiscoverer.class);
final List<Pair<ArtifactClassLoader, Service>> services = new ArrayList<>();
Pair<ArtifactClassLoader, Service> service1 = new Pair(mock(ArtifactClassLoader.class), mock(StartableService.class));
Pair<ArtifactClassLoader, Service> service2 = new Pair(mock(ArtifactClassLoader.class), mock(StartableService.class));
services.add(service1);
services.add(service2);
when(serviceDiscoverer.discoverServices()).thenReturn(services);
final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
muleServiceManager.start();
InOrder inOrder = inOrder(service1.getSecond(), service2.getSecond());
inOrder.verify((StartableService) service1.getSecond()).start();
inOrder.verify((StartableService) service2.getSecond()).start();
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class TestBootstrapServiceDiscovererConfigurationBuilder method getArtifactBootstrapService.
private List<BootstrapService> getArtifactBootstrapService(Object artifactClassLoader) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
// Uses reflection to access the class loader as classes were loaded from different class loaders so they cannot be casted
ClassLoader classLoader = (ClassLoader) artifactClassLoader.getClass().getMethod("getClassLoader").invoke(artifactClassLoader);
final Enumeration<URL> resources = (Enumeration<URL>) classLoader.getClass().getMethod("findResources", String.class).invoke(classLoader, BOOTSTRAP_PROPERTIES);
final List<BootstrapService> bootstrapServices = new ArrayList<>();
if (resources.hasMoreElements()) {
while (resources.hasMoreElements()) {
final URL localResource = resources.nextElement();
final Properties properties = PropertiesUtils.loadProperties(localResource);
final PropertiesBootstrapService propertiesBootstrapService = new PropertiesBootstrapService(classLoader, properties);
bootstrapServices.add(propertiesBootstrapService);
}
}
return bootstrapServices;
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class ArtifactClassLoaderRunner method injectPluginsClassLoaders.
/**
* Invokes the method to inject the plugin class loaders as the test is annotated with {@link PluginClassLoadersAware}.
*
* @param artifactClassLoaderHolder the result {@link ArtifactClassLoader}s defined for container, plugins and application
* @param isolatedTestClass the test {@link Class} loaded with the isolated {@link ClassLoader}
* @throws IllegalStateException if the test doesn't have an annotated method to inject plugin class loaders or if it has more
* than one method annotated.
* @throws Throwable if an error ocurrs while setting the list of {@link ArtifactClassLoader}s for plugins.
*/
private static void injectPluginsClassLoaders(ArtifactClassLoaderHolder artifactClassLoaderHolder, Class<?> isolatedTestClass) throws Throwable {
final Class<PluginClassLoadersAware> pluginClassLoadersAwareClass = PluginClassLoadersAware.class;
final String expectedParamType = "List<" + ArtifactClassLoader.class + ">";
final FrameworkMethod method = getAnnotatedMethod(artifactClassLoaderHolder, isolatedTestClass, pluginClassLoadersAwareClass, expectedParamType);
final Object valueToInject = artifactClassLoaderHolder.getPluginsClassLoaders();
doFieldInjection(pluginClassLoadersAwareClass, method, valueToInject, expectedParamType);
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader 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