use of org.mule.runtime.core.api.construct.Flow in project mule by mulesoft.
the class SimpleCollectionAggregatorTestCase method testAggregateSingleEvent.
@Test
public void testAggregateSingleEvent() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
SimpleCollectionAggregator router = new SimpleCollectionAggregator();
SensingNullMessageProcessor sensingMessageProcessor = getSensingNullMessageProcessor();
router.setListener(sensingMessageProcessor);
router.setMuleContext(muleContext);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext executionContext = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = of("test event A");
CoreEvent event1 = InternalEvent.builder(executionContext).message(message1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 1))).build();
CoreEvent resultEvent = router.process(event1);
assertNotNull(sensingMessageProcessor.event);
assertThat(resultEvent, equalTo(sensingMessageProcessor.event));
Message nextMessage = sensingMessageProcessor.event.getMessage();
assertNotNull(nextMessage);
assertTrue(nextMessage.getPayload().getValue() instanceof List<?>);
List<InternalMessage> payload = (List<InternalMessage>) nextMessage.getPayload().getValue();
assertEquals(1, payload.size());
assertEquals("test event A", payload.get(0).getPayload().getValue());
}
use of org.mule.runtime.core.api.construct.Flow in project mule by mulesoft.
the class AbstractProcessingStrategyTestCase method testBackPressure.
protected void testBackPressure(BackPressureStrategy backPressureStrategy, Matcher<Integer> processedAssertion, Matcher<Integer> rejectedAssertion, Matcher<Integer> totalAssertion) throws MuleException {
if (mode.equals(SOURCE)) {
triggerableMessageSource = new TriggerableMessageSource(backPressureStrategy);
flow = flowBuilder.get().source(triggerableMessageSource).processors(asList(cpuLightProcessor, new ThreadTrackingProcessor() {
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
try {
sleep(3);
} catch (InterruptedException e) {
currentThread().interrupt();
throw new RuntimeException(e);
}
return super.process(event);
}
@Override
public ProcessingType getProcessingType() {
return BLOCKING;
}
})).maxConcurrency(2).build();
flow.initialise();
flow.start();
AtomicInteger rejected = new AtomicInteger();
AtomicInteger processed = new AtomicInteger();
for (int i = 0; i < STREAM_ITERATIONS; i++) {
cachedThreadPool.submit(() -> Flux.just(newEvent()).cast(CoreEvent.class).transform(triggerableMessageSource.getListener()).doOnNext(event -> processed.getAndIncrement()).doOnError(e -> rejected.getAndIncrement()).subscribe());
}
new PollingProber(DEFAULT_TIMEOUT * 10, DEFAULT_POLLING_INTERVAL).check(new JUnitLambdaProbe(() -> {
LOGGER.info("DONE " + processed.get() + " , REJECTED " + rejected.get() + ", ");
assertThat(rejected.get() + processed.get(), totalAssertion);
assertThat(processed.get(), processedAssertion);
assertThat(rejected.get(), rejectedAssertion);
return true;
}));
}
}
Aggregations