public static void advanceTime(long ms) { advanceTimeNanos(millisToNanos(ms)); }
private static void simulatedSleepUntilNanos(long targetTimeNanos) throws InterruptedException { try { synchronized (SLEEP_TIMES_LOCK) { if (!SIMULATING.get()) { LOG.debug("{} is still sleeping after simulated time disabled.", Thread.currentThread(), new RuntimeException("STACK TRACE")); throw new InterruptedException(); } THREAD_SLEEP_TIMES_NANOS.put(Thread.currentThread(), new AtomicLong(targetTimeNanos)); } while (SIMULATED_CURR_TIME_NANOS.get() < targetTimeNanos) { synchronized (SLEEP_TIMES_LOCK) { if (!SIMULATING.get()) { LOG.debug("{} is still sleeping after simulated time disabled.", Thread.currentThread(), new RuntimeException("STACK TRACE")); throw new InterruptedException(); } long autoAdvance = AUTO_ADVANCE_NANOS_ON_SLEEP.get(); if (autoAdvance > 0) { advanceTimeNanos(autoAdvance); } } Thread.sleep(10); } } finally { THREAD_SLEEP_TIMES_NANOS.remove(Thread.currentThread()); } }
public static void advanceTime(long ms) { advanceTimeNanos(millisToNanos(ms)); }
private static void simulatedSleepUntilNanos(long targetTimeNanos) throws InterruptedException { try { synchronized (sleepTimesLock) { if (threadSleepTimesNanos == null) { LOG.debug("{} is still sleeping after simulated time disabled.", Thread.currentThread(), new RuntimeException("STACK TRACE")); throw new InterruptedException(); } threadSleepTimesNanos.put(Thread.currentThread(), new AtomicLong(targetTimeNanos)); } while (simulatedCurrTimeNanos.get() < targetTimeNanos) { synchronized (sleepTimesLock) { if (threadSleepTimesNanos == null) { LOG.debug("{} is still sleeping after simulated time disabled.", Thread.currentThread(), new RuntimeException("STACK TRACE")); throw new InterruptedException(); } } long autoAdvance = autoAdvanceNanosOnSleep.get(); if (autoAdvance > 0) { advanceTimeNanos(autoAdvance); } Thread.sleep(10); } } finally { synchronized (sleepTimesLock) { if (simulating.get() && threadSleepTimesNanos != null) { threadSleepTimesNanos.remove(Thread.currentThread()); } } } }