use of org.mule.runtime.core.privileged.event.MuleSession in project mule by mulesoft.
the class SplitterTestCase method assertRouted.
private void assertRouted(Object payload, int count, boolean counted) throws Exception, MuleException {
MuleSession session = new DefaultMuleSession();
Map<String, Serializable> inboundProps = new HashMap<>();
inboundProps.put("inbound1", "1");
inboundProps.put("inbound2", 2);
inboundProps.put("inbound3", session);
Map<String, Serializable> outboundProps = new HashMap<>();
outboundProps.put("outbound1", "3");
outboundProps.put("outbound2", 4);
outboundProps.put("outbound3", session);
Map<String, Object> invocationProps = new HashMap<>();
invocationProps.put("invoke1", "5");
invocationProps.put("invoke2", 6);
invocationProps.put("invoke3", session);
Set<Integer> expectedSequences = new HashSet<>();
for (int i = 1; i <= count; i++) {
expectedSequences.add(i);
}
Message toSplit = InternalMessage.builder().value(payload).inboundProperties(inboundProps).outboundProperties(outboundProps).build();
Splitter splitter = new Splitter();
Grabber grabber = new Grabber();
splitter.setMuleContext(muleContext);
splitter.setListener(grabber);
splitter.initialise();
final Builder eventBuilder = this.<PrivilegedEvent.Builder>getEventBuilder().message(toSplit).session(session);
for (Map.Entry<String, Object> entry : invocationProps.entrySet()) {
eventBuilder.addVariable(entry.getKey(), entry.getValue());
}
CoreEvent event = eventBuilder.build();
splitter.process(event);
List<CoreEvent> splits = grabber.getEvents();
assertEquals(count, splits.size());
Set<Object> actualSequences = new HashSet<>();
assertSplitParts(count, counted, inboundProps, outboundProps, invocationProps, splits, actualSequences);
assertEquals(expectedSequences, actualSequences);
}
use of org.mule.runtime.core.privileged.event.MuleSession in project mule by mulesoft.
the class ResequencerTestCase method testMessageResequencer.
@Test
public void testMessageResequencer() throws Exception {
MuleSession session = new DefaultMuleSession();
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
TestEventResequencer router = new TestEventResequencer(3);
router.setMuleContext(muleContext);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext context = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
Message message3 = Message.of("test event C");
CoreEvent event1 = InternalEvent.builder(context).message(message1).session(session).build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
assertNull(router.process(event2));
assertNull(router.process(event3));
CoreEvent resultEvent = router.process(event1);
assertNotNull(resultEvent);
Message resultMessage = resultEvent.getMessage();
assertNotNull(resultMessage);
assertTrue(getPayloadAsString(resultMessage).equals("test event A") || getPayloadAsString(resultMessage).equals("test event B") || getPayloadAsString(resultMessage).equals("test event C"));
}
use of org.mule.runtime.core.privileged.event.MuleSession in project mule by mulesoft.
the class RoundRobinTestCase method testRoundRobin.
@Test
public void testRoundRobin() throws Exception {
RoundRobin rr = new RoundRobin();
rr.setAnnotations(getAppleFlowComponentLocationAnnotations());
MuleSession session = new DefaultMuleSession();
List<TestProcessor> routes = new ArrayList<>(NUMBER_OF_ROUTES);
for (int i = 0; i < NUMBER_OF_ROUTES; i++) {
routes.add(new TestProcessor());
}
rr.setRoutes(new ArrayList<Processor>(routes));
initialiseIfNeeded(rr, muleContext);
List<Thread> threads = new ArrayList<>(NUMBER_OF_ROUTES);
for (int i = 0; i < NUMBER_OF_ROUTES; i++) {
threads.add(new Thread(new TestDriver(session, rr, NUMBER_OF_MESSAGES, getTestFlow(muleContext))));
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
for (TestProcessor route : routes) {
assertEquals(NUMBER_OF_MESSAGES, route.getCount());
}
}
use of org.mule.runtime.core.privileged.event.MuleSession in project mule by mulesoft.
the class AggregatorTestCase method testMessageAggregator.
@Test
public void testMessageAggregator() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
MuleSession session = new DefaultMuleSession();
TestEventAggregator router = new TestEventAggregator(3);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext context = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
Message message3 = Message.of("test event C");
CoreEvent event1 = InternalEvent.builder(context).message(message1).session(session).build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
assertNull(router.process(event1));
assertNull(router.process(event2));
CoreEvent result = router.process(event3);
assertNotNull(result);
PrivilegedEvent privilegedResult = (PrivilegedEvent) result;
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event A"));
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event B"));
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event C"));
assertTrue(privilegedResult.getMessageAsString(muleContext).matches("test event [A,B,C] test event [A,B,C] test event [A,B,C] "));
}
use of org.mule.runtime.core.privileged.event.MuleSession in project mule by mulesoft.
the class FirstSuccessfulTestCase method testFirstSuccessful.
@Test
public void testFirstSuccessful() throws Exception {
MuleSession session = new DefaultMuleSession();
FirstSuccessful fs = createFirstSuccessfulRouter(new TestProcessor("abc"), new TestProcessor("def"), new TestProcessor("ghi"));
fs.initialise();
assertThat(getPayload(fs, session, ""), is("No abc"));
assertThat(getPayload(fs, session, "abc"), is("No def"));
assertThat(getPayload(fs, session, "abcdef"), is("No ghi"));
assertThat(getPayload(fs, session, "abcdefghi"), is(EXCEPTION_SEEN));
assertThat(getPayload(fs, session, "ABC"), is("No def"));
assertThat(getPayload(fs, session, "ABCDEF"), is("No ghi"));
assertThat(getPayload(fs, session, "ABCDEFGHI"), is(EXCEPTION_SEEN));
}
Aggregations