public static <U> Task<U> withRetryPolicy(String name, RetryPolicy policy, Function1<Integer, Task<U>> taskFunction) {
    RetriableTask<U> retriableTask = new RetriableTask<>(name, policy, taskFunction);
    Task<U> retryTaskWrapper = Task.async(name + " retriableTask", retriableTask::run);
    retryTaskWrapper.getShallowTraceBuilder().setTaskType(TaskType.WITH_RETRY.getName());
    return retryTaskWrapper;
  }
@Test
  public void testSimpleRetryPolicy()
  {
    Task<Void> task = withRetryPolicy("testSimpleRetryPolicy", RetryPolicy.attempts(3, 0),
        attempt -> Task.failure(new RuntimeException("current attempt: " + attempt)));
    runAndWaitException(task, RuntimeException.class);
    assertTrue(task.isDone());
    assertEquals(task.getError().getMessage(), "current attempt: 2");
  }