Search in sources :

Example 1 with DefaultFlow

use of org.mule.runtime.core.internal.construct.DefaultFlowBuilder.DefaultFlow 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 2 with DefaultFlow

use of org.mule.runtime.core.internal.construct.DefaultFlowBuilder.DefaultFlow in project mule by mulesoft.

the class DefaultFlowFactoryBean method getObject.

@Override
public Flow getObject() throws Exception {
    Builder flowBuilder = Flow.builder(name, muleContext).messagingExceptionHandler(exceptionListener).initialState(initialState);
    flowBuilder.processors(messageProcessors != null ? messageProcessors : emptyList());
    if (messageSource != null) {
        flowBuilder.source(messageSource);
    }
    if (processingStrategyFactory != null) {
        flowBuilder.processingStrategyFactory(processingStrategyFactory);
    }
    if (maxConcurrency != null) {
        flowBuilder.maxConcurrency(maxConcurrency.intValue());
    }
    final DefaultFlow build = (DefaultFlow) flowBuilder.build();
    build.setAnnotations(getAnnotations());
    return build;
}
Also used : Builder(org.mule.runtime.core.api.construct.Flow.Builder) DefaultFlow(org.mule.runtime.core.internal.construct.DefaultFlowBuilder.DefaultFlow)

Aggregations

DefaultFlow (org.mule.runtime.core.internal.construct.DefaultFlowBuilder.DefaultFlow)2 Thread.currentThread (java.lang.Thread.currentThread)1 ArrayList (java.util.ArrayList)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 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 ExpectedException.none (org.junit.rules.ExpectedException.none)1 RunWith (org.junit.runner.RunWith)1