@Override public CoreEvent process(CoreEvent event) throws MuleException { correlationId = event.getCorrelationId(); 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)); }; } }
private void assertLogicallyEqualEvents(final CoreEvent testEvent, CoreEvent eventReceived) throws MuleException { // events have been rewritten so are different but the correlation ID has been carried around assertEquals(testEvent.getCorrelationId(), eventReceived.getCorrelationId()); // and their payload assertEquals(testEvent.getMessage(), eventReceived.getMessage()); }
@Test public void initAfterDeserializationAfterProcess() throws Exception { when(mockEventCorrelatorCallback.shouldAggregateEvents(mockEventGroup)).thenReturn(false); when(mockMuleEvent.getCorrelationId()).thenReturn(TEST_GROUP_ID); EventCorrelator eventCorrelator = createEventCorrelator(); eventCorrelator.process(mockMuleEvent); verify(mockEventGroup, times(1)).initAfterDeserialisation(mockMuleContext); }
@Test public void testEventGroupFreedInRoutingException() throws Exception { CoreEvent event = mock(CoreEvent.class); when(event.getCorrelationId()).thenReturn(GROUP_NAME); try { eventCorrelator.process(event); fail("Routing Exception must be catched."); } catch (RoutingException e) { assertTrue("Event Group wasn't saved", eventGroupWasSaved); assertThat(countOfEventGroups, is(0)); } }
@Test public void correlationId() throws Exception { when(event.getCorrelationId()).thenReturn("3"); assertEquals("3", evaluate("message.correlationId", event)); assertFinalProperty("message.correlationId=2", event); }
private void assertTargetEvent(CoreEvent request) { // Assert that event is processed in async thread assertNotNull(target.sensedEvent); assertThat(request, not(sameInstance(target.sensedEvent))); assertThat(request.getCorrelationId(), equalTo(target.sensedEvent.getCorrelationId())); assertThat(request.getMessage(), sameInstance(target.sensedEvent.getMessage())); assertThat(target.thread, not(sameInstance(currentThread()))); }
@Test public void overrideCorrelationIdInContext() { final Message message = of(TEST_PAYLOAD); final CoreEvent event = InternalEvent.builder(executionContextWithCorrelation).message(message) .groupCorrelation(empty()).build(); assertThat(event.getCorrelationId(), is(CUSTOM_CORRELATION_ID)); }
@Test public void noCorrelationIdInContext() { final Message message = of(TEST_PAYLOAD); final CoreEvent event = InternalEvent.builder(executionContext).message(message).build(); assertThat(event.getCorrelationId(), is(GENERATED_CORRELATION_ID)); }
@Test public void correlationIdInContext() { final Message message = of(TEST_PAYLOAD); final CoreEvent event = InternalEvent.builder(executionContextWithCorrelation).message(message).build(); assertThat(event.getCorrelationId(), is(CUSTOM_CORRELATION_ID)); }
@Test public void testHandleExceptionWithMessageProcessorsChangingEvent() throws Exception { CoreEvent lastEventCreated = InternalEvent.builder(context).message(of("")).build(); onErrorContinueHandler .setMessageProcessors(asList(createChagingEventMessageProcessor(InternalEvent.builder(context).message(of("")) .build()), createChagingEventMessageProcessor(lastEventCreated))); onErrorContinueHandler.setAnnotations(getAppleFlowComponentLocationAnnotations()); initialiseIfNeeded(onErrorContinueHandler, muleContext); when(mockException.handled()).thenReturn(true); when(mockException.getDetailedMessage()).thenReturn(DEFAULT_LOG_MESSAGE); when(mockException.getEvent()).thenReturn(muleEvent); CoreEvent exceptionHandlingResult = onErrorContinueHandler.handleException(mockException, muleEvent); verify(mockException).setHandled(true); assertThat(exceptionHandlingResult.getCorrelationId(), is(lastEventCreated.getCorrelationId())); }
@Test public void overrideCorrelationIdInContextSequence() { final Message message = of(TEST_PAYLOAD); final CoreEvent event = InternalEvent.builder(executionContextWithCorrelation).message(message).correlationId(CUSTOM_CORRELATION_ID) .groupCorrelation(Optional.of(GroupCorrelation.of(6))).build(); assertThat(event.getCorrelationId(), is(CUSTOM_CORRELATION_ID)); }
@Test public void eventGroupConversionToString() throws Exception { EventGroup eg = new EventGroup(UUID.getUUID(), muleContext); eg.initEventsStore(objectStore); String es = eg.toString(); assertTrue(es.endsWith("events=0}")); CoreEvent firstEvent = eventBuilder(muleContext).message(Message.of("foo")).build(); String firstId = firstEvent.getCorrelationId(); eg.addEvent(firstEvent); es = eg.toString(); assertTrue(es.contains("events=1")); assertTrue(es.endsWith("[" + firstId + "]}")); CoreEvent secondEvent = eventBuilder(muleContext) .message(Message.of("foo2")) .build(); String secondId = secondEvent.getCorrelationId(); eg.addEvent(secondEvent); es = eg.toString(); assertTrue(es.contains("events=2")); assertTrue(es.contains(firstId)); assertTrue(es.contains(secondId)); }
@Test public void operationFiresNotificationsWithCustomData() throws Exception { Latch latch = new Latch(); setUpListener(notification -> checkIfDone(latch, 2), false); String correlationId = flowRunner("operationNotification").run().getCorrelationId(); assertThat("Expected notifications not received.", latch.await(6000, MILLISECONDS), is(true)); MultiMap<String, ExtensionNotification> notifications = listener.getNotifications(); Set<String> keys = notifications.keySet(); assertThat(keys, hasItem(KNOCKING_DOOR)); assertThat(keys, hasItem(KNOCKED_DOOR)); ExtensionNotification knockingDoor = notifications.get(KNOCKING_DOOR); assertThat(knockingDoor, is(notNullValue())); assertThat(knockingDoor.getAction().getNamespace(), is(HEISENBERG)); assertThat(knockingDoor.getData().getValue(), instanceOf(SimpleKnockeableDoor.class)); assertThat(((SimpleKnockeableDoor) knockingDoor.getData().getValue()).getSimpleName(), is("Top Level Skyler @ 308 Negra Arroyo Lane")); assertThat(knockingDoor.getEvent().getCorrelationId(), is(correlationId)); ExtensionNotification knockedDoor = notifications.get(KNOCKED_DOOR); assertThat(knockedDoor, is(notNullValue())); assertThat(knockedDoor.getAction().getNamespace(), is(HEISENBERG)); assertThat(knockedDoor.getData().getValue(), instanceOf(SimpleKnockeableDoor.class)); assertThat(((SimpleKnockeableDoor) knockedDoor.getData().getValue()).getSimpleName(), is("Top Level Skyler @ 308 Negra Arroyo Lane")); assertThat(knockedDoor.getEvent().getCorrelationId(), is(correlationId)); }
assertThat(result.getCorrelationId(), equalTo(event1.getCorrelationId()));
@Override public CoreEvent process(CoreEvent event) throws MuleException { correlationId = event.getCorrelationId(); return event; } }
@Override public LazyValue<CorrelationInfo> resolve(ExecutionContext executionContext) { return new LazyValue<>(() -> { CoreEvent event = ((ExecutionContextAdapter) executionContext).getEvent(); return new ImmutableCorrelationInfo(event.getContext().getId(), true, event.getCorrelationId(), event.getItemSequenceInfo().orElse(null)); }); } }
@Test public void overrideCorrelationIdInContext() { final Message message = of(TEST_PAYLOAD); final CoreEvent event = InternalEvent.builder(executionContextWithCorrelation).message(message) .groupCorrelation(empty()).build(); assertThat(event.getCorrelationId(), is(CUSTOM_CORRELATION_ID)); }
@Test public void correlationIdInContext() { final Message message = of(TEST_PAYLOAD); final CoreEvent event = InternalEvent.builder(executionContextWithCorrelation).message(message).build(); assertThat(event.getCorrelationId(), is(CUSTOM_CORRELATION_ID)); }
@Test public void noCorrelationIdInContext() { final Message message = of(TEST_PAYLOAD); final CoreEvent event = InternalEvent.builder(executionContext).message(message).build(); assertThat(event.getCorrelationId(), is(GENERATED_CORRELATION_ID)); }