use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class FileSystemServiceProviderDiscovererTestCase method discoversServices.
@Test
public void discoversServices() throws Exception {
installService("fooService", FooServiceProvider.class);
installService("barService", BarServiceProvider.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());
final List<Pair<ArtifactClassLoader, ServiceProvider>> serviceProvidersPairs = serviceProviderDiscoverer.discover();
List<ServiceProvider> serviceProviders = serviceProvidersPairs.stream().map(Pair::getSecond).collect(Collectors.toList());
assertThat(serviceProviders.size(), equalTo(2));
assertThat(serviceProviders, hasItem(instanceOf(FooServiceProvider.class)));
assertThat(serviceProviders, hasItem(instanceOf(BarServiceProvider.class)));
}
use of org.mule.runtime.api.util.Pair 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.api.util.Pair 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.api.util.Pair 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.api.util.Pair 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));
}
Aggregations