/** * Given a parent service, find the one that is a forked process * @param serviceParent parent * @return the forked process service or null if there is none */ protected ForkedProcessService getFPSFromParentService(ServiceParent serviceParent) { List<Service> services = serviceParent.getServices(); for (Service s : services) { if (s instanceof ForkedProcessService) { return (ForkedProcessService) s; } } return null; }
@Override public ServiceParent buildService(Service... services) { ServiceParent parent = new WorkflowCompositeService("test", services); parent.init(new Configuration()); return 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; }
@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); }
@Test public void testSingleChildFailing() throws Throwable { ServiceParent parent = startService(new MockService("1", true, 100)); waitForParentToStop(parent); assert parent.getFailureCause() != null; }
/** * 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 testSingleSequence() throws Throwable { ServiceParent parent = startService(new MockService()); parent.stop(); }
@Test public void testAddChild() throws Throwable { MockService one = new MockService("one", false, 5000); MockService two = new MockService("two", false, 100); ServiceParent parent = startService(one, two); CallableHandler handler = new CallableHandler("hello"); WorkflowCallbackService<String> ens = new WorkflowCallbackService<String>("handler", handler, 100, true); parent.addService(ens); waitForParentToStop(parent, 10000); assertStopped(one); assertStopped(two); assertStopped(ens); assertStopped(two); assertEquals("hello", ens.getScheduledFuture().get()); }
@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); }
@Test public void testSingleChildFailing() throws Throwable { ServiceParent parent = startService(new MockService("1", true, 100)); waitForParentToStop(parent); assert parent.getFailureCause() != null; }
/** * 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 testSingleSequence() throws Throwable { ServiceParent parent = startService(new MockService()); parent.stop(); }
@Test public void testAddChild() throws Throwable { MockService one = new MockService("one", false, 5000); MockService two = new MockService("two", false, 100); ServiceParent parent = startService(one, two); CallableHandler handler = new CallableHandler("hello"); WorkflowCallbackService<String> ens = new WorkflowCallbackService<String>("handler", handler, 100, true); parent.addService(ens); waitForParentToStop(parent, 10000); assertStopped(one); assertStopped(two); assertStopped(ens); assertStopped(two); assertEquals("hello", ens.getScheduledFuture().get()); }
/** * Given a parent service, find the one that is a forked process * @param serviceParent parent * @return the forked process service or null if there is none */ protected ForkedProcessService getFPSFromParentService(ServiceParent serviceParent) { List<Service> services = serviceParent.getServices(); for (Service s : services) { if (s instanceof ForkedProcessService) { return (ForkedProcessService) s; } } return null; }
@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 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); }
/** * 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; }
@Override public ServiceParent buildService(Service... services) { ServiceParent parent = new WorkflowCompositeService("test", services); parent.init(new Configuration()); return parent; }
protected void logState(ServiceParent p) { logService(p); for (Service s : p.getServices()) { logService(s); } }
@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()); }