use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class CompositeSourcePolicyTestCase method nextProcessorExecutionFailurePropagates.
@Test
public void nextProcessorExecutionFailurePropagates() throws Exception {
RuntimeException policyException = new RuntimeException("policy failure");
reset(flowExecutionProcessor);
when(flowExecutionProcessor.apply(any())).thenAnswer(invocation -> {
Mono<CoreEvent> mono = from(invocation.getArgumentAt(0, Publisher.class));
mono.doOnNext(event -> ((BaseEventContext) event.getContext()).error(new MessagingException(event, policyException))).subscribe();
return empty();
});
compositeSourcePolicy = new CompositeSourcePolicy(asList(firstPolicy, secondPolicy), sourcePolicyParametersTransformer, sourcePolicyProcessorFactory, flowExecutionProcessor, sourceParametersTransformer);
Either<SourcePolicyFailureResult, SourcePolicySuccessResult> sourcePolicyResult = from(compositeSourcePolicy.process(initialEvent)).block();
assertThat(sourcePolicyResult.isLeft(), is(true));
assertThat(sourcePolicyResult.getLeft().getMessagingException(), instanceOf(FlowExecutionException.class));
assertThat(sourcePolicyResult.getLeft().getMessagingException().getCause(), is(policyException));
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class DefaultPolicyStateHandlerTestCase method destroyStateWhenEventIsCompleted.
@Test
public void destroyStateWhenEventIsCompleted() {
PolicyStateId policyStateExecutionId = new PolicyStateId(TEST_EXECUTION_ID, TEST_POLICY_ID);
Reference<BiConsumer> subscriberReference = new Reference<>();
BaseEventContext rootEventContext = eventTestExecutionId.getContext().getRootContext();
Mockito.doAnswer(invocationOnMock -> {
subscriberReference.set((BiConsumer) invocationOnMock.getArguments()[0]);
return null;
}).when(rootEventContext).onTerminated(any(BiConsumer.class));
defaultPolicyStateHandler.updateState(policyStateExecutionId, eventTestExecutionId);
subscriberReference.get().accept(null, null);
assertThat(defaultPolicyStateHandler.getLatestState(policyStateExecutionId).isPresent(), is(false));
assertThat(defaultPolicyStateHandler.policyStateIdsByExecutionIdentifier.containsKey(policyStateExecutionId.getExecutionIdentifier()), is(false));
assertThat(defaultPolicyStateHandler.nextOperationMap.containsKey(policyStateExecutionId.getExecutionIdentifier()), is(false));
assertThat(defaultPolicyStateHandler.stateMap.containsKey(policyStateExecutionId), is(false));
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class ExecutableComponentTestCase method testExecuteWithEvent.
@Test
public void testExecuteWithEvent() throws Exception {
Event response = executableComponent.execute(testEvent()).get();
assertThat(componentInEvent.get().getMessage(), equalTo(requestMessage));
assertThat(response.getMessage(), equalTo(responseMessage));
assertThat(componentInEvent.get().getContext(), not(equalTo(response.getContext())));
assertThat(((BaseEventContext) componentInEvent.get().getContext()).isTerminated(), is(true));
assertThat(((BaseEventContext) response.getContext()).isTerminated(), is(false));
BaseEventContext childContext = (BaseEventContext) componentInEvent.get().getContext();
assertThat(childContext.isTerminated(), is(true));
BaseEventContext parentContext = (BaseEventContext) testEvent().getContext();
assertThat(parentContext.isTerminated(), is(false));
((BaseEventContext) testEvent().getContext()).success();
assertThat(parentContext.isTerminated(), is(true));
}
use of org.mule.runtime.core.privileged.event.BaseEventContext 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()));
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class ParameterizedConfigParserTestCase method configWithExpressionFunctionStillDynamic.
@Test
public void configWithExpressionFunctionStillDynamic() throws Exception {
CoreEvent event = null;
CoreEvent anotherEvent = null;
try {
event = getHeisenbergEvent();
anotherEvent = CoreEvent.builder(getHeisenbergEvent()).addVariable("age", 40).build();
HeisenbergExtension config = lookupHeisenberg(HEISENBERG_EXPRESSION, event);
HeisenbergExtension anotherConfig = lookupHeisenberg(HEISENBERG_EXPRESSION, anotherEvent);
assertThat(config, is(not(sameInstance(anotherConfig))));
} finally {
if (event != null) {
((BaseEventContext) event.getContext()).success();
}
if (anotherEvent != null) {
((BaseEventContext) anotherEvent.getContext()).success();
}
}
}
Aggregations