public static void retry(String action, RunnableThrowsIOException f, RetryPolicy policy)
      throws IOException {
    IOException e = null;
    while (policy.attempt()) {
      try {
        f.run();
        return;
      } catch (IOException ioe) {
        e = ioe;
        LOG.debug("Failed to {} (attempt {}): {}", action, policy.getAttemptCount(), e.toString());
      }
    }
    if (e != null) {
      throw e;
    }
    throw new IOException(String.format("Failed to run action %s after %d attempts",
        action, policy.getAttemptCount()));
  }
@Test
  public void success() throws IOException {
    AtomicInteger count = new AtomicInteger(0);
    RetryUtils.retry("success test", () -> {
      count.incrementAndGet();
      if (count.get() == 5) {
        return;
      }
      throw new IOException("Fail");
    }, new CountingRetry(10));
    assertEquals(5, count.get());
  }