use of org.mule.runtime.extension.api.runtime.route.Chain in project mule by mulesoft.
the class NestedProcessorValueResolverTestCase method yieldsNestedProcessor.
@Test
public void yieldsNestedProcessor() throws Exception {
ProcessorChainValueResolver resolver = new ProcessorChainValueResolver(muleContext, messageProcessor);
final CoreEvent event = testEvent();
Chain nestedProcessor = resolver.resolve(ValueResolvingContext.from(event));
nestedProcessor.process(result -> {
assertThat(result.getOutput(), is(TEST_PAYLOAD));
ArgumentCaptor<CoreEvent> captor = ArgumentCaptor.forClass(CoreEvent.class);
try {
verify(messageProcessor).process(captor.capture());
} catch (MuleException e) {
throw new RuntimeException(e);
}
CoreEvent capturedEvent = captor.getValue();
assertThat(capturedEvent, is(event));
}, (e, r) -> fail(e.getMessage()));
}
use of org.mule.runtime.extension.api.runtime.route.Chain in project mule by mulesoft.
the class HeisenbergRouters method concurrentRouteExecutor.
public void concurrentRouteExecutor(WhenRoute when, RouterCompletionCallback callback) {
Consumer<Chain> processor = (chain) -> {
final Latch latch = new Latch();
chain.process((result -> latch.release()), (error, result) -> latch.release());
try {
latch.await(10000, MILLISECONDS);
} catch (Exception e) {
throw new RuntimeException(e);
}
};
Thread first = new Thread(() -> processor.accept(when.getChain()));
Thread second = new Thread(() -> processor.accept(when.getChain()));
first.start();
second.start();
try {
first.join();
second.join();
} catch (Exception e) {
callback.error(e);
}
callback.success(Result.builder().output("SUCCESS").build());
}
use of org.mule.runtime.extension.api.runtime.route.Chain in project mule by mulesoft.
the class NestedProcessorValueResolverTestCase method alwaysGivesDifferentInstances.
@Test
public void alwaysGivesDifferentInstances() throws Exception {
ProcessorChainValueResolver resolver = new ProcessorChainValueResolver(muleContext, messageProcessor);
Chain resolved1 = resolver.resolve(ValueResolvingContext.from(testEvent()));
Chain resolved2 = resolver.resolve(ValueResolvingContext.from(testEvent()));
assertThat(resolved1, is(not(sameInstance(resolved2))));
}
Aggregations