use of org.mule.runtime.api.lifecycle.Stoppable 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();
}
use of org.mule.runtime.api.lifecycle.Stoppable 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();
}
use of org.mule.runtime.api.lifecycle.Stoppable in project mule by mulesoft.
the class LifecycleFilterServiceProxyTestCase method avoidsStopExecution.
@Test
public void avoidsStopExecution() throws Exception {
StoppableService service = mock(StoppableService.class);
final Stoppable serviceProxy = (Stoppable) createLifecycleFilterServiceProxy(service);
expected.expect(UnsupportedOperationException.class);
serviceProxy.stop();
}
Aggregations