@Test public void sleepForSpecifiedInterval() throws Exception { final SleepingTimer timer = new SleepingTimer(THREAD_NAME, INTERVAL_MS, mMockLogger, mFakeClock, mMockSleeper); timer.tick(); verify(mMockSleeper, times(0)).sleep(any(Duration.class)); timer.tick(); verify(mMockSleeper).sleep(Duration.ofMillis(INTERVAL_MS)); }
public void tick() throws InterruptedException { if (mPreviousTickMs != 0) { long executionTimeMs = mClock.millis() - mPreviousTickMs; if (executionTimeMs > mIntervalMs) { mLogger.warn("{} last execution took {} ms. Longer than the interval {}", mThreadName, executionTimeMs, mIntervalMs); } else { mSleeper.sleep(Duration.ofMillis(mIntervalMs - executionTimeMs)); } } mPreviousTickMs = mClock.millis(); }
SleepingTimer implements HeartbeatTimer { public void tick() throws InterruptedException { if (mPreviousTickMs != 0) { long executionTimeMs = mClock.millis() - mPreviousTickMs; if (executionTimeMs > mIntervalMs) { mLogger.warn("{} last execution took {} ms. Longer than the interval {}", mThreadName, executionTimeMs, mIntervalMs); } else { mSleeper.sleep(Duration.ofMillis(mIntervalMs - executionTimeMs)); } } mPreviousTickMs = mClock.millis(); } }
SleepingTimer implements HeartbeatTimer { public void tick() throws InterruptedException { if (mPreviousTickMs != 0) { long executionTimeMs = mClock.millis() - mPreviousTickMs; if (executionTimeMs > mIntervalMs) { mLogger.warn("{} last execution took {} ms. Longer than the interval {}", mThreadName, executionTimeMs, mIntervalMs); } else { mSleeper.sleep(Duration.ofMillis(mIntervalMs - executionTimeMs)); } } mPreviousTickMs = mClock.millis(); } SleepingTimer(String threadName, long intervalMs);  SleepingTimer(String threadName, long intervalMs, Logger logger, Clock clock,
      Sleeper sleeper); }
SleepingTimer implements HeartbeatTimer { public void tick() throws InterruptedException { if (mPreviousTickMs != 0) { long executionTimeMs = mClock.millis() - mPreviousTickMs; if (executionTimeMs > mIntervalMs) { mLogger.warn("{} last execution took {} ms. Longer than the interval {}", mThreadName, executionTimeMs, mIntervalMs); } else { mSleeper.sleep(Duration.ofMillis(mIntervalMs - executionTimeMs)); } } mPreviousTickMs = mClock.millis(); } SleepingTimer(String threadName, long intervalMs);  SleepingTimer(String threadName, long intervalMs, Logger logger, Clock clock,
      Sleeper sleeper); void tick(); }
SleepingTimer implements HeartbeatTimer { public void tick() throws InterruptedException { if (mPreviousTickMs != 0) { long executionTimeMs = mClock.millis() - mPreviousTickMs; if (executionTimeMs > mIntervalMs) { mLogger.warn("{} last execution took {} ms. Longer than the interval {}", mThreadName, executionTimeMs, mIntervalMs); } else { mSleeper.sleep(Duration.ofMillis(mIntervalMs - executionTimeMs)); } } mPreviousTickMs = mClock.millis(); } SleepingTimer(String threadName, long intervalMs);  SleepingTimer(String threadName, long intervalMs, Logger logger, Clock clock,
      Sleeper sleeper); void tick();  }