Search in sources :

Example 1 with Lifecycle

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);
}
Also used : AbstractInterceptingMessageProcessor(org.mule.runtime.core.privileged.processor.AbstractInterceptingMessageProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with Lifecycle

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);
}
Also used : AbstractInterceptingMessageProcessor(org.mule.runtime.core.privileged.processor.AbstractInterceptingMessageProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with Lifecycle

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();
    }
}
Also used : Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with Lifecycle

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();
    }
}
Also used : Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with Lifecycle

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);
    }
}
Also used : Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) Method(java.lang.reflect.Method)

Aggregations

Lifecycle (org.mule.runtime.api.lifecycle.Lifecycle)5 Test (org.junit.Test)4 SmallTest (org.mule.tck.size.SmallTest)4 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)2 Processor (org.mule.runtime.core.api.processor.Processor)2 AbstractInterceptingMessageProcessor (org.mule.runtime.core.privileged.processor.AbstractInterceptingMessageProcessor)2 InternalProcessor (org.mule.runtime.core.privileged.processor.InternalProcessor)2 Method (java.lang.reflect.Method)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1