@Test(timeOut = TEST_SAFE_TIMEOUT) public void testRequestIsDelayed() { HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http: HttpResponse response = HttpResponse.builder().statusCode(429).addHeader(RETRY_AFTER, "5").build(); long start = System.currentTimeMillis(); assertTrue(rateLimitRetryHandler.shouldRetryRequest(command, response)); assertTrue(System.currentTimeMillis() - start > 2500); }
@Override public boolean shouldRetryRequest(final HttpCommand command, final HttpResponse response) { command.incrementFailureCount(); if (response.getStatusCode() != rateLimitErrorStatus()) { return false; } else if (!command.isReplayable()) { logger.error("Cannot retry after rate limit error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after rate limit error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { return delayRequestUntilAllowed(command, response); } }
RateLimitRetryHandler implements HttpRetryHandler { @Override public boolean shouldRetryRequest(final HttpCommand command, final HttpResponse response) { command.incrementFailureCount(); if (response.getStatusCode() != rateLimitErrorStatus()) { return false; } else if (!command.isReplayable()) { logger.error("Cannot retry after rate limit error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after rate limit error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { return delayRequestUntilAllowed(command, response); } } }
RateLimitRetryHandler implements HttpRetryHandler { @Override public boolean shouldRetryRequest(final HttpCommand command, final HttpResponse response) { command.incrementFailureCount(); if (response.getStatusCode() != rateLimitErrorStatus()) { return false; } else if (!command.isReplayable()) { logger.error("Cannot retry after rate limit error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after rate limit error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { return delayRequestUntilAllowed(command, response); } }  }
RateLimitRetryHandler implements HttpRetryHandler { @Override public boolean shouldRetryRequest(final HttpCommand command, final HttpResponse response) { command.incrementFailureCount(); if (response.getStatusCode() != rateLimitErrorStatus()) { return false; } else if (!command.isReplayable()) { logger.error("Cannot retry after rate limit error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after rate limit error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { return delayRequestUntilAllowed(command, response); } }  @Override boolean shouldRetryRequest(final HttpCommand command, final HttpResponse response); int getRetryCountLimit(); int getMaxRateLimitWait(); }
RateLimitRetryHandler implements HttpRetryHandler { @Override public boolean shouldRetryRequest(final HttpCommand command, final HttpResponse response) { command.incrementFailureCount(); if (response.getStatusCode() != rateLimitErrorStatus()) { return false; } else if (!command.isReplayable()) { logger.error("Cannot retry after rate limit error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after rate limit error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { return delayRequestUntilAllowed(command, response); } }  @Override boolean shouldRetryRequest(final HttpCommand command, final HttpResponse response); int getRetryCountLimit(); int getMaxRateLimitWait();  }