Search in sources :

Example 66 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class TransformerChainingTestCase method testIgnoreBadInputBreaksChainWithTransformationOrderInvalidValid.

@Test
public void testIgnoreBadInputBreaksChainWithTransformationOrderInvalidValid() throws Exception {
    AbstractTransformer invalidTransformer = (AbstractTransformer) this.getInvalidTransformer();
    assertNotNull(invalidTransformer);
    invalidTransformer.setIgnoreBadInput(false);
    AbstractTransformer validTransformer = (AbstractTransformer) this.getIncreaseByOneTransformer();
    assertNotNull(validTransformer);
    Message message = of(new Integer(0));
    Transformer messageTransformer = new TransformerChain(invalidTransformer, validTransformer);
    try {
        transformationService.applyTransformers(message, eventBuilder(muleContext).message(of(0)).build(), messageTransformer);
        fail("Transformer chain is expected to fail because of invalid transformer within chain.");
    } catch (MuleException tfe) {
    // ignore
    }
}
Also used : Message(org.mule.runtime.api.message.Message) TransformerChain(org.mule.runtime.core.privileged.transformer.TransformerChain) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 67 with MuleException

use of org.mule.runtime.api.exception.MuleException 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)

Example 68 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class AbstractProcessingStrategyTestCase method concurrentStream.

@Test
public void concurrentStream() throws Exception {
    flow = flowBuilder.get().processors(cpuLightProcessor).build();
    flow.initialise();
    flow.start();
    CountDownLatch latch = new CountDownLatch(STREAM_ITERATIONS);
    for (int i = 0; i < CONCURRENT_TEST_CONCURRENCY; i++) {
        asyncExecutor.submit(() -> {
            for (int j = 0; j < STREAM_ITERATIONS / CONCURRENT_TEST_CONCURRENCY; j++) {
                try {
                    dispatchFlow(newEvent(), t -> latch.countDown(), response -> bubble(new AssertionError("Unexpected error")));
                } catch (MuleException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }
    assertThat(latch.await(RECEIVE_TIMEOUT, MILLISECONDS), is(true));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MuleException(org.mule.runtime.api.exception.MuleException) Exceptions.rxExceptionToMuleException(org.mule.runtime.core.api.rx.Exceptions.rxExceptionToMuleException) Test(org.junit.Test)

Aggregations

MuleException (org.mule.runtime.api.exception.MuleException)68 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)21 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)19 Test (org.junit.Test)15 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)14 Processor (org.mule.runtime.core.api.processor.Processor)12 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 Logger (org.slf4j.Logger)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)6 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)6 Map (java.util.Map)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleContext (org.mule.runtime.core.api.MuleContext)5 LifecycleUtils.stopIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded)5 Thread.currentThread (java.lang.Thread.currentThread)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Startable (org.mule.runtime.api.lifecycle.Startable)4