Search in sources :

Example 31 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class AsyncRequestReplyRequesterTestCase method returnsNullWhenInterruptedWhileWaitingForReply.

@Test
@Ignore("See MULE-8830")
public void returnsNullWhenInterruptedWhileWaitingForReply() throws Exception {
    final Latch fakeLatch = new Latch() {

        @Override
        public void await() throws InterruptedException {
            throw new InterruptedException();
        }
    };
    asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext) {

        @Override
        protected Latch createEventLock() {
            return fakeLatch;
        }
    };
    final CountDownLatch processingLatch = new CountDownLatch(1);
    Processor target = mock(Processor.class);
    asyncReplyMP.setListener(target);
    MessageSource messageSource = mock(MessageSource.class);
    asyncReplyMP.setReplySource(messageSource);
    asyncReplyMP.setMuleContext(muleContext);
    final boolean[] exceptionThrown = new boolean[1];
    final Object[] responseEvent = new Object[1];
    Thread thread = new Thread(() -> {
        try {
            responseEvent[0] = asyncReplyMP.process(testEvent());
        } catch (MuleException e) {
            exceptionThrown[0] = true;
        } finally {
            processingLatch.countDown();
        }
    });
    thread.start();
    assertTrue(processingLatch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
    assertFalse(exceptionThrown[0]);
    assertNull(responseEvent[0]);
}
Also used : SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Processor(org.mule.runtime.core.api.processor.Processor) AsyncDelegateMessageProcessor(org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor) CountDownLatch(java.util.concurrent.CountDownLatch) Latch(org.mule.runtime.api.util.concurrent.Latch) MessageSource(org.mule.runtime.core.api.source.MessageSource) CountDownLatch(java.util.concurrent.CountDownLatch) MuleException(org.mule.runtime.api.exception.MuleException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method errorEager.

@Test
@Description("When configured with delayErrors='false' the first errors causes strategy to throw this exception.")
public void errorEager() throws Throwable {
    strategy = createStrategy(processingStrategy, 1, false, MAX_VALUE);
    Processor processorSpy = createProcessorSpy(of(1));
    RuntimeException exception = new IllegalStateException();
    RoutingPair failingPair = of(testEvent(), createFailingRoutingPair(exception));
    RoutingPair okPair = of(testEvent(), createChain(processorSpy));
    expectedException.expect(instanceOf(MessagingException.class));
    expectedException.expectCause(is(exception));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair, okPair), throwable -> verify(processorSpy, never()).process(any(CoreEvent.class)));
}
Also used : ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 33 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method errorEagerConcurrent.

@Test
@Description("When configured with delayErrors='false' the first errors causes strategy to throw this exception. Other routes may or may not be executed depending on concurrency.")
public void errorEagerConcurrent() throws Throwable {
    strategy = createStrategy(processingStrategy, 4, false, MAX_VALUE);
    Processor processorSpy = createProcessorSpy(of(1));
    Processor processorSpy2 = createProcessorSpy(of(2));
    Processor processorSpy3 = createProcessorSpy(of(3));
    CoreEvent orignial = testEvent();
    RuntimeException exception = new IllegalStateException();
    RoutingPair failingPair = of(orignial, createFailingRoutingPair(exception));
    RoutingPair okPair = of(orignial, createChain(processorSpy));
    RoutingPair okPair2 = of(orignial, createChain(processorSpy2));
    RoutingPair okPair3 = of(orignial, createChain(processorSpy3));
    expectedException.expect(instanceOf(MessagingException.class));
    expectedException.expectCause(is(exception));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair, okPair, okPair2, okPair3), throwable -> {
        verify(processorSpy, atMost(1)).process(any(CoreEvent.class));
        verify(processorSpy2, atMost(1)).process(any(CoreEvent.class));
        verify(processorSpy3, atMost(1)).process(any(CoreEvent.class));
    });
}
Also used : ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 34 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method timeoutDelayed.

@Test
@Description("When a route timeout occurs all routes are still executed and  a CompositeRoutingException is thrown with details of timeout error and successful routes in RoutingResult.")
public void timeoutDelayed() throws Throwable {
    strategy = createStrategy(processingStrategy, 1, true, 50);
    Message pair2Result = of(2);
    Processor pair2Processor = createProcessorSpy(pair2Result);
    RoutingPair pair2 = of(testEvent(), createChain(pair2Processor));
    expectedException.expect(instanceOf(CompositeRoutingException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250), pair2), throwable -> {
        verify(pair2Processor, times(1)).process(any(CoreEvent.class));
        CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 1);
        RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 1, 1);
        assertThat(routingResult.getFailures().get("0").getCause(), instanceOf(TimeoutException.class));
        assertThat(routingResult.getResults().get("1"), is(pair2Result));
    });
}
Also used : CompositeRoutingException(org.mule.runtime.core.privileged.routing.CompositeRoutingException) RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) TimeoutException(java.util.concurrent.TimeoutException) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 35 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class JoinOnlyForkJoinStrategyTestCase method joinOnly.

@Test
@Description("This strategy waits for all routes to return and then returns the original event.")
public void joinOnly() throws Throwable {
    CoreEvent original = testEvent();
    Processor processor1 = createProcessorSpy(of(1));
    Processor processor2 = createProcessorSpy(of(2));
    Processor processor3 = createProcessorSpy(of(3));
    RoutingPair pair1 = createRoutingPair(processor1);
    RoutingPair pair2 = createRoutingPair(processor2);
    RoutingPair pair3 = createRoutingPair(processor3);
    CoreEvent result = invokeStrategyBlocking(strategy, original, asList(pair1, pair2, pair3));
    assertThat(result, is(original));
    verify(processor1, times(1)).process(any(CoreEvent.class));
    verify(processor2, times(1)).process(any(CoreEvent.class));
    verify(processor2, times(1)).process(any(CoreEvent.class));
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

Processor (org.mule.runtime.core.api.processor.Processor)58 Test (org.junit.Test)31 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)24 MuleException (org.mule.runtime.api.exception.MuleException)15 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)14 Component (org.mule.runtime.api.component.Component)12 ArrayList (java.util.ArrayList)11 InternalProcessor (org.mule.runtime.core.privileged.processor.InternalProcessor)11 Publisher (org.reactivestreams.Publisher)11 Message (org.mule.runtime.api.message.Message)10 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)10 Map (java.util.Map)9 Arrays.asList (java.util.Arrays.asList)8 Flow (org.mule.runtime.core.api.construct.Flow)8 Inject (javax.inject.Inject)7 Assert.assertThat (org.junit.Assert.assertThat)7 Mockito.mock (org.mockito.Mockito.mock)7 Mockito.when (org.mockito.Mockito.when)7 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)7 Disposable (org.mule.runtime.api.lifecycle.Disposable)7