Search in sources :

Example 1 with Processor

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

the class DefaultFlowBuilderTestCase method buildsFullFlow.

@Test
public void buildsFullFlow() throws Exception {
    Processor processor1 = mock(Processor.class);
    Processor processor2 = mock(Processor.class);
    List<Processor> messageProcessors = new ArrayList<>();
    messageProcessors.add(processor1);
    messageProcessors.add(processor2);
    MessageSource messageSource = mock(MessageSource.class);
    ProcessingStrategyFactory processingStrategyFactory = mock(ProcessingStrategyFactory.class);
    ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class);
    when(processingStrategyFactory.create(any(), any())).thenReturn(processingStrategy);
    FlowExceptionHandler exceptionListener = mock(FlowExceptionHandler.class);
    Flow flow = flowBuilder.processors(messageProcessors).source(messageSource).processingStrategyFactory(processingStrategyFactory).messagingExceptionHandler(exceptionListener).build();
    assertThat(flow.getName(), equalTo(FLOW_NAME));
    assertThat(flow.getMuleContext(), is(muleContext));
    assertThat(flow.getProcessors(), contains(processor1, processor2));
    assertThat(flow.getSource(), is(messageSource));
    assertThat(flow.getExceptionListener(), is(exceptionListener));
    assertThat(flow.getProcessingStrategy(), sameInstance(processingStrategy));
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) MessageSource(org.mule.runtime.core.api.source.MessageSource) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) FlowExceptionHandler(org.mule.runtime.core.api.exception.FlowExceptionHandler) Flow(org.mule.runtime.core.api.construct.Flow) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with Processor

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

the class MessageProcessingFlowTraceManagerTestCase method createMockProcessor.

public Processor createMockProcessor(String processorPath, boolean useLocationSettings) {
    ComponentLocation componentLocation = mock(ComponentLocation.class);
    when(componentLocation.getLocation()).thenReturn(processorPath);
    when(componentLocation.getFileName()).thenReturn(useLocationSettings ? of(CONFIG_FILE_NAME) : empty());
    when(componentLocation.getLineInFile()).thenReturn(useLocationSettings ? of(LINE_NUMBER) : empty());
    Component annotatedMessageProcessor = (Component) mock(Processor.class, withSettings().extraInterfaces(Component.class).defaultAnswer(RETURNS_DEEP_STUBS));
    when(annotatedMessageProcessor.getAnnotation(any())).thenReturn(null);
    when(annotatedMessageProcessor.getLocation()).thenReturn(componentLocation);
    return (Processor) annotatedMessageProcessor;
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) Processor(org.mule.runtime.core.api.processor.Processor) Component(org.mule.runtime.api.component.Component)

Example 3 with Processor

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

the class MessageProcessingFlowTraceManagerTestCase method newAnnotatedComponentCall.

@Test
public void newAnnotatedComponentCall() {
    CoreEvent event = buildEvent("newAnnotatedComponentCall");
    PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName());
    assertThat(getContextInfo(event, rootFlowConstruct), is(""));
    manager.onPipelineNotificationStart(pipelineNotification);
    assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName()));
    Component annotatedMessageProcessor = (Component) createMockProcessor("/comp", true);
    when(annotatedMessageProcessor.getAnnotation(docNameAttrName)).thenReturn("annotatedName");
    manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, (Processor) annotatedMessageProcessor));
    assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":muleApp.xml:10 (annotatedName))"));
    manager.onPipelineNotificationComplete(pipelineNotification);
    assertThat(getContextInfo(event, rootFlowConstruct), is(""));
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) PipelineMessageNotification(org.mule.runtime.api.notification.PipelineMessageNotification) Component(org.mule.runtime.api.component.Component) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with Processor

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

the class AbstractForkJoinStrategyTestCase method errorDelayed.

@Test
@Description("When an error occurs all routes are executed regardless and a CompositeRoutingException is thrown containing a RoutingResult with details of both failures and successes.")
public void errorDelayed() throws Throwable {
    Processor processorSpy = createProcessorSpy(testEvent().getMessage());
    RuntimeException exception1 = new IllegalStateException();
    RoutingPair failingPair1 = of(testEvent(), createFailingRoutingPair(exception1));
    RuntimeException exception2 = new UnsupportedOperationException();
    RoutingPair failingPair2 = of(testEvent(), createFailingRoutingPair(exception2));
    RuntimeException exception3 = new IndexOutOfBoundsException();
    RoutingPair failingPair3 = of(testEvent(), createFailingRoutingPair(exception3));
    RoutingPair okPair = of(testEvent(), createChain(processorSpy));
    expectedException.expect(instanceOf(CompositeRoutingException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair1, failingPair2, failingPair3, okPair), throwable -> {
        verify(processorSpy, times(1)).process(any(CoreEvent.class));
        CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 3);
        RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 1, 3);
        assertThat(routingResult.getFailures().get("0").getCause(), is(exception1));
        assertThat(routingResult.getFailures().get("1").getCause(), is(exception2));
        assertThat(routingResult.getFailures().get("2").getCause(), is(exception3));
        assertThat(routingResult.getFailures().get("3"), is(nullValue()));
    });
}
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) 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)

Example 5 with Processor

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

the class AbstractForkJoinStrategyTestCase method timeoutEager.

@Test
@Description("When configured with delayErrors='false' the first timeout causes strategy to throw a TimeoutException.")
public void timeoutEager() throws Throwable {
    strategy = createStrategy(processingStrategy, 1, false, 50);
    Message pair2Result = of(2);
    Processor pair2Processor = createProcessorSpy(pair2Result);
    RoutingPair pair2 = of(testEvent(), createChain(pair2Processor));
    expectedException.expect(instanceOf(DefaultMuleException.class));
    expectedException.expectCause(instanceOf(TimeoutException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250), pair2), throwable -> verify(pair2Processor, never()).process(any(CoreEvent.class)));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) 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) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) TimeoutException(java.util.concurrent.TimeoutException) 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