CompositeService extends AbstractService { public List<Service> getServices() { synchronized (serviceList) { return Collections.unmodifiableList(new ArrayList<>(serviceList)); } } CompositeService(String name); List<Service> getServices();  }
@Test public void testServiceStartup() { ServiceManager serviceManager = new ServiceManager("ServiceManager"); for (int i = 0; i < NUM_OF_SERVICES; i++) { CompositeServiceImpl service = new CompositeServiceImpl(i); if (i == FAILED_SERVICE_SEQ_NUMBER) { service.setThrowExceptionOnStart(true); } serviceManager.addTestService(service); } CompositeServiceImpl[] services = serviceManager.getServices().toArray( new CompositeServiceImpl[0]); Configuration conf = new Configuration(); serviceManager.init(conf); try { serviceManager.start(); fail("Exception should have been thrown due to startup failure of last service"); } catch (ServiceTestRuntimeException e) { for (int i = 0; i < NUM_OF_SERVICES - 1; i++) { if (i >= FAILED_SERVICE_SEQ_NUMBER && STOP_ONLY_STARTED_SERVICES) { assertEquals("Service state should have been ", STATE.INITED, services[NUM_OF_SERVICES - 1].getServiceState()); } else { assertEquals("Service state should have been ", STATE.STOPPED, services[i].getServiceState()); } } } }