DelayQueueTimeoutService implements TimeoutService { @Override public void scheduleTimeout(Timeout timeout, long timeoutMillis) { scheduleTimeout(timeout, timeoutMillis, System.nanoTime()); } DelayQueueTimeoutService(String name);  DelayQueueTimeoutService(String name, Clock clock, Thread.UncaughtExceptionHandler exceptionHandler); @Override void scheduleTimeout(Timeout timeout, long timeoutMillis); @Override void scheduleTimeout(Timeout timeout, long timeoutMillis, long nanoTime); void stop(); static long adjustTimeout(long millisTimeout); static final long MAX_TIMEOUT_MILLIS; static final DelayQueueTimeoutService DEFAULT_TIMEOUT_SERVICE; }
@Test public void timeoutWillOccur() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); timeoutService.scheduleTimeout(new TestTimeout(latch), 10L); latch.await(); assertTrue(didTimeout); }
@Test public void timeoutsWillOccurInOrder() throws InterruptedException { CountDownLatch latch = new CountDownLatch(3); timeoutService.scheduleTimeout(new TestTimeout2(latch, 3), 100L); timeoutService.scheduleTimeout(new TestTimeout2(latch, 1), 10L); timeoutService.scheduleTimeout(new TestTimeout2(latch, 2), 50L); latch.await(); assertEquals(1, queue.poll().intValue()); assertEquals(2, queue.poll().intValue()); assertEquals(3, queue.poll().intValue()); }