@Override public void run() { try { Thread.sleep(lifespan); } catch (InterruptedException ignored) { } finish(); } });
void finish() { if (fail) { ServiceStateException e = new ServiceStateException(getName() + " failed"); noteFailure(e); stop(); throw e; } else { stop(); } }
@Test public void testTwoChildren() throws Throwable { MockService one = new MockService("one", false, 100); MockService two = new MockService("two", false, 100); ServiceParent parent = startService(one, two); waitForParentToStop(parent); assertStopped(one); assertStopped(two); }
@Test public void testFailingComposite() throws Throwable { MockService one = new MockService("one", true, 10); MockService two = new MockService("two", false, 1000); ServiceParent parent = startService(one, two); waitForParentToStop(parent); assertStopped(one); assertStopped(two); assertNotNull(one.getFailureCause()); assertNotNull(parent.getFailureCause()); assertEquals(one.getFailureCause(), parent.getFailureCause()); }
@Test public void testTwoChildren() throws Throwable { MockService one = new MockService("one", false, 100); MockService two = new MockService("two", false, 100); ServiceParent parent = startService(one, two); waitForParentToStop(parent); assertStopped(one); assertStopped(two); }
@Test public void testFailingComposite() throws Throwable { MockService one = new MockService("one", true, 10); MockService two = new MockService("two", false, 1000); ServiceParent parent = startService(one, two); waitForParentToStop(parent); assertStopped(one); assertStopped(two); assertNotNull(one.getFailureCause()); assertNotNull(parent.getFailureCause()); assertEquals(one.getFailureCause(), parent.getFailureCause()); }
@Test public void testSequence() throws Throwable { MockService one = new MockService("one", false, 100); MockService two = new MockService("two", false, 100); ServiceParent parent = startService(one, two); waitForParentToStop(parent); assertStopped(one); assertStopped(two); assert ((WorkflowSequenceService) parent).getPreviousService().equals(two); }
void finish() { if (fail) { ServiceStateException e = new ServiceStateException(getName() + " failed"); noteFailure(e); stop(); throw e; } else { stop(); } }
@Test public void testFailInStartNext() throws Throwable { MockService one = new MockService("one", false, 100); MockService two = new MockService("two", true, 0); MockService three = new MockService("3", false, 0); ServiceParent parent = startService(one, two, three); waitForParentToStop(parent); assertStopped(one); assertStopped(two); Throwable failureCause = two.getFailureCause(); assertNotNull(failureCause); Throwable parentFailureCause = parent.getFailureCause(); assertNotNull(parentFailureCause); assertEquals(parentFailureCause, failureCause); assertInState(three, Service.STATE.NOTINITED); }
@Override public void run() { try { Thread.sleep(lifespan); } catch (InterruptedException ignored) { } finish(); } });
@Test public void testSequence() throws Throwable { MockService one = new MockService("one", false, 100); MockService two = new MockService("two", false, 100); ServiceParent parent = startService(one, two); waitForParentToStop(parent); assertStopped(one); assertStopped(two); assert ((WorkflowSequenceService) parent).getPreviousService().equals(two); }
@Test public void testFailInStartNext() throws Throwable { MockService one = new MockService("one", false, 100); MockService two = new MockService("two", true, 0); MockService three = new MockService("3", false, 0); ServiceParent parent = startService(one, two, three); waitForParentToStop(parent); assertStopped(one); assertStopped(two); Throwable failureCause = two.getFailureCause(); assertNotNull(failureCause); Throwable parentFailureCause = parent.getFailureCause(); assertNotNull(parentFailureCause); assertEquals(parentFailureCause, failureCause); assertInState(three, Service.STATE.NOTINITED); }
@Override protected void serviceStart() throws Exception { //act on the lifespan here if (lifespan > 0) { executorService.submit(new Runnable() { @Override public void run() { try { Thread.sleep(lifespan); } catch (InterruptedException ignored) { } finish(); } }); } else { if (lifespan == 0) { finish(); } else { //continue until told not to } } }
@Test public void testSequenceInSequence() throws Throwable { MockService one = new MockService("one", false, 100); MockService two = new MockService("two", false, 100); ServiceParent parent = buildService(one, two); ServiceParent outer = startService(parent); waitForParentToStop(parent); assertStopped(one); assertStopped(two); }
@Override protected void serviceStart() throws Exception { //act on the lifespan here if (lifespan > 0) { executorService.submit(new Runnable() { @Override public void run() { try { Thread.sleep(lifespan); } catch (InterruptedException ignored) { } finish(); } }); } else { if (lifespan == 0) { finish(); } else { //continue until told not to } } }
@Test public void testSingleChild() throws Throwable { Service parent = startService(new MockService()); parent.stop(); }
@Test public void testSingleSequence() throws Throwable { ServiceParent parent = startService(new MockService()); parent.stop(); }
@Test public void testSingleChild() throws Throwable { Service parent = startService(new MockService()); parent.stop(); }
@Test public void testSingleSequence() throws Throwable { ServiceParent parent = startService(new MockService()); parent.stop(); }
@Test public void testVarargsConstructor() throws Throwable { MockService one = new MockService("one", false, 100); MockService two = new MockService("two", false, 100); ServiceParent parent = new WorkflowSequenceService("test", one, two); parent.init(new Configuration()); parent.start(); waitForParentToStop(parent); assertStopped(one); assertStopped(two); }