Search in sources :

Example 1 with Startable

use of org.mule.runtime.api.lifecycle.Startable in project mule by mulesoft.

the class DefaultFlowTestCase method testFailStartingMessageSourceOnLifecycleShouldStopStartedPipelineProcesses.

@Test
public void testFailStartingMessageSourceOnLifecycleShouldStopStartedPipelineProcesses() throws Exception {
    // Need to start mule context to have endpoints started during flow start
    muleContext.start();
    MessageSource mockMessageSource = mock(MessageSource.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
    doThrow(new LifecycleException(mock(I18nMessage.class), mockMessageSource)).when(((Startable) mockMessageSource)).start();
    final List<Processor> processors = new ArrayList<>(flow.getProcessors());
    Processor mockMessageProcessor = spy(new LifecycleTrackerProcessor());
    processors.add(mockMessageProcessor);
    after();
    flow = (DefaultFlow) Flow.builder(FLOW_NAME, muleContext).source(mockMessageSource).processors(processors).build();
    flow.initialise();
    try {
        flow.start();
        fail();
    } catch (LifecycleException e) {
    }
    verify((Startable) mockMessageProcessor, times(1)).start();
    verify((Stoppable) mockMessageProcessor, times(1)).stop();
    verify((Startable) mockMessageSource, times(1)).start();
    verify((Stoppable) mockMessageSource, times(1)).stop();
}
Also used : Startable(org.mule.runtime.api.lifecycle.Startable) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) 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) LifecycleTrackerProcessor(org.mule.tck.core.lifecycle.LifecycleTrackerProcessor) ArrayList(java.util.ArrayList) MessageSource(org.mule.runtime.core.api.source.MessageSource) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) Test(org.junit.Test)

Example 2 with Startable

use of org.mule.runtime.api.lifecycle.Startable 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 3 with Startable

use of org.mule.runtime.api.lifecycle.Startable in project mule by mulesoft.

the class AbstractMessageProcessorChain method start.

@Override
public void start() throws MuleException {
    List<Processor> startedProcessors = new ArrayList<>();
    try {
        for (Processor processor : getMessageProcessorsForLifecycle()) {
            if (processor instanceof Startable) {
                ((Startable) processor).start();
                startedProcessors.add(processor);
            }
        }
    } catch (MuleException e) {
        stopIfNeeded(getMessageProcessorsForLifecycle());
        throw e;
    }
}
Also used : Startable(org.mule.runtime.api.lifecycle.Startable) InterceptedReactiveProcessor(org.mule.runtime.core.internal.processor.chain.InterceptedReactiveProcessor) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) MuleException(org.mule.runtime.api.exception.MuleException)

Example 4 with Startable

use of org.mule.runtime.api.lifecycle.Startable in project mule by mulesoft.

the class LifecycleFilterServiceProxyTestCase method avoidsStartExecution.

@Test
public void avoidsStartExecution() throws Exception {
    StartableService service = mock(StartableService.class);
    final Startable serviceProxy = (Startable) createLifecycleFilterServiceProxy(service);
    expected.expect(UnsupportedOperationException.class);
    serviceProxy.start();
}
Also used : Startable(org.mule.runtime.api.lifecycle.Startable) Test(org.junit.Test)

Example 5 with Startable

use of org.mule.runtime.api.lifecycle.Startable in project mule by mulesoft.

the class MuleServiceManager method startServices.

private void startServices() throws MuleException {
    for (Pair<ArtifactClassLoader, Service> pair : registeredServices) {
        Service service = pair.getSecond();
        if (service instanceof Startable) {
            ClassLoader originalContextClassLoader = currentThread().getContextClassLoader();
            try {
                currentThread().setContextClassLoader(service.getClass().getClassLoader());
                ((Startable) service).start();
                startedServices.add(service);
                if (isNotEmpty(service.getSplashMessage())) {
                    logger.info(new ServiceSplashScreen(service).toString());
                }
            } finally {
                currentThread().setContextClassLoader(originalContextClassLoader);
            }
        }
    }
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) Startable(org.mule.runtime.api.lifecycle.Startable) Service(org.mule.runtime.api.service.Service) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)

Aggregations

Startable (org.mule.runtime.api.lifecycle.Startable)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Processor (org.mule.runtime.core.api.processor.Processor)3 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)3 MuleException (org.mule.runtime.api.exception.MuleException)2 LifecycleException (org.mule.runtime.api.lifecycle.LifecycleException)2 Stoppable (org.mule.runtime.api.lifecycle.Stoppable)2 MessageSource (org.mule.runtime.core.api.source.MessageSource)2 SensingNullMessageProcessor (org.mule.tck.SensingNullMessageProcessor)2 LifecycleTrackerProcessor (org.mule.tck.core.lifecycle.LifecycleTrackerProcessor)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