use of org.mule.runtime.api.lifecycle.Lifecycle in project mule by mulesoft.
the class DefaultMessageProcessorChainTestCase method testMPChainLifecycle.
@Test
public void testMPChainLifecycle() throws Exception {
DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
AppendingInterceptingMP mp1 = new AppendingInterceptingMP("1");
AppendingInterceptingMP mp2 = new AppendingInterceptingMP("2");
Processor chain = builder.chain(mp1, mp2).build();
initialiseIfNeeded(chain, muleContext);
((Lifecycle) chain).start();
((Lifecycle) chain).stop();
((Lifecycle) chain).dispose();
assertLifecycle(mp1);
assertLifecycle(mp2);
}
use of org.mule.runtime.api.lifecycle.Lifecycle in project mule by mulesoft.
the class DefaultMessageProcessorChainTestCase method testNestedMPChainLifecycle.
@Test
public void testNestedMPChainLifecycle() throws Exception {
DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
DefaultMessageProcessorChainBuilder nestedBuilder = new DefaultMessageProcessorChainBuilder();
AppendingInterceptingMP mp1 = new AppendingInterceptingMP("1");
AppendingInterceptingMP mp2 = new AppendingInterceptingMP("2");
AppendingInterceptingMP mpa = new AppendingInterceptingMP("a");
AppendingInterceptingMP mpb = new AppendingInterceptingMP("b");
Processor chain = builder.chain(mp1, nestedBuilder.chain(mpa, mpb).build(), mp2).build();
initialiseIfNeeded(chain, muleContext);
((Lifecycle) chain).start();
((Lifecycle) chain).stop();
((Lifecycle) chain).dispose();
assertLifecycle(mp1);
assertLifecycle(mp2);
assertLifecycle(mpa);
assertLifecycle(mpb);
}
use of org.mule.runtime.api.lifecycle.Lifecycle in project mule by mulesoft.
the class DynamicConfigurationProviderTestCase method configFailsOnStart.
@Test
public void configFailsOnStart() throws Exception {
final Lifecycle connProvider = mock(Lifecycle.class, withSettings().extraInterfaces(ConnectionProvider.class));
final RuntimeException toThrow = new RuntimeException("Start failed!");
doThrow(toThrow).when(connProvider).start();
when(connectionProviderResolver.resolve(any())).thenReturn(new Pair<>(connProvider, resolverSetResult));
expected.expectCause(sameInstance(toThrow));
try {
provider.get(event);
} finally {
verify(connProvider).initialise();
verify(connProvider).start();
verify(connProvider).stop();
verify(connProvider).dispose();
}
}
use of org.mule.runtime.api.lifecycle.Lifecycle in project mule by mulesoft.
the class DynamicConfigurationProviderTestCase method configFailsOnInitialize.
@Test
public void configFailsOnInitialize() throws Exception {
final Lifecycle connProvider = mock(Lifecycle.class, withSettings().extraInterfaces(ConnectionProvider.class));
final String expectedExceptionMessage = "Init failed!";
doThrow(new RuntimeException(expectedExceptionMessage)).when(connProvider).initialise();
when(connectionProviderResolver.resolve(any())).thenReturn(new Pair<>(connProvider, mock(ResolverSetResult.class)));
expected.expectCause(hasMessage(is(InitialisationException.class.getName() + ": " + expectedExceptionMessage)));
try {
provider.get(event);
} finally {
verify(connProvider).initialise();
verify(connProvider, never()).start();
verify(connProvider, never()).stop();
verify(connProvider).dispose();
}
}
use of org.mule.runtime.api.lifecycle.Lifecycle in project mule by mulesoft.
the class LifecycleTransitionResult method processAllNoRetry.
/**
* The logic for processing a collection of children
*
* @param iface The lifecycle interface to be called
* @param objects An iterator over all children that must also be called
* @throws LifecycleException if any fail
*/
private static void processAllNoRetry(Class<? extends Initialisable> iface, Iterator<? extends Initialisable> objects) throws LifecycleException {
if (!iface.isAssignableFrom(Lifecycle.class)) {
throw new IllegalArgumentException("Not a Lifecycle interface: " + iface);
}
Set<Method> lifecycleMethodsCandidate = getAllMethods(iface, withName(Initialisable.PHASE_NAME));
Method method = lifecycleMethodsCandidate.isEmpty() ? null : lifecycleMethodsCandidate.iterator().next();
// some interfaces have a single exception, others none
boolean hasException = method.getExceptionTypes().length > 0;
Class<?> exception = hasException ? method.getExceptionTypes()[0] : null;
while (objects.hasNext()) {
Object target = objects.next();
processSingleNoRetry(target, method, exception, iface);
}
}
Aggregations