@Test(timeout = 1000) public void testAddStartedSiblingInInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); sibling.init(new Configuration()); sibling.start(); parent.addService(new AddSiblingService(parent, sibling, STATE.INITED)); parent.init(new Configuration()); assertInState(STATE.STARTED, sibling); parent.start(); assertInState(STATE.STARTED, sibling); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); assertInState(STATE.STOPPED, sibling); }
@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) { //expected } parent.stop(); }
@Test(timeout = 1000) public void testAddUninitedSiblingInInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); parent.addService(new AddSiblingService(parent, sibling, STATE.INITED)); parent.init(new Configuration()); try { parent.start(); fail("Expected an exception, got " + parent); } catch (ServiceStateException e) { //expected } parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@Test(timeout = 1000) public void testAddUninitedSiblingInInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); parent.addService(new AddSiblingService(parent, sibling, STATE.INITED)); parent.init(new Configuration()); try { parent.start(); fail("Expected an exception, got " + parent); } catch (ServiceStateException e) { //expected } parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@Test(timeout = 1000) public void testAddStartedSiblingInInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); sibling.init(new Configuration()); sibling.start(); parent.addService(new AddSiblingService(parent, sibling, STATE.INITED)); parent.init(new Configuration()); assertInState(STATE.STARTED, sibling); parent.start(); assertInState(STATE.STARTED, sibling); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); assertInState(STATE.STOPPED, sibling); }
@Test(timeout = 1000) public void testAddStartedSiblingInStart() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); sibling.init(new Configuration()); sibling.start(); parent.addService(new AddSiblingService(parent, sibling, STATE.STARTED)); parent.init(new Configuration()); parent.start(); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@Test(timeout = 1000) public void testAddStartedSiblingInStart() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); sibling.init(new Configuration()); sibling.start(); parent.addService(new AddSiblingService(parent, sibling, STATE.STARTED)); parent.init(new Configuration()); parent.start(); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@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) { //expected } parent.stop(); }
@Test(timeout = 1000) public void testAddStartedSiblingInStop() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); sibling.init(new Configuration()); sibling.start(); parent.addService(new AddSiblingService(parent, sibling, STATE.STOPPED)); parent.init(new Configuration()); parent.start(); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@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) { //expected } parent.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) { //expected } parent.stop(); }
@Test(timeout = 1000) public void testAddStartedSiblingInStop() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); sibling.init(new Configuration()); sibling.start(); parent.addService(new AddSiblingService(parent, sibling, STATE.STOPPED)); parent.init(new Configuration()); parent.start(); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@Test(timeout = 1000) public void testAddInitedSiblingInInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); sibling.init(new Configuration()); parent.addService(new AddSiblingService(parent, sibling, STATE.INITED)); parent.init(new Configuration()); parent.start(); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@Test(timeout = 1000) public void testAddInitedSiblingInInit() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); sibling.init(new Configuration()); parent.addService(new AddSiblingService(parent, sibling, STATE.INITED)); parent.init(new Configuration()); parent.start(); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@Test(timeout = 1000) public void testAddUninitedSiblingInStart() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); parent.addService(new AddSiblingService(parent, sibling, STATE.STARTED)); parent.init(new Configuration()); assertInState(STATE.NOTINITED, sibling); parent.start(); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@Test(timeout = 1000) public void testAddUninitedSiblingInStart() throws Throwable { CompositeService parent = new CompositeService("parent"); BreakableService sibling = new BreakableService(); parent.addService(new AddSiblingService(parent, sibling, STATE.STARTED)); parent.init(new Configuration()); assertInState(STATE.NOTINITED, sibling); parent.start(); parent.stop(); assertEquals("Incorrect number of services", 2, parent.getServices().size()); }
@Override protected void serviceStop() throws Exception { maybeAddSibling(); super.serviceStop(); }
@Override protected void serviceInit(Configuration conf) throws Exception { maybeAddSibling(); super.serviceInit(conf); }
/** * Add the serviceToAdd to the parent if this service * is in the state requested */ private void maybeAddSibling() { if (getServiceState() == triggerState) { parent.addService(serviceToAdd); } }
@Override protected void serviceStart() throws Exception { maybeAddSibling(); super.serviceStart(); }