@Override public void start() throws LifecycleException { event.fire(new BeforeStart(deployableContainer)); try { deployableContainer.start(); setState(Container.State.STARTED); } catch (LifecycleException e) { setState(State.STARTED_FAILED); failureCause = e; throw e; } event.fire(new AfterStart(deployableContainer)); }
@Override public void start() throws LifecycleException { event.fire(new BeforeStart(deployableContainer)); try { deployableContainer.start(); setState(Container.State.STARTED); } catch (LifecycleException e) { setState(State.STARTED_FAILED); failureCause = e; throw e; } event.fire(new AfterStart(deployableContainer)); }
@Test public void shouldUsePreRunningContainerInStartOrConnectMode() { Map<String, String> data = new HashMap<String, String>(); data.put("connectionMode", ConnectionMode.STARTORCONNECT.name()); bind(ApplicationScoped.class, CubeConfiguration.class, CubeConfiguration.fromMap(data)); when(cube.isRunningOnRemote()).thenReturn(true); fire(new BeforeStart(deployableContainer)); assertEventFired(PreRunningCube.class, 1); }
@Test public void shouldNotCreateAndStartWhenNoCubeFoundMatchingContainer() { when(container.getName()).thenReturn(MISSING_CUBE_ID); fire(new BeforeStart(deployableContainer)); assertEventFired(CreateCube.class, 0); assertEventFired(StartCube.class, 0); }
@Test public void shouldStartAContainerInStartOrConnectModeAndStopIt() { Map<String, String> data = new HashMap<String, String>(); data.put("connectionMode", ConnectionMode.STARTORCONNECT.name()); bind(ApplicationScoped.class, CubeConfiguration.class, CubeConfiguration.fromMap(data)); when(cube.isRunningOnRemote()).thenReturn(false); fire(new BeforeStart(deployableContainer)); assertEventFired(CreateCube.class, 1); assertEventFired(StartCube.class, 1); assertEventFired(PreRunningCube.class, 0); }
@Test public void shouldStartAContainerInStartOrConnectLeaveModeAndNotStopIt() { Map<String, String> data = new HashMap<String, String>(); data.put("connectionMode", ConnectionMode.STARTORCONNECTANDLEAVE.name()); bind(ApplicationScoped.class, CubeConfiguration.class, CubeConfiguration.fromMap(data)); when(cube.isRunningOnRemote()).thenReturn(false); fire(new BeforeStart(deployableContainer)); assertEventFired(CreateCube.class, 1); assertEventFired(StartCube.class, 1); assertEventFired(PreRunningCube.class, 1); }
@Test public void shouldCreateAndStartCubeDuringBeforeStart() { fire(new BeforeStart(deployableContainer)); assertEventFired(CreateCube.class, 1); assertEventFired(StartCube.class, 1); }
@Test public void shouldNotCreateAndStartWhenNoContainerFound() { fire(new BeforeStart(deployableContainerNoMatch)); assertEventFired(CreateCube.class, 0); assertEventFired(StartCube.class, 0); }