Search in sources :

Example 51 with ArtifactClassLoader

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

the class FileSystemServiceProviderDiscovererTestCase method detectsCorruptServiceFile.

@Test(expected = ServiceResolutionError.class)
public void detectsCorruptServiceFile() throws Exception {
    installCorruptedService("fooService", FooServiceProvider.class);
    ArtifactClassLoader serviceClassLoader = mock(ArtifactClassLoader.class);
    when(serviceClassLoaderFactory.create(argThat(any(String.class)), argThat(any(ServiceDescriptor.class)), argThat(any(ClassLoader.class)), argThat(any(ClassLoaderLookupPolicy.class)))).thenReturn(serviceClassLoader);
    final FileSystemServiceProviderDiscoverer serviceProviderDiscoverer = new FileSystemServiceProviderDiscoverer(containerClassLoader, serviceClassLoaderFactory, descriptorLoaderRepository, builder());
    serviceProviderDiscoverer.discover();
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) Test(org.junit.Test)

Example 52 with ArtifactClassLoader

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

the class MuleServiceManagerTestCase method registerServices.

@Test
public void registerServices() 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(Service.class));
    Pair<ArtifactClassLoader, Service> service2 = new Pair(mock(ArtifactClassLoader.class), mock(Service.class));
    services.add(service1);
    services.add(service2);
    when(serviceDiscoverer.discoverServices()).thenReturn(services);
    final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
    muleServiceManager.start();
    assertThat(muleServiceManager.getServices().size(), equalTo(2));
    assertThat(muleServiceManager.getServices().get(0), equalTo(service1.getSecond()));
    assertThat(muleServiceManager.getServices().get(1), equalTo(service2.getSecond()));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArrayList(java.util.ArrayList) Service(org.mule.runtime.api.service.Service) ServiceDiscoverer(org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer) Pair(org.mule.runtime.api.util.Pair) Test(org.junit.Test)

Example 53 with ArtifactClassLoader

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

the class MuleServiceManagerTestCase method stopsOnlyStoppableServices.

@Test
public void stopsOnlyStoppableServices() throws Exception {
    final ServiceDiscoverer serviceDiscoverer = mock(ServiceDiscoverer.class);
    final List<Pair<ArtifactClassLoader, Service>> services = new ArrayList<>();
    Pair<ArtifactClassLoader, Service> service1Pairs = new Pair(mock(ArtifactClassLoader.class), mock(StoppableService.class));
    Pair<ArtifactClassLoader, Service> service2Pairs = new Pair(mock(ArtifactClassLoader.class), mock(StoppableService.class));
    services.add(service1Pairs);
    services.add(service2Pairs);
    when(serviceDiscoverer.discoverServices()).thenReturn(services);
    final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
    muleServiceManager.start();
    muleServiceManager.stop();
    InOrder inOrder = inOrder(service1Pairs.getSecond(), service2Pairs.getSecond());
    inOrder.verify((StoppableService) service2Pairs.getSecond()).stop();
    inOrder.verify((StoppableService) service1Pairs.getSecond()).stop();
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) Service(org.mule.runtime.api.service.Service) ServiceDiscoverer(org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer) Pair(org.mule.runtime.api.util.Pair) Test(org.junit.Test)

Example 54 with ArtifactClassLoader

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

the class MuleServiceManagerTestCase method stopsStartableStoppableServices.

@Test
public void stopsStartableStoppableServices() throws Exception {
    final ServiceDiscoverer serviceDiscoverer = mock(ServiceDiscoverer.class);
    final List<Pair<ArtifactClassLoader, Service>> services = new ArrayList<>();
    Pair<ArtifactClassLoader, Service> service1Pairs = new Pair(mock(ArtifactClassLoader.class), mock(StartableStoppableService.class));
    Pair<ArtifactClassLoader, Service> service2Pairs = new Pair(mock(ArtifactClassLoader.class), mock(StartableStoppableService.class));
    services.add(service1Pairs);
    services.add(service2Pairs);
    when(serviceDiscoverer.discoverServices()).thenReturn(services);
    final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
    muleServiceManager.start();
    muleServiceManager.stop();
    InOrder inOrder = inOrder(service1Pairs.getSecond(), service2Pairs.getSecond());
    inOrder.verify((StartableStoppableService) service2Pairs.getSecond()).stop();
    inOrder.verify((StartableStoppableService) service1Pairs.getSecond()).stop();
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) Service(org.mule.runtime.api.service.Service) ServiceDiscoverer(org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer) Pair(org.mule.runtime.api.util.Pair) Test(org.junit.Test)

Example 55 with ArtifactClassLoader

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

the class MuleServiceManager method startServices.

private void startServices() throws MuleException {
    for (Pair<ArtifactClassLoader, Service> pair : registeredServices) {
        Service service = pair.getSecond();
        if (service instanceof Startable) {
            ClassLoader originalContextClassLoader = currentThread().getContextClassLoader();
            try {
                currentThread().setContextClassLoader(service.getClass().getClassLoader());
                ((Startable) service).start();
                startedServices.add(service);
                if (isNotEmpty(service.getSplashMessage())) {
                    logger.info(new ServiceSplashScreen(service).toString());
                }
            } finally {
                currentThread().setContextClassLoader(originalContextClassLoader);
            }
        }
    }
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) Startable(org.mule.runtime.api.lifecycle.Startable) Service(org.mule.runtime.api.service.Service) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)

Aggregations

ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)58 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)17 URL (java.net.URL)12 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)12 Pair (org.mule.runtime.api.util.Pair)10 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)10 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)10 Service (org.mule.runtime.api.service.Service)8 SmallTest (org.mule.tck.size.SmallTest)8 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)7 Map (java.util.Map)6 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)6 File (java.io.File)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 MuleModule (org.mule.runtime.container.api.MuleModule)5 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)5 HashSet (java.util.HashSet)4