Search in sources :

Example 1 with ServiceDiscoverer

use of org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer in project mule by mulesoft.

the class MuleServiceManagerTestCase method ignoresServiceStopError.

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

Example 2 with ServiceDiscoverer

use of org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer 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();
}
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 3 with ServiceDiscoverer

use of org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer 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();
}
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 4 with ServiceDiscoverer

use of org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer in project mule by mulesoft.

the class MuleServiceManagerTestCase method wrapsServices.

@Test
public void wrapsServices() throws Exception {
    final ServiceDiscoverer serviceDiscoverer = mock(ServiceDiscoverer.class);
    final List<Pair<ArtifactClassLoader, Service>> services = new ArrayList<>();
    StoppableService service1 = mock(StoppableService.class);
    services.add(new Pair<>(mock(ArtifactClassLoader.class), service1));
    when(serviceDiscoverer.discoverServices()).thenReturn(services);
    final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
    muleServiceManager.start();
    assertThat(Proxy.isProxyClass(muleServiceManager.getServices().get(0).getClass()), is(true));
}
Also used : ArrayList(java.util.ArrayList) ServiceDiscoverer(org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer) Pair(org.mule.runtime.api.util.Pair) Test(org.junit.Test)

Example 5 with ServiceDiscoverer

use of org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer 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)

Aggregations

ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Pair (org.mule.runtime.api.util.Pair)7 ServiceDiscoverer (org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer)7 Service (org.mule.runtime.api.service.Service)5 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)5 InOrder (org.mockito.InOrder)4