/** * Events have a list of message processor paths it went trough so that the execution path of an event can be reconstructed * after it has executed. * * @return the message processors trace associated to the given event. */ public static ProcessorsTrace getProcessorsTrace(CoreEvent event) { return ((BaseEventContext) event.getContext()).getProcessorsTrace(); }
private void completeEventContext() { if (requestEvent != null) { ((BaseEventContext) requestEvent.getContext()).success(); } }
private CoreEvent handleError(Throwable error, CoreEvent childEvent) { try { errorHandler.accept(error, EventedResult.from(childEvent)); } catch (Throwable e) { ((BaseEventContext) originalEvent.getContext()).error(e); } return null; }
@Override public CoreEvent process(CoreEvent event) throws MuleException { eventContextService.getCurrentlyActiveFlowStacks().stream() .filter(fsde -> fsde.getEventId().equals(event.getContext().getId())).findAny() .ifPresent(dumpEntry -> stackToAssert = dumpEntry.getFlowCallStack()); return event; }
protected CoreEvent buildEvent(String eventId, FlowCallStack flowStack) { CoreEvent event = mock(CoreEvent.class); when(event.getContext()).thenReturn(messageContext); when(event.getContext()).thenReturn(messageContext); when(event.getFlowCallStack()).thenReturn(flowStack); return event; }
@Override public Supplier<CorrelationInfo> resolve(ExecutionContext executionContext) { return () -> { CoreEvent event = ((ExecutionContextAdapter) executionContext).getEvent(); return new ImmutableCorrelationInfo(event.getContext().getId(), true, event.getCorrelationId(), event.getItemSequenceInfo().orElse(null)); }; } }
/** * Creates a new instance * * @param event the event on which the operation is being executed. */ public DefaultFlowListener(ExtensionModel extensionModel, OperationModel operationModel, CoreEvent event) { this.extensionModel = extensionModel; this.operationModel = operationModel; BaseEventContext context = (BaseEventContext) event.getContext(); context.onResponse(this::onResponse); context.getRootContext().onTerminated((e, t) -> onTerminated()); }
private CoreEvent runFlow(Flow flow, CoreEvent event, OAuthConfig config, String callbackType) { final Publisher<CoreEvent> childPublisher = processWithChildContext(event, flow, child((BaseEventContext) event.getContext(), of(flow.getLocation()))); return from(childPublisher) .onErrorMap(MuleException.class, e -> new MuleRuntimeException(createStaticMessage(format("Error found while execution flow '%s' which is configured in the '%s' parameter " + "of the '%s' config", flow.getName(), callbackType, config.getOwnerConfigName()), e))) .block(); } }
@Before public void setup() { logger = new ThreadNotificationLogger(service, true); when(event.getContext()).thenReturn(context); when(context.getId()).thenReturn("id"); }
private Object resolveCursorStreamProvider(InputStream value) { CursorProviderFactory factory = cursorProviderFactory.accepts(value) ? cursorProviderFactory : streamingManager.forBytes().getDefaultCursorProviderFactory(); return factory.of(((BaseEventContext) event.getContext()).getRootContext(), value); }
private Object resolveCursorIteratorProvider(Iterator value) { CursorProviderFactory factory = cursorProviderFactory.accepts(value) ? cursorProviderFactory : streamingManager.forObjects().getDefaultCursorProviderFactory(); return factory.of(((BaseEventContext) event.getContext()).getRootContext(), value); }
@Test public void cursorStreamProvidersAreManaged() throws Exception { CursorStreamProvider provider = mock(CursorStreamProvider.class); final InputStream inputStream = mock(InputStream.class); doReturn(provider).when(cursorStreamProviderFactory).of(((BaseEventContext) event.getContext()).getRootContext(), inputStream); when(operationExecutor.execute(any())).thenReturn(just(inputStream)); messageProcessor.process(event); verify(streamingManager).manage(same(provider), any(EventContext.class)); }
@Before public void setup() { EventContext ctx = mock(EventContext.class); when(event.getContext()).thenReturn(ctx); when(mockExpressionManager.openSession(any(), any(), any())).thenReturn(session); when(session.evaluate(anyObject())).thenReturn(new TypedValue("something", DataType.STRING)); when(session.evaluate(anyObject(), anyObject())).thenReturn(new TypedValue("something", DataType.STRING)); }
protected HeisenbergExtension lookupHeisenberg(String key) throws Exception { CoreEvent heisenbergEvent = null; try { heisenbergEvent = getHeisenbergEvent(); return lookupHeisenberg(key, heisenbergEvent); } finally { if (heisenbergEvent != null) { ((BaseEventContext) heisenbergEvent.getContext()).success(); } } }
@Test public void testExecuteWithInputEvent() throws Exception { ExecutionResult executionResult = executableComponent.execute(InputEvent.create().message(requestMessage)).get(); Event response = executionResult.getEvent(); assertThat(componentInEvent.get().getMessage(), equalTo(requestMessage)); assertThat(response.getMessage(), equalTo(responseMessage)); assertThat(componentInEvent.get().getContext(), equalTo(response.getContext())); BaseEventContext eventContext = (BaseEventContext) componentInEvent.get().getContext(); assertThat(eventContext.isTerminated(), is(false)); executionResult.complete(); assertThat(eventContext.isTerminated(), is(true)); }
private void assertPreNotification(CoreEvent inEvent, MessageProcessorNotification preNotification) { assertThat(preNotification.getAction().getActionId(), equalTo(MESSAGE_PROCESSOR_PRE_INVOKE)); assertThat(preNotification.getEventContext(), equalTo(inEvent.getContext())); assertThat(preNotification.getEvent(), equalTo(inEvent)); assertThat(preNotification.getException(), is(nullValue())); }
private IronMan getIronMan(String name) throws Exception { CoreEvent initialiserEvent = null; try { initialiserEvent = getInitialiserEvent(muleContext); return (IronMan) getConfigurationInstanceFromRegistry(name, initialiserEvent, muleContext).getValue(); } finally { if (initialiserEvent != null) { ((BaseEventContext) initialiserEvent.getContext()).success(); } } }
@Test public void customCorrelationId() throws Exception { final String correlationId = "correlateThis"; final CoreEvent event = flowRunner("correlate").withSourceCorrelationId(correlationId).withItemSequenceInfo(of(43, 100)).run(); CorrelationInfo correlationInfo = (CorrelationInfo) event.getMessage().getPayload().getValue(); assertThat(correlationInfo.getEventId(), is(event.getContext().getId())); assertThat(correlationInfo.isOutboundCorrelationEnabled(), is(true)); assertThat(correlationInfo.getCorrelationId(), is(correlationId)); assertThat(correlationInfo.getItemSequenceInfo().get().getPosition(), is(43)); assertThat(correlationInfo.getItemSequenceInfo().get().getSequenceSize().getAsInt(), is(100)); }
protected ReactiveProcessor processor() { return eventPub -> { Flux<CoreEvent> baseFlux = Flux.from(eventPub); if (processChangeThread) { baseFlux = baseFlux.publishOn(Schedulers.single()); } return baseFlux .doOnNext(ev -> flowActualResultEvent = ev) .doOnNext(event -> ((BaseEventContext) event.getContext()).success(event)); }; }
@Test public void defaultCorrelationInfo() throws Exception { final CoreEvent event = flowRunner("correlate").run(); CorrelationInfo correlationInfo = (CorrelationInfo) event.getMessage().getPayload().getValue(); assertThat(correlationInfo.getEventId(), is(event.getContext().getId())); assertThat(correlationInfo.isOutboundCorrelationEnabled(), is(true)); assertThat(correlationInfo.getCorrelationId(), is(correlationInfo.getCorrelationId())); assertThat(correlationInfo.getItemSequenceInfo(), is(empty())); }