use of org.mule.runtime.core.api.source.MessageSource.BackPressureStrategy in project mule by mulesoft.
the class ExtensionSourceObjectFactory method doGetObject.
@Override
public ExtensionMessageSource doGetObject() throws ConfigurationException, InitialisationException {
return withContextClassLoader(getClassLoader(extensionModel), () -> {
getParametersResolver().checkParameterGroupExclusiveness(Optional.of(sourceModel), sourceModel.getParameterGroupModels(), parameters.keySet());
ResolverSet nonCallbackParameters = getNonCallbackParameters();
if (nonCallbackParameters.isDynamic()) {
throw dynamicParameterException(nonCallbackParameters, sourceModel);
}
ResolverSet responseCallbackParameters = getCallbackParameters(sourceModel.getSuccessCallback());
ResolverSet errorCallbackParameters = getCallbackParameters(sourceModel.getErrorCallback());
initialiseIfNeeded(nonCallbackParameters, true, muleContext);
initialiseIfNeeded(responseCallbackParameters, true, muleContext);
initialiseIfNeeded(errorCallbackParameters, true, muleContext);
final BackPressureStrategy backPressureStrategy = getBackPressureStrategy();
return new ExtensionMessageSource(extensionModel, sourceModel, getSourceAdapterFactory(nonCallbackParameters, responseCallbackParameters, errorCallbackParameters, backPressureStrategy), configurationProvider, primaryNodeOnly != null ? primaryNodeOnly : sourceModel.runsOnPrimaryNodeOnly(), getRetryPolicyTemplate(), cursorProviderFactory, backPressureStrategy, muleContext.getExtensionManager());
});
}
use of org.mule.runtime.core.api.source.MessageSource.BackPressureStrategy 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