public static <T> boolean checkAndSleep(T expectedValue, Supplier<T> expressionToCheck, int timeoutInMs) {
    long startTime = System.currentTimeMillis();
    try {
      while (!Objects.equals(expectedValue, expressionToCheck.get())) {
        if (System.currentTimeMillis() - startTime >= timeoutInMs) {
          return false;
        }
        Thread.sleep(CHECK_INTERVAL_IN_MS);
      }
    } catch (InterruptedException e) {
      return false;
    }
    return true;
  }
Periodically check expectedValue and actualValue until timeout.
@param expectedValue the expected value.
@param expressionToCheck the expression to check.
@param timeoutInMs the time out in millisecond.
@return true if value match.
ambry-test-utils/src/main/java/com/github/ambry/utils/TestUtils.java