use of org.mule.tck.junit4.AbstractReactiveProcessorTestCase.Mode.BLOCKING 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