* makes sense.
*/
public void testEmptyServiceManager() {
Logger logger = Logger.getLogger(ServiceManager.class.getName());
logger.setLevel(Level.FINEST);
TestLogHandler logHandler = new TestLogHandler();
logger.addHandler(logHandler);
ServiceManager manager = new ServiceManager(Arrays.<Service>asList());
RecordingListener listener = new RecordingListener();
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());
// check that our NoOpService is not directly observable via any of the inspection methods or
// via logging.
assertEquals("ServiceManager{services=[]}", manager.toString());
assertTrue(manager.servicesByState().isEmpty());
assertTrue(manager.startupTimes().isEmpty());
Formatter logFormatter = new Formatter() {
@Override public String format(LogRecord record) {
return formatMessage(record);
}
};
for (LogRecord record : logHandler.getStoredLogRecords()) {
assertFalse(logFormatter.format(record).contains("NoOpService"));
}
}