Search in sources :

Example 6 with MessageProcessorChain

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

the class ChoiceRouterTestCase method testUpdateRoute.

@Test
public void testUpdateRoute() throws Exception {
    MessageProcessorChain mp = newChain(empty(), new TestMessageProcessor("bar"));
    choiceRouter.addRoute(payloadPazExpression(), mp);
    choiceRouter.updateRoute(payloadZapExpression(), mp);
    choiceRouter.setMuleContext(muleContext);
    choiceRouter.initialise();
    assertThat(process(choiceRouter, zapEvent()).getMessage().getPayload().getValue(), is("zap:bar"));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) TestMessageProcessor(org.mule.tck.testmodels.mule.TestMessageProcessor) Test(org.junit.Test)

Example 7 with MessageProcessorChain

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

the class MessageProcessorChainObjectFactory method doGetObject.

@Override
public MessageProcessorChain doGetObject() throws Exception {
    MessageProcessorChainBuilder builder = getBuilderInstance();
    for (Object processor : processors) {
        if (processor instanceof Processor) {
            builder.chain((Processor) processor);
        } else {
            throw new IllegalArgumentException(format("MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured. Found a %s", processor.getClass().getName()));
        }
    }
    MessageProcessorChain messageProcessorChain = builder.build();
    messageProcessorChain.setMuleContext(muleContext);
    return messageProcessorChain;
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Processor(org.mule.runtime.core.api.processor.Processor) DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) MessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder)

Example 8 with MessageProcessorChain

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

the class CompositeProcessorChainRouterTestCase method childContextChain.

@Test
@Description("Ensure that when a child context is created as part of the execution of one of the composite chains then the chain does not complete and the next chains is not executed until the child context completes.")
public void childContextChain() throws Exception {
    Latch latch = new Latch();
    AtomicReference<BaseEventContext> childEventContext = new AtomicReference<>();
    MessageProcessorChain chainUsingChildContext = newChain(empty(), event -> {
        latch.release();
        childEventContext.set(child((BaseEventContext) event.getContext(), empty()));
        return event;
    });
    chainRouter = createCompositeProcessorChainRouter(chainUsingChildContext, newChain(empty(), event -> event));
    // CompletableFuture is not returned immediately because simply invoking CompositeProcessorChainRouter there is no async
    // hand-off and so this blocks until child context completes.
    Future<CompletableFuture<Event>> future = scheduler.submit(() -> chainRouter.execute(testEvent()));
    latch.await();
    try {
        future.get(BLOCK_TIMEOUT, MILLISECONDS);
        fail("Timeout expected");
    } catch (TimeoutException te) {
    }
    childEventContext.get().success();
    assertThat(future.get(BLOCK_TIMEOUT, MILLISECONDS).get().getMessage(), equalTo(testEvent().getMessage()));
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) CompletableFuture(java.util.concurrent.CompletableFuture) Latch(org.mule.runtime.api.util.concurrent.Latch) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeoutException(java.util.concurrent.TimeoutException) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 9 with MessageProcessorChain

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

the class FlowRefFactoryBeanTestCase method createDynamicFlowRefFactoryBean.

private FlowRefFactoryBean createDynamicFlowRefFactoryBean(Processor target, Object targetBuilder) throws InitialisationException {
    doReturn(true).when(expressionManager).isExpression(anyString());
    doReturn(PARSED_DYNAMIC_REFERENCED_FLOW).when(expressionManager).parse(eq(DYNAMIC_REFERENCED_FLOW), any(CoreEvent.class), any(ComponentLocation.class));
    if (targetBuilder != null) {
        when(applicationContext.getBean(eq(PARSED_DYNAMIC_REFERENCED_FLOW))).thenReturn(targetBuilder);
    } else {
        when(applicationContext.getBean(eq(PARSED_DYNAMIC_REFERENCED_FLOW))).thenReturn(target);
    }
    if (target instanceof MessageProcessorChain) {
        Processor processor = ((MessageProcessorChain) target).getMessageProcessors().get(0);
        when(processor.apply(any())).thenAnswer(successAnswer());
    } else {
        when(target.apply(any())).thenAnswer(successAnswer());
    }
    return createFlowRefFactoryBean(DYNAMIC_REFERENCED_FLOW);
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Example 10 with MessageProcessorChain

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

the class FlowRefFactoryBeanTestCase method dynamicFlowRefSubFlowMessageProcessorChain.

@Test
public void dynamicFlowRefSubFlowMessageProcessorChain() throws Exception {
    CoreEvent event = testEvent();
    Processor targetSubFlowConstructAware = (Processor) mock(Object.class, INITIALIZABLE_MESSAGE_PROCESSOR);
    when(targetSubFlowConstructAware.apply(any(Publisher.class))).thenReturn(just(result));
    Processor targetMuleContextAwareAware = (Processor) mock(MuleContextAware.class, INITIALIZABLE_MESSAGE_PROCESSOR);
    when(targetMuleContextAwareAware.apply(any(Publisher.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
    MessageProcessorChain targetSubFlowChain = mock(MessageProcessorChain.class, INITIALIZABLE_MESSAGE_PROCESSOR);
    when(targetSubFlowChain.apply(any(Publisher.class))).thenReturn(just(result));
    List<Processor> targetSubFlowProcessors = asList(targetSubFlowConstructAware, targetMuleContextAwareAware);
    when(targetSubFlowChain.getMessageProcessors()).thenReturn(targetSubFlowProcessors);
    SubflowMessageProcessorChainBuilder chainBuilder = new SubflowMessageProcessorChainBuilder();
    chainBuilder.chain(targetSubFlowProcessors);
    FlowRefFactoryBean flowRefFactoryBean = createDynamicFlowRefFactoryBean(targetSubFlowChain, chainBuilder);
    final Processor flowRefProcessor = getFlowRefProcessor(flowRefFactoryBean);
    just(event).transform(flowRefProcessor).block();
    verify((MuleContextAware) targetMuleContextAwareAware, atLeastOnce()).setMuleContext(mockMuleContext);
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) MuleContextAware(org.mule.runtime.core.api.context.MuleContextAware) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

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