@Override
  public boolean retryRequest(
      HttpRequest request, IOException exception, int execCount, HttpContext context) {
    if (execCount > maxRetries) {
      // Do not retry if over max retries
      return false;
    }

    if (nonRetriableExceptions.contains(exception.getClass())) {
      return false;
    } else {
      for (Class<? extends IOException> rejectException : nonRetriableExceptions) {
        if (rejectException.isInstance(exception)) {
          return false;
        }
      }
    }

    if (request instanceof CancellableDependency
        && ((CancellableDependency) request).isCancelled()) {
      return false;
    }

    // Retry if the request is considered idempotent
    return Method.isIdempotent(request.getMethod());
  }
@Test
  public void basicRetry() {
    BasicHttpResponse response503 = new BasicHttpResponse(503, "Oopsie");
    assertThat(retryStrategy.retryRequest(response503, 3, null)).isTrue();

    BasicHttpResponse response429 = new BasicHttpResponse(429, "Oopsie");
    assertThat(retryStrategy.retryRequest(response429, 3, null)).isTrue();

    BasicHttpResponse response404 = new BasicHttpResponse(404, "Oopsie");
    assertThat(retryStrategy.retryRequest(response404, 3, null)).isFalse();
  }