use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair in project mule by mulesoft.
the class AbstractForkJoinStrategyTestCase method flowVarsMerged.
@Test
@Description("After successful completion of all routes the variables from each route are merged into the result.")
public void flowVarsMerged() throws Throwable {
final String beforeVarName = "before";
final String beforeVarValue = "beforeValue";
final String beforeVar2Name = "before2";
final String beforeVar2Value = "before2Value";
final String beforeVar2NewValue = "before2NewValue";
final String fooVarName = "foo";
final String fooVarValue = "fooValue1";
final String fooVar2Name = "foo2";
final String fooVar2Value1 = "foo2Value1";
final String fooVar2Value2 = "foo2Value2";
final String fooVar3Name = "foo3";
final String fooVar3Value1 = "foo3Value1";
final Apple fooVar3Value2 = new Apple();
CoreEvent original = builder(this.<CoreEvent>newEvent()).addVariable(beforeVarName, beforeVarValue).addVariable(beforeVar2Name, beforeVar2Value).build();
RoutingPair pair1 = of(original, createChain(event -> builder(event).addVariable(beforeVar2Name, beforeVar2NewValue).addVariable(fooVarName, fooVarValue).addVariable(fooVar2Name, fooVar2Value1).addVariable(fooVar3Name, fooVar3Value1).build()));
RoutingPair pair2 = of(original, createChain(event -> builder(event).addVariable(fooVar2Name, fooVar2Value2).addVariable(fooVar3Name, fooVar3Value2).build()));
CoreEvent result = invokeStrategyBlocking(strategy, original, asList(pair1, pair2));
assertThat(result.getVariables().keySet(), hasSize(5));
assertThat(result.getVariables().keySet(), hasItems(beforeVarName, beforeVar2Name, fooVarName, fooVarName, fooVar2Name, fooVar3Name));
assertThat(result.getVariables().get(beforeVarName).getValue(), equalTo(beforeVarValue));
assertThat(result.getVariables().get(beforeVar2Name).getValue(), equalTo(beforeVar2NewValue));
assertThat(result.getVariables().get(fooVarName).getValue(), equalTo(fooVarValue));
TypedValue fooVar2 = result.getVariables().get(fooVar2Name);
assertThat(fooVar2.getDataType(), equalTo(DataType.builder().collectionType(List.class).itemType(String.class).build()));
assertThat(((List<String>) fooVar2.getValue()), hasItems(fooVar2Value1, fooVar2Value2));
TypedValue fooVar3 = result.getVariables().get(fooVar3Name);
assertThat(fooVar3.getDataType(), equalTo(DataType.builder().collectionType(List.class).itemType(Object.class).build()));
assertThat(((List<Object>) fooVar3.getValue()), hasItems(fooVar3Value1, fooVar3Value2));
}
use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair 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()));
});
}
use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair 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));
});
}
use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair in project mule by mulesoft.
the class AbstractForkJoinStrategyTestCase method timeoutEager.
@Test
@Description("When configured with delayErrors='false' the first timeout causes strategy to throw a TimeoutException.")
public void timeoutEager() throws Throwable {
strategy = createStrategy(processingStrategy, 1, false, 50);
Message pair2Result = of(2);
Processor pair2Processor = createProcessorSpy(pair2Result);
RoutingPair pair2 = of(testEvent(), createChain(pair2Processor));
expectedException.expect(instanceOf(DefaultMuleException.class));
expectedException.expectCause(instanceOf(TimeoutException.class));
invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250), pair2), throwable -> verify(pair2Processor, never()).process(any(CoreEvent.class)));
}
use of org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair in project mule by mulesoft.
the class CollectListForkJoinStrategyTestCase method collectList.
@Test
@Description("This strategy waits for all routes to return and then collects results into a list.")
public void collectList() throws Throwable {
CoreEvent original = testEvent();
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, original, asList(pair1, pair2, pair3));
assertThat(result.getMessage().getPayload().getValue(), instanceOf(List.class));
List<Message> resultList = (List<Message>) result.getMessage().getPayload().getValue();
assertThat(resultList, hasSize(3));
assertThat(resultList, hasItems(route1Result, route2Result, route3Result));
}
Aggregations