@Override public boolean isCompleted() throws IOException { return !serviceManager.isHealthy(); }
assertFalse("State should be updated before calling listeners", manager.isHealthy());
public void testServiceStartStop() { Service a = new NoOpService(); Service b = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b); assertFalse(manager.isHealthy()); manager.startAsync().awaitHealthy(); assertState(manager, Service.State.RUNNING, a, b); assertTrue(manager.isHealthy()); assertTrue(listener.healthyCalled); assertFalse(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); manager.stopAsync().awaitStopped(); assertState(manager, Service.State.TERMINATED, a, b); assertFalse(manager.isHealthy()); assertTrue(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); }
manager.addListener(listener); manager.startAsync().awaitHealthy(); assertTrue(manager.isHealthy()); assertTrue(listener.healthyCalled); assertFalse(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); manager.stopAsync().awaitStopped(); assertFalse(manager.isHealthy()); assertTrue(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty());
public void testFailStart() throws Exception { Service a = new NoOpService(); Service b = new FailStartService(); Service c = new NoOpService(); Service d = new FailStartService(); Service e = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b, c, d, e)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b, c, d, e); try { manager.startAsync().awaitHealthy(); fail(); } catch (IllegalStateException expected) { } assertFalse(listener.healthyCalled); assertState(manager, Service.State.RUNNING, a, c, e); assertEquals(ImmutableSet.of(b, d), listener.failedServices); assertState(manager, Service.State.FAILED, b, d); assertFalse(manager.isHealthy()); manager.stopAsync().awaitStopped(); assertFalse(manager.isHealthy()); assertFalse(listener.healthyCalled); assertTrue(listener.stoppedCalled); }
@Override public boolean isCompleted() throws IOException { return !serviceManager.isHealthy(); }
@Override public boolean isCompleted() throws IOException { return !serviceManager.isHealthy(); }
public boolean isRunning() { return services.isHealthy(); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy}. The manager * will become healthy after all the component services have reached the {@linkplain State#RUNNING * running} state. * * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy() { state.awaitHealthy(); checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy}. The manager * will become healthy after all the component services have reached the {@linkplain State#RUNNING * running} state. * * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy() { state.awaitHealthy(); checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy}. The manager * will become healthy after all the component services have reached the {@linkplain State#RUNNING * running} state. * * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy() { state.awaitHealthy(); checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy}. The manager * will become healthy after all the component services have reached the {@linkplain State#RUNNING * running} state. * * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy() { state.awaitHealthy(); checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy}. The manager * will become healthy after all the component services have reached the {@linkplain State#RUNNING * running} state. * * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy() { state.awaitHealthy(); checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy} for no more * than the given time. The manager will become healthy after all the component services have * reached the {@linkplain State#RUNNING running} state. * * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @throws TimeoutException if not all of the services have finished starting within the deadline * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { if (!state.awaitHealthy(timeout, unit)) { // It would be nice to tell the caller who we are still waiting on, and this information is // likely to be in servicesByState(), however due to race conditions we can't actually tell // which services are holding up healthiness. The current set of NEW or STARTING services is // likely to point out the culprit, but may not. If we really wanted to solve this we could // change state to track exactly which services have started and then we could accurately // report on this. But it is only for logging so we likely don't care. throw new TimeoutException("Timeout waiting for the services to become healthy."); } checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy} for no more * than the given time. The manager will become healthy after all the component services have * reached the {@linkplain State#RUNNING running} state. * * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @throws TimeoutException if not all of the services have finished starting within the deadline * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { if (!state.awaitHealthy(timeout, unit)) { // It would be nice to tell the caller who we are still waiting on, and this information is // likely to be in servicesByState(), however due to race conditions we can't actually tell // which services are holding up healthiness. The current set of NEW or STARTING services is // likely to point out the culprit, but may not. If we really wanted to solve this we could // change state to track exactly which services have started and then we could accurately // report on this. But it is only for logging so we likely don't care. throw new TimeoutException("Timeout waiting for the services to become healthy."); } checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy} for no more * than the given time. The manager will become healthy after all the component services have * reached the {@linkplain State#RUNNING running} state. * * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @throws TimeoutException if not all of the services have finished starting within the deadline * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { if (!state.awaitHealthy(timeout, unit)) { // It would be nice to tell the caller who we are still waiting on, and this information is // likely to be in servicesByState(), however due to race conditions we can't actually tell // which services are holding up healthiness. The current set of NEW or STARTING services is // likely to point out the culprit, but may not. If we really wanted to solve this we could // change state to track exactly which services have started and then we could accurately // report on this. But it is only for logging so we likely don't care. throw new TimeoutException("Timeout waiting for the services to become healthy."); } checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy} for no more * than the given time. The manager will become healthy after all the component services have * reached the {@linkplain State#RUNNING running} state. * * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @throws TimeoutException if not all of the services have finished starting within the deadline * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { if (!state.awaitHealthy(timeout, unit)) { // It would be nice to tell the caller who we are still waiting on, and this information is // likely to be in servicesByState(), however due to race conditions we can't actually tell // which services are holding up healthiness. The current set of NEW or STARTING services is // likely to point out the culprit, but may not. If we really wanted to solve this we could // change state to track exactly which services have started and then we could accurately // report on this. But it is only for logging so we likely don't care. throw new TimeoutException("Timeout waiting for the services to become healthy."); } checkState(isHealthy(), "Expected to be healthy after starting"); }
/** * Waits for the {@link ServiceManager} to become {@linkplain #isHealthy() healthy} for no more * than the given time. The manager will become healthy after all the component services have * reached the {@linkplain State#RUNNING running} state. * * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @throws TimeoutException if not all of the services have finished starting within the deadline * @throws IllegalStateException if the service manager reaches a state from which it cannot * become {@linkplain #isHealthy() healthy}. */ public void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { if (!state.awaitHealthy(timeout, unit)) { // It would be nice to tell the caller who we are still waiting on, and this information is // likely to be in servicesByState(), however due to race conditions we can't actually tell // which services are holding up healthiness. The current set of NEW or STARTING services is // likely to point out the culprit, but may not. If we really wanted to solve this we could // change state to track exactly which services have started and then we could accurately // report on this. But it is only for logging so we likely don't care. throw new TimeoutException("Timeout waiting for the services to become healthy."); } checkState(isHealthy(), "Expected to be healthy after starting"); }
public void testServiceStartStop() { Service a = new NoOpService(); Service b = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b); assertFalse(manager.isHealthy()); manager.startAsync().awaitHealthy(); assertState(manager, Service.State.RUNNING, a, b); assertTrue(manager.isHealthy()); assertTrue(listener.healthyCalled); assertFalse(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); manager.stopAsync().awaitStopped(); assertState(manager, Service.State.TERMINATED, a, b); assertFalse(manager.isHealthy()); assertTrue(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); }
public void testFailStart() throws Exception { Service a = new NoOpService(); Service b = new FailStartService(); Service c = new NoOpService(); Service d = new FailStartService(); Service e = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b, c, d, e)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b, c, d, e); try { manager.startAsync().awaitHealthy(); fail(); } catch (IllegalStateException expected) { } assertFalse(listener.healthyCalled); assertState(manager, Service.State.RUNNING, a, c, e); assertEquals(ImmutableSet.of(b, d), listener.failedServices); assertState(manager, Service.State.FAILED, b, d); assertFalse(manager.isHealthy()); manager.stopAsync().awaitStopped(); assertFalse(manager.isHealthy()); assertFalse(listener.healthyCalled); assertTrue(listener.stoppedCalled); }