@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));  // no instance state change, should not try restart
    checkMs.set(1);
    monitor.doWork();   // should do restart now as 10 times checkMs has elapsed
    Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS));
}