Search in sources :

Example 1 with ProcessingStrategyFactory

use of org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory 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 ProcessingStrategyFactory

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

the class FlowProcessingStrategyTestCase method fixedProcessingStrategyIsHonoured.

@Test
public void fixedProcessingStrategyIsHonoured() throws Exception {
    ProcessingStrategyFactory processingStrategyFactory = mock(ProcessingStrategyFactory.class);
    ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class);
    when(processingStrategyFactory.create(any(), any())).thenReturn(processingStrategy);
    createFlow(processingStrategyFactory);
    flow.initialise();
    assertThat(flow.getProcessingStrategy(), is(sameInstance(processingStrategy)));
}
Also used : ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with ProcessingStrategyFactory

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

the class FlowProcessingStrategyTestCase method defaultProcessingStrategyInConfigIsHonoured.

@Test
public void defaultProcessingStrategyInConfigIsHonoured() throws Exception {
    ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class);
    ProcessingStrategyFactory processingStrategyFactory = mock(ProcessingStrategyFactory.class);
    when(processingStrategyFactory.create(any(), any())).thenReturn(processingStrategy);
    when(configuration.getDefaultProcessingStrategyFactory()).thenReturn(processingStrategyFactory);
    createFlow(null);
    flow.initialise();
    assertThat(flow.getProcessingStrategy(), is(sameInstance(processingStrategy)));
}
Also used : ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with ProcessingStrategyFactory

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

the class AsyncDelegateMessageProcessor method initialise.

@Override
public void initialise() throws InitialisationException {
    Object rootContainer = getFromAnnotatedObject(componentLocator, this).orElse(null);
    if (rootContainer instanceof FlowConstruct) {
        if (maxConcurrency != null && rootContainer instanceof Pipeline) {
            ProcessingStrategyFactory flowPsFactory = ((Pipeline) rootContainer).getProcessingStrategyFactory();
            if (flowPsFactory instanceof AsyncProcessingStrategyFactory) {
                ((AsyncProcessingStrategyFactory) flowPsFactory).setMaxConcurrency(maxConcurrency);
            } else {
                logger.warn("{} does not support 'maxConcurrency'. Ignoring the value.", flowPsFactory.getClass().getSimpleName());
            }
            processingStrategy = flowPsFactory.create(muleContext, getLocation().getLocation());
            ownProcessingStrategy = true;
        } else {
            processingStrategy = ((FlowConstruct) rootContainer).getProcessingStrategy();
        }
    } else {
        processingStrategy = DIRECT_PROCESSING_STRATEGY_INSTANCE;
    }
    if (delegateBuilder == null) {
        throw new InitialisationException(objectIsNull("delegate message processor"), this);
    }
    delegateBuilder.setProcessingStrategy(processingStrategy);
    delegate = delegateBuilder.build();
    initialiseIfNeeded(delegate, muleContext);
    super.initialise();
}
Also used : FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) AsyncProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory) ComponentUtils.getFromAnnotatedObject(org.mule.runtime.core.internal.component.ComponentUtils.getFromAnnotatedObject) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) AsyncProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory) Pipeline(org.mule.runtime.core.api.construct.Pipeline)

Example 5 with ProcessingStrategyFactory

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

the class FlowProcessingStrategyTestCase method fixedProcessingStrategyTakesPrecedenceOverConfig.

@Test
public void fixedProcessingStrategyTakesPrecedenceOverConfig() throws Exception {
    ProcessingStrategyFactory configProcessingStrategyFactory = mock(ProcessingStrategyFactory.class);
    when(configuration.getDefaultProcessingStrategyFactory()).thenReturn(configProcessingStrategyFactory);
    ProcessingStrategyFactory processingStrategyFactory = mock(ProcessingStrategyFactory.class);
    ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class);
    when(processingStrategyFactory.create(any(), any())).thenReturn(processingStrategy);
    createFlow(processingStrategyFactory);
    flow.initialise();
    assertThat(flow.getProcessingStrategy(), is(sameInstance(processingStrategy)));
}
Also used : ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ProcessingStrategyFactory (org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory)5 Test (org.junit.Test)4 ProcessingStrategy (org.mule.runtime.core.api.processor.strategy.ProcessingStrategy)4 SmallTest (org.mule.tck.size.SmallTest)4 ArrayList (java.util.ArrayList)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 Flow (org.mule.runtime.core.api.construct.Flow)1 FlowConstruct (org.mule.runtime.core.api.construct.FlowConstruct)1 Pipeline (org.mule.runtime.core.api.construct.Pipeline)1 FlowExceptionHandler (org.mule.runtime.core.api.exception.FlowExceptionHandler)1 Processor (org.mule.runtime.core.api.processor.Processor)1 AsyncProcessingStrategyFactory (org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory)1 MessageSource (org.mule.runtime.core.api.source.MessageSource)1 ComponentUtils.getFromAnnotatedObject (org.mule.runtime.core.internal.component.ComponentUtils.getFromAnnotatedObject)1