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