private static void assertState( ServiceManager manager, Service.State state, Service... services) { Collection<Service> managerServices = manager.servicesByState().get(state); for (Service service : services) { assertEquals(service.toString(), state, service.state()); assertEquals(service.toString(), service.isRunning(), state == Service.State.RUNNING); assertTrue(managerServices + " should contain " + service, managerServices.contains(service)); } }
public void testNotifyStoppedAfterFailure() throws TimeoutException { Service a = new AbstractService() { @Override protected void doStart() { notifyFailed(new IllegalStateException("start failure")); notifyStopped(); // This will be a no-op. } @Override protected void doStop() { notifyStopped(); } }; final ServiceManager manager = new ServiceManager(asList(a)); manager.startAsync(); manager.awaitStopped(10, TimeUnit.MILLISECONDS); assertThat(manager.servicesByState().keySet()).containsExactly(Service.State.FAILED); }
serviceManager.stopAsync().awaitStopped(configuration.getShutdownTimeout(), TimeUnit.MILLISECONDS); } catch (TimeoutException timeoutException) { LOG.error("Unable to shutdown properly on time. {}", serviceManager.servicesByState());
public void testDoCancelStart() throws TimeoutException { Service a = new AbstractService() { @Override protected void doStart() { // Never starts! } @Override protected void doCancelStart() { assertThat(state()).isEqualTo(Service.State.STOPPING); notifyStopped(); } @Override protected void doStop() { throw new AssertionError(); // Should not be called. } }; final ServiceManager manager = new ServiceManager(asList(a)); manager.startAsync(); manager.stopAsync(); manager.awaitStopped(10, TimeUnit.MILLISECONDS); assertThat(manager.servicesByState().keySet()).containsExactly(Service.State.TERMINATED); }
assertTrue(manager.servicesByState().isEmpty()); assertTrue(manager.startupTimes().isEmpty()); Formatter logFormatter =
public ImmutableMultimap<Service.State, Service> servicesByState() { return serviceManager.servicesByState(); } }
@Override public void failure(Service service) { System.err.println(Joiner.on('\n').withKeyValueSeparator(":").join(manager.servicesByState().entries())); System.exit(1); } }, MoreExecutors.directExecutor());
ImmutableMultimap<State, Service> serviceStateMap = this.serviceManager.servicesByState();
serviceManager.stopAsync().awaitStopped(configuration.getShutdownTimeout(), TimeUnit.MILLISECONDS); } catch (TimeoutException timeoutException) { LOG.error("Unable to shutdown properly on time. {}", serviceManager.servicesByState());
private static void assertState( ServiceManager manager, Service.State state, Service... services) { Collection<Service> managerServices = manager.servicesByState().get(state); for (Service service : services) { assertEquals(service.toString(), state, service.state()); assertEquals(service.toString(), service.isRunning(), state == Service.State.RUNNING); assertTrue(managerServices + " should contain " + service, managerServices.contains(service)); } }
assertTrue(manager.servicesByState().isEmpty()); assertTrue(manager.startupTimes().isEmpty()); Formatter logFormatter = new Formatter() {