Search in sources :

Example 1 with BLOCKING

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;
        }));
    }
}
Also used : Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) Thread.currentThread(java.lang.Thread.currentThread) IO_RW(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.IO_RW) DEFAULT_TIMEOUT(org.mule.tck.probe.PollingProber.DEFAULT_TIMEOUT) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Future(java.util.concurrent.Future) LifecycleUtils.setMuleContextIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.setMuleContextIfNeeded) Arrays.asList(java.util.Arrays.asList) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) NamedThreadFactory(org.mule.runtime.core.api.util.concurrent.NamedThreadFactory) SOURCE(org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategyTestCase.Mode.SOURCE) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Operators.requestUnbounded(org.mule.runtime.core.internal.util.rx.Operators.requestUnbounded) Builder(org.mule.runtime.core.api.construct.Flow.Builder) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.contains(org.hamcrest.Matchers.contains) DEFAULT_POLLING_INTERVAL(org.mule.tck.probe.PollingProber.DEFAULT_POLLING_INTERVAL) TriggerableMessageSource(org.mule.tck.TriggerableMessageSource) RunWith(org.junit.runner.RunWith) Callable(java.util.concurrent.Callable) Supplier(java.util.function.Supplier) MESSAGE_PROCESSOR_POST_INVOKE(org.mule.runtime.api.notification.MessageProcessorNotification.MESSAGE_PROCESSOR_POST_INVOKE) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleException(org.mule.runtime.api.exception.MuleException) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) EventContextFactory.create(org.mule.runtime.core.api.event.EventContextFactory.create) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) MessageProcessorNotificationListener(org.mule.runtime.api.notification.MessageProcessorNotificationListener) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Flux(reactor.core.publisher.Flux) IntegerAction(org.mule.runtime.api.notification.IntegerAction) Matcher(org.hamcrest.Matcher) BackPressureStrategy(org.mule.runtime.core.api.source.MessageSource.BackPressureStrategy) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Flow.builder(org.mule.runtime.core.api.construct.Flow.builder) ScheduledFuture(java.util.concurrent.ScheduledFuture) Collections.synchronizedSet(java.util.Collections.synchronizedSet) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) PROCESSOR_SCHEDULER_CONTEXT_KEY(org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategy.PROCESSOR_SCHEDULER_CONTEXT_KEY) Scheduler(org.mule.runtime.api.scheduler.Scheduler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Mono.just(reactor.core.publisher.Mono.just) Thread.sleep(java.lang.Thread.sleep) Exceptions.bubble(reactor.core.Exceptions.bubble) Parameterized(org.junit.runners.Parameterized) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) TimeZone(java.util.TimeZone) Collection(java.util.Collection) MessageProcessorNotification(org.mule.runtime.api.notification.MessageProcessorNotification) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Flow(org.mule.runtime.core.api.construct.Flow) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) FlowBackPressureException(org.mule.runtime.core.internal.construct.FlowBackPressureException) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) List(java.util.List) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) MESSAGE_PROCESSOR_PRE_INVOKE(org.mule.runtime.api.notification.MessageProcessorNotification.MESSAGE_PROCESSOR_PRE_INVOKE) CPU_LITE(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE) FLOW_BACK_PRESSURE_ERROR_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.FLOW_BACK_PRESSURE_ERROR_IDENTIFIER) ProcessingType(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Flux.from(reactor.core.publisher.Flux.from) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) BLOCKING(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.BLOCKING) HashSet(java.util.HashSet) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MuleContext(org.mule.runtime.core.api.MuleContext) CPU_LITE_ASYNC(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE_ASYNC) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ExpectedException(org.junit.rules.ExpectedException) ExecutorService(java.util.concurrent.ExecutorService) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) Logger(org.slf4j.Logger) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Latch(org.mule.runtime.api.util.concurrent.Latch) Rule(org.junit.Rule) Exceptions.rxExceptionToMuleException(org.mule.runtime.core.api.rx.Exceptions.rxExceptionToMuleException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) PollingProber(org.mule.tck.probe.PollingProber) TriggerableMessageSource(org.mule.tck.TriggerableMessageSource) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProcessingType(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType) MuleException(org.mule.runtime.api.exception.MuleException) Exceptions.rxExceptionToMuleException(org.mule.runtime.core.api.rx.Exceptions.rxExceptionToMuleException)

Aggregations

Thread.currentThread (java.lang.Thread.currentThread)1 Thread.sleep (java.lang.Thread.sleep)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.synchronizedSet (java.util.Collections.synchronizedSet)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 TimeZone (java.util.TimeZone)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newFixedThreadPool (java.util.concurrent.Executors.newFixedThreadPool)1 Future (java.util.concurrent.Future)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1