@Test public void checks_twice_when_two_request_made_in_11_seconds() throws Exception { when(untrustedApi.isOk()).thenReturn(false); when(trustedApi.isOk()).thenReturn(true); date.setFixed(FIRST_CHECK_TIME); apiDownChecker.isApiDown(); date.setFixed(SECOND_CHECK_AFTER_11_SECONDS); apiDownChecker.isApiDown(); verify(untrustedApi, times(2)).isOk(); verify(trustedApi, times(2)).isOk(); }
public synchronized boolean isApiDown() { long currentTime = dateProvider.now(); if (lastCheckTimestamp + KEEP_ALIVE_MILLIS >= currentTime) { return lastResult; } else { lastCheckTimestamp = currentTime; lastResult = requestIsApiDown(); return lastResult; } }
ApiDownChecker { public synchronized boolean isApiDown() { long currentTime = dateProvider.now(); if (lastCheckTimestamp + KEEP_ALIVE_MILLIS >= currentTime) { return lastResult; } else { lastCheckTimestamp = currentTime; lastResult = requestIsApiDown(); return lastResult; } } }
ApiDownChecker { public synchronized boolean isApiDown() { long currentTime = dateProvider.now(); if (lastCheckTimestamp + KEEP_ALIVE_MILLIS >= currentTime) { return lastResult; } else { lastCheckTimestamp = currentTime; lastResult = requestIsApiDown(); return lastResult; } } ApiDownChecker(ApiValidator untrustedApiValidator, ApiValidator trustedValidator, Logger logger, DateProvider dateProvider); }
ApiDownChecker { public synchronized boolean isApiDown() { long currentTime = dateProvider.now(); if (lastCheckTimestamp + KEEP_ALIVE_MILLIS >= currentTime) { return lastResult; } else { lastCheckTimestamp = currentTime; lastResult = requestIsApiDown(); return lastResult; } } ApiDownChecker(ApiValidator untrustedApiValidator, ApiValidator trustedValidator, Logger logger, DateProvider dateProvider); static ApiDownChecker.Builder create(); synchronized boolean isApiDown(); ApiValidator getTrustedValidator(); ApiValidator getUntrustedValidator(); Logger getLogger(); }
ApiDownChecker { public synchronized boolean isApiDown() { long currentTime = dateProvider.now(); if (lastCheckTimestamp + KEEP_ALIVE_MILLIS >= currentTime) { return lastResult; } else { lastCheckTimestamp = currentTime; lastResult = requestIsApiDown(); return lastResult; } } ApiDownChecker(ApiValidator untrustedApiValidator, ApiValidator trustedValidator, Logger logger, DateProvider dateProvider); static ApiDownChecker.Builder create(); synchronized boolean isApiDown(); ApiValidator getTrustedValidator(); ApiValidator getUntrustedValidator(); Logger getLogger();  }