protected void logState(ServiceParent p) { logService(p); for (Service s : p.getServices()) { logService(s); } }
/** * Use {@link #buildService(Service...)} to create service and then start it * @param services * @return */ protected ServiceParent startService(Service... services) { ServiceParent parent = buildService(services); //expect service to start and stay started parent.start(); return parent; }
/** * Wait for the service parent to stop * @param parent the service to wait for * @param timeout time in milliseconds */ protected void waitForParentToStop(ServiceParent parent, int timeout) { boolean stop = parent.waitForServiceToStop(timeout); if (!stop) { logState(parent); fail("Service failed to stop : after " + timeout + " millis " + parent); } }
@Test public void testFailureRun() throws Throwable { WorkflowCompositeService svc = run(new WorkflowCompositeService()); ServiceTerminatingRunnable runnable = new ServiceTerminatingRunnable(svc, new SimpleRunnable(true)); // synchronous in-thread execution runnable.run(); assertStopped(svc); assertNotNull(runnable.getException()); }
@Test public void testFailingSequence() throws Throwable { MockService one = new MockService("one", true, 100); MockService two = new MockService("two", false, 100); WorkflowSequenceService parent = (WorkflowSequenceService) startService(one, two); waitForParentToStop(parent); assertStopped(one); assertInState(two, Service.STATE.NOTINITED); assertEquals(one, parent.getPreviousService()); }
@Test public void testBasicRun() throws Throwable { WorkflowCompositeService svc = run(new WorkflowCompositeService()); ServiceTerminatingRunnable runnable = new ServiceTerminatingRunnable(svc, new SimpleRunnable()); // synchronous in-thread execution runnable.run(); assertStopped(svc); }
@Test public void testNestedComposite() 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); assertTrue(outer.waitForServiceToStop(1000)); assertStopped(one); assertStopped(two); }
@Test public void testAsyncRun() throws Throwable { ExecutorSvc svc = run(new ExecutorSvc()); ServiceTerminatingRunnable runnable = new ServiceTerminatingRunnable(svc, new SimpleRunnable()); // synchronous in-thread execution svc.execute(runnable); Thread.sleep(1000); assertStopped(svc); }
public void exec() throws InterruptedException, TimeoutException { assertNotNull(process); process.start(); assert process.waitForServiceToStop(5000); }
@Test public void testSingleChildFailing() throws Throwable { ServiceParent parent = startService(new MockService("1", true, 100)); waitForParentToStop(parent); assert parent.getFailureCause() != null; }
@Test public void testNoservice() throws Throwable { try { new ServiceTerminatingRunnable(null, new SimpleRunnable()); fail("unexpected "); } catch (IllegalArgumentException e) { // expected } }
@Test public void testSingleSequence() throws Throwable { ServiceParent parent = startService(new MockService()); parent.stop(); }
@Test public void testFailureRun() throws Throwable { WorkflowCompositeService svc = run(new WorkflowCompositeService()); ServiceTerminatingRunnable runnable = new ServiceTerminatingRunnable(svc, new SimpleRunnable(true)); // synchronous in-thread execution runnable.run(); assertStopped(svc); assertNotNull(runnable.getException()); }
@Test public void testFailingSequence() throws Throwable { MockService one = new MockService("one", true, 100); MockService two = new MockService("two", false, 100); WorkflowSequenceService parent = (WorkflowSequenceService) startService(one, two); waitForParentToStop(parent); assertStopped(one); assertInState(two, Service.STATE.NOTINITED); assertEquals(one, parent.getPreviousService()); }
@Test public void testBasicRun() throws Throwable { WorkflowCompositeService svc = run(new WorkflowCompositeService()); ServiceTerminatingRunnable runnable = new ServiceTerminatingRunnable(svc, new SimpleRunnable()); // synchronous in-thread execution runnable.run(); assertStopped(svc); }
@Test public void testNestedComposite() 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); assertTrue(outer.waitForServiceToStop(1000)); assertStopped(one); assertStopped(two); }
public void exec() throws InterruptedException, TimeoutException { assertNotNull(process); process.start(); assert process.waitForServiceToStop(5000); }
protected void logState(ServiceParent p) { logService(p); for (Service s : p.getServices()) { logService(s); } }
/** * Wait for the service parent to stop * @param parent the service to wait for * @param timeout time in milliseconds */ protected void waitForParentToStop(ServiceParent parent, int timeout) { boolean stop = parent.waitForServiceToStop(timeout); if (!stop) { logState(parent); fail("Service failed to stop : after " + timeout + " millis " + parent); } }
/** * Use {@link #buildService(Service...)} to create service and then start it * @param services * @return */ protected ServiceParent startService(Service... services) { ServiceParent parent = buildService(services); //expect service to start and stay started parent.start(); return parent; }