Search in sources :

Example 1 with Chain

use of org.mule.runtime.extension.api.runtime.route.Chain in project mule by mulesoft.

the class NestedProcessorValueResolverTestCase method yieldsNestedProcessor.

@Test
public void yieldsNestedProcessor() throws Exception {
    ProcessorChainValueResolver resolver = new ProcessorChainValueResolver(muleContext, messageProcessor);
    final CoreEvent event = testEvent();
    Chain nestedProcessor = resolver.resolve(ValueResolvingContext.from(event));
    nestedProcessor.process(result -> {
        assertThat(result.getOutput(), is(TEST_PAYLOAD));
        ArgumentCaptor<CoreEvent> captor = ArgumentCaptor.forClass(CoreEvent.class);
        try {
            verify(messageProcessor).process(captor.capture());
        } catch (MuleException e) {
            throw new RuntimeException(e);
        }
        CoreEvent capturedEvent = captor.getValue();
        assertThat(capturedEvent, is(event));
    }, (e, r) -> fail(e.getMessage()));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Chain(org.mule.runtime.extension.api.runtime.route.Chain) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 2 with Chain

use of org.mule.runtime.extension.api.runtime.route.Chain in project mule by mulesoft.

the class HeisenbergRouters method concurrentRouteExecutor.

public void concurrentRouteExecutor(WhenRoute when, RouterCompletionCallback callback) {
    Consumer<Chain> processor = (chain) -> {
        final Latch latch = new Latch();
        chain.process((result -> latch.release()), (error, result) -> latch.release());
        try {
            latch.await(10000, MILLISECONDS);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
    Thread first = new Thread(() -> processor.accept(when.getChain()));
    Thread second = new Thread(() -> processor.accept(when.getChain()));
    first.start();
    second.start();
    try {
        first.join();
        second.join();
    } catch (Exception e) {
        callback.error(e);
    }
    callback.success(Result.builder().output("SUCCESS").build());
}
Also used : Summary(org.mule.runtime.extension.api.annotation.param.display.Summary) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Attribute(org.mule.test.heisenberg.extension.model.Attribute) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) OtherwiseRoute(org.mule.test.heisenberg.extension.route.OtherwiseRoute) RouterCompletionCallback(org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback) DrugKillingRoute(org.mule.test.heisenberg.extension.route.DrugKillingRoute) AfterCall(org.mule.test.heisenberg.extension.route.AfterCall) Collectors.toMap(java.util.stream.Collectors.toMap) MuleException(org.mule.runtime.api.exception.MuleException) BeforeCall(org.mule.test.heisenberg.extension.route.BeforeCall) Map(java.util.Map) Chain(org.mule.runtime.extension.api.runtime.route.Chain) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) Optional(org.mule.runtime.extension.api.annotation.param.Optional) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) Disposable(org.mule.runtime.api.lifecycle.Disposable) Startable(org.mule.runtime.api.lifecycle.Startable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Result(org.mule.runtime.extension.api.runtime.operation.Result) Consumer(java.util.function.Consumer) Latch(org.mule.runtime.api.util.concurrent.Latch) List(java.util.List) WhenRoute(org.mule.test.heisenberg.extension.route.WhenRoute) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) NullSafe(org.mule.runtime.extension.api.annotation.param.NullSafe) KillingRoute(org.mule.test.heisenberg.extension.route.KillingRoute) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) Expression(org.mule.runtime.extension.api.annotation.Expression) Chain(org.mule.runtime.extension.api.runtime.route.Chain) Latch(org.mule.runtime.api.util.concurrent.Latch) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 3 with Chain

use of org.mule.runtime.extension.api.runtime.route.Chain in project mule by mulesoft.

the class NestedProcessorValueResolverTestCase method alwaysGivesDifferentInstances.

@Test
public void alwaysGivesDifferentInstances() throws Exception {
    ProcessorChainValueResolver resolver = new ProcessorChainValueResolver(muleContext, messageProcessor);
    Chain resolved1 = resolver.resolve(ValueResolvingContext.from(testEvent()));
    Chain resolved2 = resolver.resolve(ValueResolvingContext.from(testEvent()));
    assertThat(resolved1, is(not(sameInstance(resolved2))));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Chain(org.mule.runtime.extension.api.runtime.route.Chain) Test(org.junit.Test)

Aggregations

Chain (org.mule.runtime.extension.api.runtime.route.Chain)3 Test (org.junit.Test)2 MuleException (org.mule.runtime.api.exception.MuleException)2 MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)2 List (java.util.List)1 Map (java.util.Map)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 Consumer (java.util.function.Consumer)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 Disposable (org.mule.runtime.api.lifecycle.Disposable)1 Initialisable (org.mule.runtime.api.lifecycle.Initialisable)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 Startable (org.mule.runtime.api.lifecycle.Startable)1 Stoppable (org.mule.runtime.api.lifecycle.Stoppable)1 NOT_SUPPORTED (org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED)1 Preconditions.checkArgument (org.mule.runtime.api.util.Preconditions.checkArgument)1 Latch (org.mule.runtime.api.util.concurrent.Latch)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 Expression (org.mule.runtime.extension.api.annotation.Expression)1