TerminationStateServiceImpl extends AbstractJobTerminationStateService { @Override public void setState(TerminationState state) { super.setState(state); if (getState() != TerminationState.NONE) { try { String host = getServiceRegistry().getRegistryHostname(); getServiceRegistry().setMaintenanceStatus(host, true); } catch (ServiceRegistryException | NotFoundException e) { logger.error("Cannot put this host into maintenance", e); } startJobPolling(); } else { try { String host = getServiceRegistry().getRegistryHostname(); getServiceRegistry().setMaintenanceStatus(host, false); } catch (ServiceRegistryException | NotFoundException e) { logger.error("Cannot take this host out of maintenance", e); } } }  @Override void setState(TerminationState state); void deactivate(); static final String CONFIG_JOB_POLLING_PERIOD; }
@Test public void testLifeCyclePolling() throws Exception { service.setState(TerminationStateServiceImpl.TerminationState.WAIT); Assert.assertEquals(TerminationStateServiceImpl.TerminationState.WAIT, service.getState()); Thread.sleep(3000); String[] trigger = scheduler.getTriggerNames(TerminationStateServiceImpl.SCHEDULE_GROUP); Assert.assertEquals(1, trigger.length); Assert.assertEquals(TerminationStateServiceImpl.SCHEDULE_JOB_POLLING_TRIGGER, trigger[0]); nRunningJobs = 0L; Thread.sleep(3000); trigger = scheduler.getTriggerNames(TerminationStateServiceImpl.SCHEDULE_GROUP); Assert.assertEquals(0, trigger.length); Assert.assertEquals(TerminationStateServiceImpl.TerminationState.READY, service.getState()); }