CompositeService extends AbstractService { private void stop(int numOfServicesStarted, boolean stopOnlyStartedServices) { Exception firstException = null; List<Service> services = getServices(); for (int i = numOfServicesStarted - 1; i >= 0; i--) { Service service = services.get(i); if (LOG.isDebugEnabled()) { LOG.debug("Stopping service #" + i + ": " + service); } STATE state = service.getServiceState(); if (state == STATE.STARTED || (!stopOnlyStartedServices && state == STATE.INITED)) { Exception ex = ServiceOperations.stopQuietly(LOG, service); if (ex != null && firstException == null) { firstException = ex; } } } if (firstException != null) { throw ServiceStateException.convert(firstException); } } CompositeService(String name); List<Service> getServices();  }
@Test(timeout = 10000) public void testAddUninitedChildBeforeInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); AddSiblingService.addChildToService(parent, child); parent.init(new Configuration()); assertInState(STATE.INITED, child); parent.start(); assertInState(STATE.STARTED, child); parent.stop(); assertInState(STATE.STOPPED, child); }
@Test(timeout = 10000) public void testAddUninitedChildInStart() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); parent.init(new Configuration()); parent.start(); AddSiblingService.addChildToService(parent, child); assertInState(STATE.NOTINITED, child); parent.stop(); assertInState(STATE.NOTINITED, child); }
@Test(timeout = 10000) public void testAddUninitedChildInStop() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); parent.init(new Configuration()); parent.start(); parent.stop(); AddSiblingService.addChildToService(parent, child); assertInState(STATE.NOTINITED, child); }
@Test(timeout = 10000) public void testAddInitedChildBeforeInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); AddSiblingService.addChildToService(parent, child); parent.init(new Configuration()); assertInState(STATE.INITED, child); parent.start(); assertInState(STATE.STARTED, child); parent.stop(); assertInState(STATE.STOPPED, child); }
@Test(timeout = 10000) public void testAddInitedChildInInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); parent.init(new Configuration()); AddSiblingService.addChildToService(parent, child); parent.start(); assertInState(STATE.STARTED, child); parent.stop(); assertInState(STATE.STOPPED, child); }
@Test(timeout = 10000) public void testAddInitedChildInStart() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); parent.init(new Configuration()); parent.start(); AddSiblingService.addChildToService(parent, child); assertInState(STATE.INITED, child); parent.stop(); assertInState(STATE.STOPPED, child); }
@Test(timeout = 10000) public void testAddInitedChildInStop() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); parent.init(new Configuration()); parent.start(); parent.stop(); AddSiblingService.addChildToService(parent, child); assertInState(STATE.INITED, child); }
@Test(timeout = 10000) public void testAddStartedChildInInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); child.start(); parent.init(new Configuration()); AddSiblingService.addChildToService(parent, child); parent.start(); assertInState(STATE.STARTED, child); parent.stop(); assertInState(STATE.STOPPED, child); }
@Test(timeout = 10000) public void testAddStartedChildInStart() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); child.start(); parent.init(new Configuration()); parent.start(); AddSiblingService.addChildToService(parent, child); assertInState(STATE.STARTED, child); parent.stop(); assertInState(STATE.STOPPED, child); }
@Test(timeout = 10000) public void testAddStartedChildInStop() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); child.start(); parent.init(new Configuration()); parent.start(); parent.stop(); AddSiblingService.addChildToService(parent, child); assertInState(STATE.STARTED, child); }
@Test(timeout = 10000) public void testAddStoppedChildInStart() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); child.start(); child.stop(); parent.init(new Configuration()); parent.start(); AddSiblingService.addChildToService(parent, child); parent.stop(); }
@Test(timeout = 10000) public void testAddStoppedChildInStop() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); child.start(); child.stop(); parent.init(new Configuration()); parent.start(); parent.stop(); AddSiblingService.addChildToService(parent, child); }
@Test public void testServiceLifecycleNoChildren() { ServiceManager serviceManager = new ServiceManager("ServiceManager"); serviceManager.init(new Configuration()); serviceManager.start(); serviceManager.stop(); }
@Test(timeout = 1000) public void testAddStartedChildBeforeInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); child.start(); AddSiblingService.addChildToService(parent, child); try { parent.init(new Configuration()); fail("Expected an exception, got " + parent); } catch (ServiceStateException e) { } parent.stop(); }
@Test(timeout = 1000) public void testAddStoppedChildBeforeInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService child = new BreakableService(); child.init(new Configuration()); child.start(); child.stop(); AddSiblingService.addChildToService(parent, child); try { parent.init(new Configuration()); fail("Expected an exception, got " + parent); } catch (ServiceStateException e) { } parent.stop(); }