@Test public void warnWhenExecutionTakesLongerThanInterval() throws Exception { SleepingTimer timer = new SleepingTimer(THREAD_NAME, INTERVAL_MS, mMockLogger, mFakeClock, mMockSleeper); timer.tick(); mFakeClock.addTimeMs(5 * INTERVAL_MS); timer.tick(); verify(mMockLogger).warn(anyString(), anyString(), Mockito.anyLong(), Mockito.anyLong()); }
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();  }