Waiter { public void wakeOrSkipNextWait() { synchronized (lock) { final boolean awoken = wake(); if (!awoken) { LOG.debug("Waiter not waiting, instructing to skip next wait."); this.skipNextWait = true; } } } Waiter(Duration duration);  Waiter(Duration duration, Clock clock);   Waiter(Duration duration, Clock clock, Object lock); void doWait(); boolean wake(); void wakeOrSkipNextWait(); Duration getWaitDuration();  }
@Test public void should_not_wait_if_instructed_to_skip_next() throws ExecutionException, InterruptedException { Waiter waiter = new Waiter(Duration.ofMillis(1000)); waiter.wakeOrSkipNextWait(); Future<Long> waitTime = executor.submit(new WaitForWaiter(waiter)); assertTrue(waitTime.get() < 10L, "Waited: " + waitTime.get()); }