MonitorRunningInstance implements Closeable { @VisibleForTesting void doWork() throws Exception { InstanceConfig config = exhibitor.getConfigManager().getConfig(); StateAndLeader stateAndLeader = getStateAndLeader(); InstanceState instanceState = new InstanceState(new ServerList(config.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(config)); currentIsLeader.set(stateAndLeader.isLeader()); exhibitor.getConfigManager().checkRollingConfig(instanceState); InstanceState localCurrentInstanceState = currentInstanceState.get(); if ( instanceState.equals(localCurrentInstanceState) ) { checkForRestart(config, localCurrentInstanceState); } else { handleServerListChange(instanceState, localCurrentInstanceState); } } MonitorRunningInstance(Exhibitor exhibitor); void start(); @Override void close(); InstanceStateTypes getCurrentInstanceState(); boolean isCurrentlyLeader(); int getRestartCount();  }
@Test public void testTempDownInstance() throws Exception { final AtomicInteger checkMs = new AtomicInteger(10000); InstanceConfig config = new InstanceConfig() { @Override public String getString(StringConfigs config) { switch ( config ) { case SERVERS_SPEC: { return "1:foo,2:bar"; } case ZOOKEEPER_DATA_DIRECTORY: case ZOOKEEPER_INSTALL_DIRECTORY: { return "/"; } } return null; } @Override public int getInt(IntConfigs config) { switch ( config ) { case CHECK_MS: { return checkMs.get(); } } return 0; } }; Exhibitor mockExhibitor = makeMockExhibitor(config, "foo"); final Semaphore semaphore = new Semaphore(0); MonitorRunningInstance monitor = new MonitorRunningInstance(mockExhibitor) { @Override protected void restartZooKeeper(InstanceState currentInstanceState) throws Exception { semaphore.release(); } }; monitor.doWork(); Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS)); monitor.doWork(); Assert.assertFalse(semaphore.tryAcquire(3, TimeUnit.SECONDS)); checkMs.set(1); monitor.doWork(); Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS)); }