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; }
((DefaultFlowCallStack) event.getFlowCallStack()).setCurrentProcessorPath(resolvedProcessorRepresentation); return policyManager .createOperationPolicy(this, event, () -> resolutionResult)
@Test public void splitStack() { CoreEvent event = buildEvent("newAnnotatedComponentCall"); PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName()); assertThat(getContextInfo(event, rootFlowConstruct), is("")); manager.onPipelineNotificationStart(pipelineNotification); assertThat(getContextInfo(event, rootFlowConstruct), startsWith("at " + rootFlowConstruct.getName())); manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, createMockProcessor("/comp", false))); assertThat(getContextInfo(event, rootFlowConstruct), startsWith("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)")); CoreEvent eventCopy = buildEvent("newAnnotatedComponentCall", event.getFlowCallStack().clone()); assertThat(getContextInfo(eventCopy, rootFlowConstruct), startsWith("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)")); manager.onPipelineNotificationComplete(pipelineNotification); assertThat(getContextInfo(event, rootFlowConstruct), is("")); final FlowConstruct asyncFlowConstruct = mock(FlowConstruct.class); when(asyncFlowConstruct.getName()).thenReturn("asyncFlow"); manager.onPipelineNotificationStart(buildPipelineNotification(eventCopy, asyncFlowConstruct.getName())); manager .onMessageProcessorNotificationPreInvoke(buildProcessorNotification(eventCopy, createMockProcessor("/asyncComp", false))); assertThat(getContextInfo(eventCopy, asyncFlowConstruct).split(quote(lineSeparator()))[0], startsWith("at " + asyncFlowConstruct.getName() + "(/asyncComp @ " + APP_ID + ":unknown:-1)")); assertThat(getContextInfo(eventCopy, asyncFlowConstruct).split(quote(lineSeparator()))[1], startsWith("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)")); }
private Consumer<CoreEvent> popSubFlowFlowStackElement() { return event -> ((DefaultFlowCallStack) event.getFlowCallStack()).pop(); }
private Consumer<CoreEvent> popFlowFlowStackElement() { return event -> ((DefaultFlowCallStack) event.getFlowCallStack()).pop(); }
private Consumer<CoreEvent> popBeforeNextFlowFlowStackElement() { return event -> ((DefaultFlowCallStack) event.getFlowCallStack()).pop(); }
@Override public Map<String, Object> getContextInfo(EnrichedNotificationInfo notificationInfo, Component lastProcessed) { FlowCallStack flowCallStack = ((CoreEvent) notificationInfo.getEvent()).getFlowCallStack(); if (isFlowTrace()) { return singletonMap(FLOW_STACK_INFO_KEY, flowCallStack.toString()); } else { return emptyMap(); } } }
startsWith("at " + rootFlowConstruct.getName() + "(/scatter-gather @ " + APP_ID + ":unknown:-1)")); CoreEvent eventCopy0 = buildEvent("joinStack_0", event.getFlowCallStack().clone()); CoreEvent eventCopy1 = buildEvent("joinStack_1", event.getFlowCallStack().clone());
@Override public void onFlowComplete(EnrichedNotificationInfo notificationInfo) { FlowCallStack flowCallStack = ((CoreEvent) notificationInfo.getEvent()).getFlowCallStack(); if (flowCallStack instanceof DefaultFlowCallStack) { ((DefaultFlowCallStack) flowCallStack).pop(); } }
private Consumer<CoreEvent> pushSubFlowFlowStackElement() { return event -> ((DefaultFlowCallStack) event.getFlowCallStack()).push(new FlowStackElement(subFlowName, null)); }
@Override public void onFlowStart(EnrichedNotificationInfo notificationInfo, String flowName) { FlowCallStack flowCallStack = ((CoreEvent) notificationInfo.getEvent()).getFlowCallStack(); if (flowCallStack instanceof DefaultFlowCallStack) { ((DefaultFlowCallStack) flowCallStack).push(new FlowStackElement(flowName, null)); } }
@Test public void splitStackEnd() { CoreEvent event = buildEvent("newAnnotatedComponentCall"); PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName()); manager.onPipelineNotificationStart(pipelineNotification); manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, createMockProcessor("/comp", false))); FlowCallStack flowCallStack = event.getFlowCallStack(); CoreEvent eventCopy = buildEvent("newAnnotatedComponentCall", flowCallStack.clone()); manager.onPipelineNotificationComplete(pipelineNotification); String asyncFlowName = "asyncFlow"; manager.onPipelineNotificationStart(buildPipelineNotification(eventCopy, asyncFlowName)); manager .onMessageProcessorNotificationPreInvoke(buildProcessorNotification(eventCopy, createMockProcessor("/asyncComp", false))); assertThat(((BaseEventContext) event.getContext()).getProcessorsTrace(), hasExecutedProcessors("/comp @ " + APP_ID + ":unknown:-1", "/asyncComp @ " + APP_ID + ":unknown:-1")); }
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; }
private Consumer<CoreEvent> pushBeforeNextFlowStackElement() { return event -> ((DefaultFlowCallStack) event.getFlowCallStack()) .push(new FlowStackElement(getLocation().getLocation() + "[before next]", null)); }
private Consumer<CoreEvent> pushAfterNextFlowStackElement() { return event -> ((DefaultFlowCallStack) event.getFlowCallStack()) .push(new FlowStackElement(toPolicyLocation(getLocation()), null)); }
/** * Given an {@code event}, it will consume from it ONLY the defined properties and parameters that were set when initializing * this class to provide scoping for the inner list of processors. */ @Override public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) { return from(publisher) .doOnNext(event -> ((DefaultFlowCallStack) event.getFlowCallStack()) .push(new FlowStackElement(getLocation().getRootContainerName(), getLocation().getLocation()))) .concatMap(request -> from(processWithChildContext(createEventWithParameters(request), super::apply, ofNullable(getLocation()))) .onErrorResume(MessagingException.class, createErrorResumeMapper(request)) .map(eventResult -> processResult(request, eventResult))) .doOnNext(event -> ((DefaultFlowCallStack) event.getFlowCallStack()).pop()) .doOnError(MessagingException.class, me -> ((DefaultFlowCallStack) me.getEvent().getFlowCallStack()).pop()); }
@Test public void joinStackEnd() { CoreEvent event = buildEvent("joinStack"); PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName()); manager.onPipelineNotificationStart(pipelineNotification); manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, createMockProcessor("/scatter-gather", false))); FlowCallStack flowCallStack = event.getFlowCallStack(); CoreEvent eventCopy0 = buildEvent("joinStack_0", flowCallStack.clone()); CoreEvent eventCopy1 = buildEvent("joinStack_1", flowCallStack.clone()); manager .onMessageProcessorNotificationPreInvoke(buildProcessorNotification(eventCopy0, createMockProcessor("/route_0", false))); manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(eventCopy1, createMockProcessor(NESTED_FLOW_NAME + "_ref", false))); PipelineMessageNotification pipelineNotificationNested = buildPipelineNotification(eventCopy1, NESTED_FLOW_NAME); manager.onPipelineNotificationStart(pipelineNotificationNested); manager .onMessageProcessorNotificationPreInvoke(buildProcessorNotification(eventCopy1, createMockProcessor("/route_1", false))); manager.onPipelineNotificationComplete(pipelineNotificationNested); manager.onPipelineNotificationComplete(pipelineNotification); assertThat(((BaseEventContext) event.getContext()).getProcessorsTrace(), hasExecutedProcessors("/scatter-gather @ " + APP_ID + ":unknown:-1", "/route_0 @ " + APP_ID + ":unknown:-1", NESTED_FLOW_NAME + "_ref @ " + APP_ID + ":unknown:-1", "/route_1 @ " + APP_ID + ":unknown:-1")); }
/** * Callback method for when a message processor is about to be invoked. * <p/> * Updates the internal state of the event's {@link ProcessorsTrace} and {@link FlowCallStack} accordingly. * * @see DefaultProcessorsTrace#addExecutedProcessors(String) * @see DefaultFlowCallStack#setCurrentProcessorPath(String) * * @param notification the notification that contains the event and the processor that is about to be invoked. */ public void onMessageProcessorNotificationPreInvoke(MessageProcessorNotification notification) { String resolveProcessorRepresentation = resolveProcessorRepresentation(muleContext.getConfiguration().getId(), notification.getComponent().getLocation() != null ? notification.getComponent().getLocation().getLocation() : null, notification.getComponent()); EventContext eventContext = notification.getEventContext(); if (eventContext != null) { ((DefaultProcessorsTrace) ((BaseEventContext) eventContext).getProcessorsTrace()) .addExecutedProcessors(resolveProcessorRepresentation); } FlowCallStack flowCallStack = ((CoreEvent) notification.getEvent()).getFlowCallStack(); if (flowCallStack != null) { ((DefaultFlowCallStack) flowCallStack).setCurrentProcessorPath(resolveProcessorRepresentation); } }
@Test public void splitStack() { CoreEvent event = buildEvent("newAnnotatedComponentCall"); PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName()); assertThat(getContextInfo(event, rootFlowConstruct), is("")); manager.onPipelineNotificationStart(pipelineNotification); assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName())); manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, createMockProcessor("/comp", false))); assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)")); CoreEvent eventCopy = buildEvent("newAnnotatedComponentCall", event.getFlowCallStack().clone()); assertThat(getContextInfo(eventCopy, rootFlowConstruct), is("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)")); manager.onPipelineNotificationComplete(pipelineNotification); assertThat(getContextInfo(event, rootFlowConstruct), is("")); final FlowConstruct asyncFlowConstruct = mock(FlowConstruct.class); when(asyncFlowConstruct.getName()).thenReturn("asyncFlow"); manager.onPipelineNotificationStart(buildPipelineNotification(eventCopy, asyncFlowConstruct.getName())); manager .onMessageProcessorNotificationPreInvoke(buildProcessorNotification(eventCopy, createMockProcessor("/asyncComp", false))); assertThat(getContextInfo(eventCopy, asyncFlowConstruct), is("at " + asyncFlowConstruct.getName() + "(/asyncComp @ " + APP_ID + ":unknown:-1)" + lineSeparator() + "at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)")); }
@Test public void splitStackEnd() { CoreEvent event = buildEvent("newAnnotatedComponentCall"); PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName()); manager.onPipelineNotificationStart(pipelineNotification); manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, createMockProcessor("/comp", false))); FlowCallStack flowCallStack = event.getFlowCallStack(); CoreEvent eventCopy = buildEvent("newAnnotatedComponentCall", flowCallStack.clone()); manager.onPipelineNotificationComplete(pipelineNotification); String asyncFlowName = "asyncFlow"; manager.onPipelineNotificationStart(buildPipelineNotification(eventCopy, asyncFlowName)); manager .onMessageProcessorNotificationPreInvoke(buildProcessorNotification(eventCopy, createMockProcessor("/asyncComp", false))); assertThat(((BaseEventContext) event.getContext()).getProcessorsTrace(), hasExecutedProcessors("/comp @ " + APP_ID + ":unknown:-1", "/asyncComp @ " + APP_ID + ":unknown:-1")); }