private static void waitForEvent(long millis, String action, Supplier<Boolean> check)
    throws InterruptedIOException {
    long end = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(millis);

    while (true) {
      if (check.get()) {
        return;
      }

      if (System.nanoTime() > end) {
        String msg = "Master not " + action + " after " + millis + "ms";
        Threads.printThreadInfo(System.out, "Thread dump because: " + msg);
        throw new RuntimeException(msg);
      }

      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        throw (InterruptedIOException) new InterruptedIOException().initCause(e);
      }
    }

  }
Utility method to wait some time for an event to occur, and then return control to the caller.
@param millis How long to wait, in milliseconds.
@param action The action that we are waiting for. Will be used in log message if the event does
              not occur.
@param check  A Supplier that will be checked periodically to produce an updated true/false
              result indicating if the expected event has happened or not.
@throws InterruptedIOException If we are interrupted while waiting for the event.
@throws RuntimeException       If we reach the specified timeout while waiting for the event.
hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java