Search in sources :

Example 11 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class SplitAggregateScopeTestCase method routingPairs.

@Test
@Description("RoutingPairs are created for each route configured. Each RoutingPair has the same input event.")
public void routingPairs() throws Exception {
    CoreEvent event = createListEvent();
    MessageProcessorChain nested = mock(MessageProcessorChain.class);
    muleContext.getInjector().inject(router);
    router.setMessageProcessors(singletonList(nested));
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    List<RoutingPair> routingPairs = from(router.getRoutingPairs(event)).collectList().block();
    assertThat(routingPairs, hasSize(2));
    assertThat(routingPairs.get(0).getEvent().getMessage().getPayload().getValue(), equalTo(((List<Message>) event.getMessage().getPayload().getValue()).get(0)));
    assertThat(routingPairs.get(0).getRoute(), sameInstance(nested));
    assertThat(routingPairs.get(1).getEvent().getMessage().getPayload().getValue(), equalTo(((List<Message>) event.getMessage().getPayload().getValue()).get(1)));
    assertThat(routingPairs.get(1).getRoute(), sameInstance(nested));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 12 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method createChain.

private MessageProcessorChain createChain(Processor processor) throws MuleException {
    MessageProcessorChain chain = newChain(Optional.empty(), processor);
    chain.setMuleContext(muleContext);
    return chain;
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)

Example 13 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class CompositeProcessorChainRouterTestCase method simpleChain.

@Test
@Description("Ensure that with simple chains both chains are executed consecutively with the result of the first chain being used for the second chain.")
public void simpleChain() throws Exception {
    Message chain1Out = of(1);
    Message chain2Out = of(2);
    AtomicReference<Message> chain1In = new AtomicReference<>();
    AtomicReference<Message> chain2In = new AtomicReference<>();
    MessageProcessorChain chain1 = newChain(empty(), event -> {
        chain1In.set(event.getMessage());
        return builder(event).message(chain1Out).build();
    });
    MessageProcessorChain chain2 = newChain(empty(), event -> {
        chain2In.set(event.getMessage());
        return builder(event).message(chain2Out).build();
    });
    chainRouter = createCompositeProcessorChainRouter(chain1, chain2);
    Message result = chainRouter.execute(testEvent()).get().getMessage();
    assertThat(chain1In.get(), equalTo(testEvent().getMessage()));
    assertThat(chain2In.get(), equalTo(chain1Out));
    assertThat(result, equalTo(chain2Out));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Message(org.mule.runtime.api.message.Message) AtomicReference(java.util.concurrent.atomic.AtomicReference) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 14 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class MessageProcessors method newChain.

/**
 * Creates a new {@link MessageProcessorChain} from a {@link List} of {@link Processor}'s. Note that this performs chains
 * construction but will not inject {@link MuleContext} or perform any lifecycle.
 *
 * @param processingStrategy the processing strategy to use for configuring the chain. It may be {@link Optional#empty()}.
 * @param processors list of processors to construct chains from.
 * @return new {@link MessageProcessorChain} instance.
 */
public static MessageProcessorChain newChain(Optional<ProcessingStrategy> processingStrategy, List<Processor> processors) {
    if (processors.size() == 1 && processors.get(0) instanceof MessageProcessorChain) {
        return (MessageProcessorChain) processors.get(0);
    } else {
        DefaultMessageProcessorChainBuilder defaultMessageProcessorChainBuilder = new DefaultMessageProcessorChainBuilder();
        processingStrategy.ifPresent(defaultMessageProcessorChainBuilder::setProcessingStrategy);
        return defaultMessageProcessorChainBuilder.chain(processors).build();
    }
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)

Example 15 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class AbstractOutboundRouter method doProcessRoute.

protected CoreEvent doProcessRoute(Processor route, CoreEvent event) throws MuleException {
    if (route instanceof MessageProcessorChain) {
        return route.process(event);
    } else {
        // MULE-13028 All routers should use processor chains rather than processors as their routes
        MessageProcessorChain chain = processorChainCache.getIfPresent(route);
        if (chain == null) {
            chain = newChain(getProcessingStrategy(locator, getRootContainerLocation()), route);
            initialiseObject(chain);
            processorChainCache.put(route, chain);
        }
        return chain.process(event);
    }
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)

Aggregations

MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)22 Test (org.junit.Test)14 Description (io.qameta.allure.Description)11 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)11 Message (org.mule.runtime.api.message.Message)7 Event (org.mule.runtime.api.event.Event)6 Processor (org.mule.runtime.core.api.processor.Processor)5 ArrayList (java.util.ArrayList)4 Collections.singletonList (java.util.Collections.singletonList)4 List (java.util.List)4 Collections.singletonMap (java.util.Collections.singletonMap)3 Map (java.util.Map)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 RoutingPair (org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair)2 DefaultMessageProcessorChainBuilder (org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder)2 MessageProcessorChainBuilder (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder)2 TestMessageProcessor (org.mule.tck.testmodels.mule.TestMessageProcessor)2 StringBufferInputStream (java.io.StringBufferInputStream)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeoutException (java.util.concurrent.TimeoutException)1