@Test public void correlationSequence() throws Exception { when(event.getGroupCorrelation()).thenReturn(Optional.of(GroupCorrelation.of(4))); assertEquals(4, evaluate("message.correlationSequence", event)); assertFinalProperty("message.correlationSequence=2", event); }
@Test public void correlationGroupSize() throws Exception { when(event.getGroupCorrelation()).thenReturn(Optional.of(GroupCorrelation.of(0, 2))); assertEquals(2, evaluate("message.correlationGroupSize", event)); assertFinalProperty("message.correlationGroupSize=2", event); }
private void assertSplitParts(int count, boolean counted, Map<String, Serializable> inboundProps, Map<String, Serializable> outboundProps, Map<String, Object> invocationProps, List<CoreEvent> splits, Set<Object> actualSequences) { for (CoreEvent event : splits) { Message msg = event.getMessage(); assertTrue(msg.getPayload().getValue() instanceof String); if (counted) { assertThat(event.getGroupCorrelation().get().getGroupSize().getAsInt(), is(count)); } else { assertThat(event.getGroupCorrelation().get().getGroupSize().isPresent(), is(false)); } actualSequences.add(event.getGroupCorrelation().get().getSequence()); String str = (String) msg.getPayload().getValue(); assertTrue(TEST_LIST_MULTIPLE.contains(str)); for (String key : inboundProps.keySet()) { assertEquals(((InternalMessage) msg).getInboundProperty(key), inboundProps.get(key)); } for (String key : outboundProps.keySet()) { assertEquals(((InternalMessage) msg).getOutboundProperty(key), outboundProps.get(key)); } for (String key : invocationProps.keySet()) { assertEquals(event.getVariables().get(key).getValue(), invocationProps.get(key)); } } }
/** * Creates a new EventGroup that will expect the number of events as returned by {@link org.mule.runtime.core.api.message.GroupCorrelation#getGroupSize()}. */ @Override public EventGroup createEventGroup(CoreEvent event, Object groupId) { return new EventGroup(groupId, muleContext, event.getGroupCorrelation().isPresent() ? event.getGroupCorrelation().get().getGroupSize().isPresent() ? Optional.of(event.getGroupCorrelation().get().getGroupSize().getAsInt()) : empty() : Optional.empty(), storePrefix); }
public int getCorrelationSequence() { return event.getGroupCorrelation().map(gc -> gc.getSequence()).orElse(-1); }
public int getCorrelationGroupSize() { return event.getGroupCorrelation().map(gc -> gc.getGroupSize().orElse(-1)).orElse(-1); }
@Override public int compare(CoreEvent event1, CoreEvent event2) { Optional<Integer> val1 = event1.getGroupCorrelation().map(gc -> of(gc.getSequence())).orElse(empty()); Optional<Integer> val2 = event2.getGroupCorrelation().map(gc -> of(gc.getSequence())).orElse(empty()); if (val1 == val2) { return 0; } else if (val1.isPresent() && !val2.isPresent()) { return 1; } else if (!val1.isPresent() && val2.isPresent()) { return -1; } else { return val1.get().compareTo(val2.get()); } } }
private void addLock(CoreEvent event) { String correlationId = getAsyncReplyCorrelationId(event); locks.put(correlationId, new RequestReplyLatch(event.getGroupCorrelation().map(gc -> gc.getGroupSize().orElse(-1)).orElse(-1), event.getGroupCorrelation().map(gc -> gc.getSequence()).orElse(-1))); }
private String getEventKey(CoreEvent event) { StringBuilder stringBuilder = new StringBuilder(); event.getGroupCorrelation().ifPresent(v -> stringBuilder.append(v.getSequence() + DASH)); stringBuilder.append(event.hashCode()); stringBuilder.append(DASH); stringBuilder.append(event.getContext().getId()); return stringBuilder.toString(); }
@Override protected Function<List<CoreEvent>, CoreEvent> createResultEvent(CoreEvent original, CoreEvent.Builder resultBuilder) { return list -> resultBuilder .message(of(list.stream().collect(toMap(event -> Integer.toString(event.getGroupCorrelation().get().getSequence()), event -> event.getMessage())))) .build(); }
private CompositeRoutingException createCompositeRoutingException(List<CoreEvent> results) { Map<String, Message> successMap = new LinkedHashMap<>(); Map<String, Error> errorMap = new LinkedHashMap<>(); for (CoreEvent event : results) { String key = Integer.toString(event.getGroupCorrelation().get().getSequence()); if (event.getError().isPresent()) { errorMap.put(key, event.getError().get()); } else { successMap.put(key, event.getMessage()); } } return new CompositeRoutingException(new RoutingResult(successMap, errorMap)); }
/** * Logs a fatal error message to the logging system. This should be used mostly if an error occurs in the exception listener * itself. This implementation logs the the message itself to the logs if it is not null * * @param event The MuleEvent currently being processed * @param t the fatal exception to log */ protected void logFatal(CoreEvent event, Throwable t) { if (statistics != null && statistics.isEnabled()) { statistics.incFatalError(); } String logUniqueId = defaultString(event.getCorrelationId(), NOT_SET); String printableLogMessage = format("Message identification summary here: id={0}, correlation={1}", logUniqueId, event.getGroupCorrelation()); logger.error("Failed to dispatch message to error queue after it failed to process. This may cause message loss. " + (event.getMessage() == null ? "" : printableLogMessage), t); }
private Mono<CoreEvent> onTimeout(ProcessingStrategy processingStrategy, boolean delayErrors, ErrorType timeoutErrorType, RoutingPair pair) { return defer(() -> delayErrors ? just(createTimeoutErrorEvent(timeoutErrorType, pair)) : error(new TimeoutException(TIMEOUT_EXCEPTION_DETAILED_DESCRIPTION_PREFIX + " '" + pair.getEvent().getGroupCorrelation().get().getSequence() + "'"))) .transform(processingStrategy.onPipeline(p -> p)); }
@Test public void correlationSequence() throws Exception { when(event.getGroupCorrelation()).thenReturn(Optional.of(GroupCorrelation.of(4))); assertEquals(4, evaluate("message.correlationSequence", event)); assertFinalProperty("message.correlationSequence=2", event); }
@Test public void correlationGroupSize() throws Exception { when(event.getGroupCorrelation()).thenReturn(Optional.of(GroupCorrelation.of(0, 2))); assertEquals(2, evaluate("message.correlationGroupSize", event)); assertFinalProperty("message.correlationGroupSize=2", event); }
private CoreEvent createTimeoutErrorEvent(ErrorType timeoutErrorType, RoutingPair pair) { return builder(pair.getEvent()).message(Message.of(null)) .error(ErrorBuilder.builder().errorType(timeoutErrorType) .exception(new TimeoutException()).description(TIMEOUT_EXCEPTION_DESCRIPTION) .detailedDescription(TIMEOUT_EXCEPTION_DETAILED_DESCRIPTION_PREFIX + " '" + pair.getEvent().getGroupCorrelation().get().getSequence() + "'") .build()) .build(); }
private void assertSplitParts(int count, boolean counted, Map<String, Serializable> inboundProps, Map<String, Serializable> outboundProps, Map<String, Object> invocationProps, List<CoreEvent> splits, Set<Object> actualSequences) { for (CoreEvent event : splits) { Message msg = event.getMessage(); assertTrue(msg.getPayload().getValue() instanceof String); if (counted) { assertThat(event.getGroupCorrelation().get().getGroupSize().getAsInt(), is(count)); } else { assertThat(event.getGroupCorrelation().get().getGroupSize().isPresent(), is(false)); } actualSequences.add(event.getGroupCorrelation().get().getSequence()); String str = (String) msg.getPayload().getValue(); assertTrue(TEST_LIST_MULTIPLE.contains(str)); for (String key : inboundProps.keySet()) { assertEquals(((InternalMessage) msg).getInboundProperty(key), inboundProps.get(key)); } for (String key : outboundProps.keySet()) { assertEquals(((InternalMessage) msg).getOutboundProperty(key), outboundProps.get(key)); } for (String key : invocationProps.keySet()) { assertEquals(event.getVariables().get(key).getValue(), invocationProps.get(key)); } } }