@Override
    public boolean retryRequest(HttpResponse response, int executionCount, HttpContext ctx) {
        log.fine(() -> String.format("retryRequest(responseCode='%s', executionCount='%d', ctx='%s'",
                                     response.getStatusLine().getStatusCode(), executionCount, ctx));
        HttpClientContext clientCtx = HttpClientContext.adapt(ctx);
        if (!predicate.test(response, clientCtx)) {
            log.fine(() -> String.format("Not retrying for '%s'", ctx));
            return false;
        }
        if (executionCount > maxRetries) {
            log.fine(() -> String.format("Max retries exceeded for '%s'", ctx));
            retryFailedConsumer.onRetryFailed(response, executionCount, clientCtx);
            return false;
        }
        Duration delay = delaySupplier.getDelay(executionCount);
        log.fine(() -> String.format("Retrying after %s for '%s'", delay, ctx));
        retryInterval.set(delay.toMillis());
        retryConsumer.onRetry(response, delay, executionCount, clientCtx);
        return true;
    }
@Test
    void retries_for_listed_exceptions_until_max_retries_exceeded() {
        int maxRetries = 2;

        DelayedResponseLevelRetryHandler handler = DelayedResponseLevelRetryHandler.Builder
                .withFixedDelay(Duration.ofSeconds(2), maxRetries)
                .retryForStatusCodes(List.of(HttpStatus.SC_SERVICE_UNAVAILABLE, HttpStatus.SC_BAD_GATEWAY))
                .build();

        HttpResponse response = createResponse(HttpStatus.SC_SERVICE_UNAVAILABLE);
        HttpClientContext ctx = new HttpClientContext();
        int lastExecutionCount = maxRetries + 1;
        for (int i = 1; i < lastExecutionCount; i++) {
            assertTrue(handler.retryRequest(response, i, ctx));
        }
        assertFalse(handler.retryRequest(response, lastExecutionCount, ctx));
    }