@Override public Iterable<Task<?>> apply(Task<?> input) { return descendants(input, parentFirst); } }));
public void doTestReleaseEvenIfErrorDuringStop(final Class<? extends SimulatedDriver> driver) throws Exception { MyService entity = app.addChild(EntitySpec.create(MyServiceWithCustomDriver.class) .configure(MyServiceWithCustomDriver.DRIVER_CLASS, driver)); entity.start(ImmutableList.of(loc)); Task<Void> t = entity.invoke(Startable.STOP, ImmutableMap.<String, Object>of()); t.blockUntilEnded(); assertFalse(t.isError(), "Expected parent to succeed, not fail with " + Tasks.getError(t)); Iterator<Task<?>> failures; failures = Tasks.failed(Tasks.descendants(t, true)).iterator(); Assert.assertTrue(failures.hasNext(), "Expected error in descendants"); Optional<Task<?>> stopping = Iterables.tryFind(Tasks.children(t), TaskPredicates.displayNameEqualTo("stopping")); Assert.assertTrue(stopping.isPresent(), "Could not find stopping task"); failures = Tasks.failed(Tasks.children(stopping.get())).iterator(); Assert.assertTrue(failures.hasNext(), "Expected error in child"); Throwable e = Tasks.getError(failures.next()); if (e == null || !e.toString().contains("Simulating stop error")) Assert.fail("Wrong error", e); Assert.assertEquals(loc.getAvailable(), ImmutableSet.of(machine), "Expected location to be available again"); Entities.unmanage(entity); }