use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class DefaultRouterResultsHandlerTestCase method aggregateMultipleEventsAllButOneNull.
@Test
public void aggregateMultipleEventsAllButOneNull() {
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
CoreEvent event1 = InternalEvent.builder(context).message(message1).addVariable("key", "value").build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).addVariable("key2", "value2").build();
List<CoreEvent> events = new ArrayList<>();
events.add(null);
events.add(event2);
CoreEvent result = resultsHandler.aggregateResults(events, event1);
assertSame(event2, result);
// Because same event instance is returned rather than MessageCollection
// don't copy invocation properties
assertThat(result.getVariables().keySet(), not(hasItem("key1")));
assertThat(result.getVariables().get("key2").getValue(), equalTo("value2"));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class DefaultRouterResultsHandlerTestCase method aggregateMultipleMuleMessageCollections.
@Test
public void aggregateMultipleMuleMessageCollections() {
Message message1 = Message.of("test event A");
CoreEvent event1 = InternalEvent.builder(context).message(message1).addVariable("key1", "value1").build();
Message message2 = Message.of("test event B");
Message message3 = Message.of("test event C");
Message message4 = Message.of("test event D");
Message message5 = Message.of("test event E");
List<Message> list = new ArrayList<>();
list.add(message2);
list.add(message3);
Message messageCollection = Message.of(list);
CoreEvent event2 = InternalEvent.builder(context).message(messageCollection).addVariable("key2", "value2").build();
List<InternalMessage> list2 = new ArrayList<>();
list.add(message4);
list.add(message5);
Message messageCollection2 = Message.of(list2);
CoreEvent event3 = InternalEvent.builder(context).message(messageCollection2).addVariable("key3", "value3").build();
List<CoreEvent> events = new ArrayList<>();
events.add(event2);
events.add(event3);
CoreEvent result = resultsHandler.aggregateResults(events, event1);
assertNotNull(result);
assertEquals(2, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).size());
assertTrue(result.getMessage().getPayload().getValue() instanceof List<?>);
assertEquals(messageCollection, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).get(0));
assertEquals(messageCollection2, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).get(1));
// Because a new MuleMessageCollection is created, propagate properties from
// original event
assertThat(result.getVariables().get("key1").getValue(), equalTo("value1"));
assertThat(result.getVariables().get("key2").getValue(), equalTo("value2"));
assertThat(result.getVariables().get("key3").getValue(), equalTo("value3"));
// Root id
assertThat(result.getCorrelationId(), equalTo(event1.getCorrelationId()));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class FirstSuccessfulTestCase method getPayload.
private String getPayload(Processor mp, MuleSession session, String message) throws Exception {
Message msg = of(message);
try {
CoreEvent event = mp.process(this.<PrivilegedEvent.Builder>getEventBuilder().message(msg).session(session).build());
Message returnedMessage = event.getMessage();
if (event.getError().isPresent()) {
return EXCEPTION_SEEN;
} else {
return getPayloadAsString(returnedMessage);
}
} catch (Exception ex) {
return EXCEPTION_SEEN;
}
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class AsyncRequestReplyRequesterTestCase method testSingleEventNoTimeout.
@Test
public void testSingleEventNoTimeout() throws Exception {
asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext);
SensingNullMessageProcessor target = getSensingNullMessageProcessor();
asyncReplyMP.setListener(target);
asyncReplyMP.setReplySource(target.getMessageSource());
asyncReplyMP.setMuleContext(muleContext);
CoreEvent resultEvent = asyncReplyMP.process(testEvent());
// Can't assert same because we copy event when we receive async reply
assertEquals(((PrivilegedEvent) testEvent()).getMessageAsString(muleContext), ((PrivilegedEvent) resultEvent).getMessageAsString(muleContext));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class AsyncRequestReplyRequesterTestCase method testMultiple.
@Test
@Ignore("See MULE-8830")
public void testMultiple() throws Exception {
asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext);
SensingNullMessageProcessor target = getSensingNullMessageProcessor();
target.setWaitTime(50);
AsyncDelegateMessageProcessor asyncMP = createAsyncMessageProcessor(target);
asyncMP.initialise();
asyncReplyMP.setListener(asyncMP);
asyncReplyMP.setReplySource(target.getMessageSource());
final AtomicInteger count = new AtomicInteger();
for (int i = 0; i < 500; i++) {
scheduler.execute(() -> {
try {
CoreEvent resultEvent = asyncReplyMP.process(testEvent());
// Can't assert same because we copy event for async currently
assertEquals(((PrivilegedEvent) testEvent()).getMessageAsString(muleContext), ((PrivilegedEvent) resultEvent).getMessageAsString(muleContext));
count.incrementAndGet();
LOGGER.debug("Finished " + count.get());
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
new PollingProber().check(new JUnitLambdaProbe(() -> {
assertThat(count.get(), greaterThanOrEqualTo(500));
return true;
}));
}
Aggregations