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();
}
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();
}
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;
}
}
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();
}
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);
}
}
}
}
Aggregations