use of org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor 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;
}));
}
use of org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor in project mule by mulesoft.
the class CompositeProcessorChainRouterTestCase method asyncDelegateChain.
@Test
@Description("Ensure that when an async scope is used as part of the execution of one of the composite chains then the chain does not complete and the next chains is not executed until the child context completes.")
public void asyncDelegateChain() throws Exception {
Latch latch = new Latch();
Latch asyncLatch = new Latch();
DefaultMessageProcessorChainBuilder delegateBuilder = new DefaultMessageProcessorChainBuilder();
delegateBuilder.chain(event -> {
try {
asyncLatch.countDown();
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return event;
});
async = new AsyncDelegateMessageProcessor(delegateBuilder);
muleContext.getInjector().inject(async);
async.setAnnotations(getAppleFlowComponentLocationAnnotations());
chainRouter = createCompositeProcessorChainRouter(newChain(empty(), async), newChain(empty(), event -> event));
chainRouter.start();
// CompletableFuture is not returned immediately because simply invoking CompositeProcessorChainRouter there is no async
// hand-off and so this blocks until child context completes.
Future<CompletableFuture<Event>> future = scheduler.submit(() -> chainRouter.execute(testEvent()));
asyncLatch.await();
try {
future.get(BLOCK_TIMEOUT, MILLISECONDS);
fail("Timeout expected");
} catch (TimeoutException te) {
}
latch.countDown();
assertThat(future.get(BLOCK_TIMEOUT, MILLISECONDS).get().getMessage(), equalTo(testEvent().getMessage()));
}
use of org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor in project mule by mulesoft.
the class AsyncMessageProcessorsFactoryBean method getObject.
@Override
public AsyncDelegateMessageProcessor getObject() throws Exception {
DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
builder.setName("'async' child chain");
for (Object processor : messageProcessors) {
if (processor instanceof Processor) {
builder.chain((Processor) processor);
} else if (processor instanceof MessageProcessorBuilder) {
builder.chain((MessageProcessorBuilder) processor);
} else {
throw new IllegalArgumentException("MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured");
}
}
AsyncDelegateMessageProcessor delegate = new AsyncDelegateMessageProcessor(builder, name);
delegate.setAnnotations(getAnnotations());
if (getMaxConcurrency() != null) {
delegate.setMaxConcurrency(getMaxConcurrency());
}
return delegate;
}
use of org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor in project mule by mulesoft.
the class AsyncRequestReplyRequesterTestCase method createAsyncMessageProcessor.
protected AsyncDelegateMessageProcessor createAsyncMessageProcessor(SensingNullMessageProcessor target) throws InitialisationException {
DefaultMessageProcessorChainBuilder delegateBuilder = new DefaultMessageProcessorChainBuilder();
delegateBuilder.chain(target);
asyncMP = new AsyncDelegateMessageProcessor(delegateBuilder);
asyncMP.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(asyncMP, true, muleContext);
return asyncMP;
}
use of org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor in project mule by mulesoft.
the class AsyncRequestReplyRequesterTestCase method testSingleEventTimeout.
@Test
public void testSingleEventTimeout() throws Exception {
asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext);
asyncReplyMP.setTimeout(1);
SensingNullMessageProcessor target = getSensingNullMessageProcessor();
target.setWaitTime(30000);
AsyncDelegateMessageProcessor asyncMP = createAsyncMessageProcessor(target);
initialiseIfNeeded(asyncMP, true, muleContext);
asyncMP.start();
asyncReplyMP.setListener(asyncMP);
asyncReplyMP.setReplySource(target.getMessageSource());
asyncReplyMP.setMuleContext(muleContext);
CoreEvent event = eventBuilder(muleContext).message(of(TEST_MESSAGE)).build();
try {
asyncReplyMP.process(event);
fail("ResponseTimeoutException expected");
} catch (Exception e) {
assertThat(e, instanceOf(ResponseTimeoutException.class));
}
}
Aggregations