Search in sources :

Example 1 with RoutingResult

use of org.mule.runtime.core.privileged.routing.RoutingResult in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method errorDelayed.

@Test
@Description("When an error occurs all routes are executed regardless and a CompositeRoutingException is thrown containing a RoutingResult with details of both failures and successes.")
public void errorDelayed() throws Throwable {
    Processor processorSpy = createProcessorSpy(testEvent().getMessage());
    RuntimeException exception1 = new IllegalStateException();
    RoutingPair failingPair1 = of(testEvent(), createFailingRoutingPair(exception1));
    RuntimeException exception2 = new UnsupportedOperationException();
    RoutingPair failingPair2 = of(testEvent(), createFailingRoutingPair(exception2));
    RuntimeException exception3 = new IndexOutOfBoundsException();
    RoutingPair failingPair3 = of(testEvent(), createFailingRoutingPair(exception3));
    RoutingPair okPair = of(testEvent(), createChain(processorSpy));
    expectedException.expect(instanceOf(CompositeRoutingException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair1, failingPair2, failingPair3, okPair), throwable -> {
        verify(processorSpy, times(1)).process(any(CoreEvent.class));
        CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 3);
        RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 1, 3);
        assertThat(routingResult.getFailures().get("0").getCause(), is(exception1));
        assertThat(routingResult.getFailures().get("1").getCause(), is(exception2));
        assertThat(routingResult.getFailures().get("2").getCause(), is(exception3));
        assertThat(routingResult.getFailures().get("3"), is(nullValue()));
    });
}
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) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 2 with RoutingResult

use of org.mule.runtime.core.privileged.routing.RoutingResult in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method error.

@Test
@Description("Errors are thrown via CompositeRoutingException with RoutingResult containing details of failures.")
public void error() throws Throwable {
    RuntimeException exception = new IllegalStateException();
    RoutingPair failingPair = of(testEvent(), createFailingRoutingPair(exception));
    expectedException.expect(instanceOf(CompositeRoutingException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair), throwable -> {
        CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 1);
        RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 0, 1);
        assertThat(routingResult.getFailures().get("0").getCause(), is(exception));
    });
}
Also used : CompositeRoutingException(org.mule.runtime.core.privileged.routing.CompositeRoutingException) RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 3 with RoutingResult

use of org.mule.runtime.core.privileged.routing.RoutingResult in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method timeout.

@Test
@Description("When a route timeout occurs a CompositeRoutingException is thrown with details of timeout error in RoutingResult.")
public void timeout() throws Throwable {
    strategy = createStrategy(processingStrategy, 1, true, 50);
    expectedException.expect(instanceOf(CompositeRoutingException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250)), throwable -> {
        CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 1);
        RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 0, 1);
        assertThat(routingResult.getFailures().get("0").getCause(), instanceOf(TimeoutException.class));
    });
}
Also used : CompositeRoutingException(org.mule.runtime.core.privileged.routing.CompositeRoutingException) RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult) TimeoutException(java.util.concurrent.TimeoutException) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 4 with RoutingResult

use of org.mule.runtime.core.privileged.routing.RoutingResult in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method assertRoutingResult.

private RoutingResult assertRoutingResult(CompositeRoutingException compositeRoutingException, int results, int errors) {
    assertThat(compositeRoutingException.getErrorMessage().getPayload().getValue(), instanceOf(RoutingResult.class));
    RoutingResult routingResult = (RoutingResult) compositeRoutingException.getErrorMessage().getPayload().getValue();
    assertThat(routingResult.getResults().size(), is(results));
    assertThat(routingResult.getFailures().size(), is(errors));
    return routingResult;
}
Also used : RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult)

Example 5 with RoutingResult

use of org.mule.runtime.core.privileged.routing.RoutingResult 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)

Aggregations

RoutingResult (org.mule.runtime.core.privileged.routing.RoutingResult)6 CompositeRoutingException (org.mule.runtime.core.privileged.routing.CompositeRoutingException)5 Description (io.qameta.allure.Description)4 Test (org.junit.Test)4 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 RoutingPair (org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair)3 TimeoutException (java.util.concurrent.TimeoutException)2 Message (org.mule.runtime.api.message.Message)2 Processor (org.mule.runtime.core.api.processor.Processor)2 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)2 InternalProcessor (org.mule.runtime.core.privileged.processor.InternalProcessor)2 LinkedHashMap (java.util.LinkedHashMap)1 Error (org.mule.runtime.api.message.Error)1