DelayedRestartTrigger extends Thread { public void trigger() { this.restartLock.lock(); try { accumulatedTriggerCount.incrementAndGet(); this.restartRequested.signal(); } finally { this.restartLock.unlock(); } } DelayedRestartTrigger(
            RunClassInSeparateJvmMachine runClassInSeparateJvmMachine); void shutdown(); int getRestartCount(); int getAccumulatedTriggerCount(); long getSettleDownMillis(); void setSettleDownMillis(long settleDownMillis); @Override void run(); void trigger();  }
@Test public void trigger() throws Exception { RunClassInSeparateJvmMachine machine = mock(RunClassInSeparateJvmMachine.class); DelayedRestartTrigger restartTrigger = new DelayedRestartTrigger(machine); restartTrigger.setSettleDownMillis(10); try { restartTrigger.start(); assertEquals(0, restartTrigger.getRestartCount()); assertEquals(0, restartTrigger.getAccumulatedTriggerCount()); waitOrTimeout(Conditions.isWaiting(restartTrigger), Timeout.timeout(millis(10000))); restartTrigger.trigger(); verify(machine, timeout(10000)).restart(); waitOrTimeout(Conditions.isWaiting(restartTrigger), Timeout.timeout(millis(10000))); assertEquals(1, restartTrigger.getRestartCount()); assertEquals(0, restartTrigger.getAccumulatedTriggerCount()); } finally { restartTrigger.shutdown(); } }