Search in sources :

Example 6 with RoutingPair

use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair 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 7 with RoutingPair

use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method errorEager.

@Test
@Description("When configured with delayErrors='false' the first errors causes strategy to throw this exception.")
public void errorEager() throws Throwable {
    strategy = createStrategy(processingStrategy, 1, false, MAX_VALUE);
    Processor processorSpy = createProcessorSpy(of(1));
    RuntimeException exception = new IllegalStateException();
    RoutingPair failingPair = of(testEvent(), createFailingRoutingPair(exception));
    RoutingPair okPair = of(testEvent(), createChain(processorSpy));
    expectedException.expect(instanceOf(MessagingException.class));
    expectedException.expectCause(is(exception));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair, okPair), throwable -> verify(processorSpy, never()).process(any(CoreEvent.class)));
}
Also used : ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 8 with RoutingPair

use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method errorEagerConcurrent.

@Test
@Description("When configured with delayErrors='false' the first errors causes strategy to throw this exception. Other routes may or may not be executed depending on concurrency.")
public void errorEagerConcurrent() throws Throwable {
    strategy = createStrategy(processingStrategy, 4, false, MAX_VALUE);
    Processor processorSpy = createProcessorSpy(of(1));
    Processor processorSpy2 = createProcessorSpy(of(2));
    Processor processorSpy3 = createProcessorSpy(of(3));
    CoreEvent orignial = testEvent();
    RuntimeException exception = new IllegalStateException();
    RoutingPair failingPair = of(orignial, createFailingRoutingPair(exception));
    RoutingPair okPair = of(orignial, createChain(processorSpy));
    RoutingPair okPair2 = of(orignial, createChain(processorSpy2));
    RoutingPair okPair3 = of(orignial, createChain(processorSpy3));
    expectedException.expect(instanceOf(MessagingException.class));
    expectedException.expectCause(is(exception));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair, okPair, okPair2, okPair3), throwable -> {
        verify(processorSpy, atMost(1)).process(any(CoreEvent.class));
        verify(processorSpy2, atMost(1)).process(any(CoreEvent.class));
        verify(processorSpy3, atMost(1)).process(any(CoreEvent.class));
    });
}
Also used : ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 9 with RoutingPair

use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method timeoutDelayed.

@Test
@Description("When a route timeout occurs all routes are still executed and  a CompositeRoutingException is thrown with details of timeout error and successful routes in RoutingResult.")
public void timeoutDelayed() throws Throwable {
    strategy = createStrategy(processingStrategy, 1, true, 50);
    Message pair2Result = of(2);
    Processor pair2Processor = createProcessorSpy(pair2Result);
    RoutingPair pair2 = of(testEvent(), createChain(pair2Processor));
    expectedException.expect(instanceOf(CompositeRoutingException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250), pair2), throwable -> {
        verify(pair2Processor, times(1)).process(any(CoreEvent.class));
        CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 1);
        RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 1, 1);
        assertThat(routingResult.getFailures().get("0").getCause(), instanceOf(TimeoutException.class));
        assertThat(routingResult.getResults().get("1"), is(pair2Result));
    });
}
Also used : CompositeRoutingException(org.mule.runtime.core.privileged.routing.CompositeRoutingException) RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) TimeoutException(java.util.concurrent.TimeoutException) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 10 with RoutingPair

use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair in project mule by mulesoft.

the class CollectMapForkJoinStrategyTestCase method collectMap.

@Test
@Description("This strategy waits for all routes to return and then collects results into a map where the key of each entry is the string representation of the index of the routing pair.")
public void collectMap() throws Throwable {
    Message route1Result = of(1);
    Message route2Result = of(2);
    Message route3Result = of(3);
    RoutingPair pair1 = createRoutingPair(route1Result);
    RoutingPair pair2 = createRoutingPair(route2Result);
    RoutingPair pair3 = createRoutingPair(route3Result);
    CoreEvent result = invokeStrategyBlocking(strategy, testEvent(), asList(pair1, pair2, pair3));
    assertThat(result.getMessage().getPayload().getValue(), instanceOf(Map.class));
    Map<String, Message> resultMap = (Map<String, Message>) result.getMessage().getPayload().getValue();
    assertThat(resultMap.entrySet(), hasSize(3));
    assertThat(resultMap.get("0"), is(route1Result));
    assertThat(resultMap.get("1"), is(route2Result));
    assertThat(resultMap.get("2"), is(route3Result));
}
Also used : Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Map(java.util.Map) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

Description (io.qameta.allure.Description)12 Test (org.junit.Test)12 RoutingPair (org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair)12 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)9 Processor (org.mule.runtime.core.api.processor.Processor)7 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)6 InternalProcessor (org.mule.runtime.core.privileged.processor.InternalProcessor)6 Message (org.mule.runtime.api.message.Message)5 CompositeRoutingException (org.mule.runtime.core.privileged.routing.CompositeRoutingException)4 RoutingResult (org.mule.runtime.core.privileged.routing.RoutingResult)4 List (java.util.List)3 TimeoutException (java.util.concurrent.TimeoutException)3 Arrays.asList (java.util.Arrays.asList)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)2 MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)2 Feature (io.qameta.allure.Feature)1 MAX_VALUE (java.lang.Integer.MAX_VALUE)1 Thread.sleep (java.lang.Thread.sleep)1 ArrayList (java.util.ArrayList)1