Search in sources :

Example 1 with ProcessingStrategy

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

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

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

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

the class DefaultFlowTestCase method lifecycleOrder.

@Test
public void lifecycleOrder() throws MuleException {
    Sink sink = mock(Sink.class, withSettings().extraInterfaces(Disposable.class));
    Processor processor = mock(Processor.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
    ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
    when(processingStrategy.createSink(any(FlowConstruct.class), any(ReactiveProcessor.class))).thenReturn(sink);
    flow = (DefaultFlow) Flow.builder(FLOW_NAME, muleContext).source(directInboundMessageSource).processors(singletonList(processor)).processingStrategyFactory((muleContext, s) -> processingStrategy).build();
    flow.initialise();
    flow.start();
    InOrder inOrder = inOrder(sink, processor, processingStrategy);
    inOrder.verify((Startable) processingStrategy).start();
    inOrder.verify(processingStrategy).createSink(any(FlowConstruct.class), any(ReactiveProcessor.class));
    inOrder.verify((Startable) processor).start();
    flow.stop();
    inOrder.verify((Disposable) sink).dispose();
    inOrder.verify((Stoppable) processor).stop();
    inOrder.verify((Stoppable) processingStrategy).stop();
}
Also used : Disposable(org.mule.runtime.api.lifecycle.Disposable) INITIAL_STATE_STOPPED(org.mule.runtime.core.api.construct.Flow.INITIAL_STATE_STOPPED) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) BiFunction(java.util.function.BiFunction) DefaultFlow(org.mule.runtime.core.internal.construct.DefaultFlowBuilder.DefaultFlow) Thread.currentThread(java.lang.Thread.currentThread) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Mono.just(reactor.core.publisher.Mono.just) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Assert.fail(org.junit.Assert.fail) Parameterized(org.junit.runners.Parameterized) Startable(org.mule.runtime.api.lifecycle.Startable) I18nMessage(org.mule.runtime.api.i18n.I18nMessage) StringAppendTransformer(org.mule.runtime.core.internal.transformer.simple.StringAppendTransformer) Collection(java.util.Collection) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Message.of(org.mule.runtime.api.message.Message.of) Flow(org.mule.runtime.core.api.construct.Flow) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) ResponseMessageProcessorAdapter(org.mule.runtime.core.internal.processor.ResponseMessageProcessorAdapter) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.inOrder(org.mockito.Mockito.inOrder) Mockito.withSettings(org.mockito.Mockito.withSettings) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Mockito.mock(org.mockito.Mockito.mock) LifecycleTrackerProcessor(org.mule.tck.core.lifecycle.LifecycleTrackerProcessor) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) MessageSource(org.mule.runtime.core.api.source.MessageSource) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Mockito.spy(org.mockito.Mockito.spy) Processor(org.mule.runtime.core.api.processor.Processor) BLOCKING(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.BLOCKING) ArrayList(java.util.ArrayList) DEFAULT_MAX_CONCURRENCY(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory.DEFAULT_MAX_CONCURRENCY) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) Disposable(org.mule.runtime.api.lifecycle.Disposable) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) BlockingProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.BlockingProcessingStrategyFactory) InOrder(org.mockito.InOrder) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Sink(org.mule.runtime.core.api.processor.Sink) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) Startable(org.mule.runtime.api.lifecycle.Startable) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) LifecycleTrackerProcessor(org.mule.tck.core.lifecycle.LifecycleTrackerProcessor) Processor(org.mule.runtime.core.api.processor.Processor) InOrder(org.mockito.InOrder) Sink(org.mule.runtime.core.api.processor.Sink) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) Test(org.junit.Test)

Example 5 with ProcessingStrategy

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

Test (org.junit.Test)5 ProcessingStrategy (org.mule.runtime.core.api.processor.strategy.ProcessingStrategy)5 ProcessingStrategyFactory (org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory)3 SmallTest (org.mule.tck.size.SmallTest)3 ArrayList (java.util.ArrayList)2 Thread.currentThread (java.lang.Thread.currentThread)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 BiFunction (java.util.function.BiFunction)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 CoreMatchers.not (org.hamcrest.CoreMatchers.not)1 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)1 CoreMatchers.sameInstance (org.hamcrest.CoreMatchers.sameInstance)1 After (org.junit.After)1 Assert.assertThat (org.junit.Assert.assertThat)1 Assert.fail (org.junit.Assert.fail)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1