public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) return false; if (response.getStatusCode() == 400 && command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getEndpoint().getPath().indexOf("sandboxes") != -1) { if (response.getPayload() != null) { String error = new String(closeClientButKeepContentStream(response)); if (error != null && error.indexOf("was not uploaded") != -1) { return backoffLimitedRetryHandler.shouldRetryRequest(command, response); } } } return false; }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) return false; if (response.getStatusCode() == 400 && command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getEndpoint().getPath().indexOf("sandboxes") != -1) { if (response.getPayload() != null) { String error = new String(closeClientButKeepContentStream(response)); if (error != null && error.indexOf("was not uploaded") != -1) { return backoffLimitedRetryHandler.shouldRetryRequest(command, response); } } } return false; }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) return false; if (response.getStatusCode() == 400 && command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getEndpoint().getPath().indexOf("sandboxes") != -1) { if (response.getPayload() != null) { String error = new String(closeClientButKeepContentStream(response)); if (error != null && error.indexOf("was not uploaded") != -1) { return backoffLimitedRetryHandler.shouldRetryRequest(command, response); } } } return false; }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) return false; if (response.getStatusCode() == 400 && command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getEndpoint().getPath().indexOf("sandboxes") != -1) { if (response.getPayload() != null) { String error = new String(closeClientButKeepContentStream(response)); if (error != null && error.indexOf("was not uploaded") != -1) { return backoffLimitedRetryHandler.shouldRetryRequest(command, response); } } } return false; }
private boolean ifReplayableBackoffAndReturnTrue(HttpCommand command) { command.incrementFailureCount(); if (!command.isReplayable()) { logger.error("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { imposeBackoffExponentialDelay(command.getFailureCount(), "server error: " + command.toString()); return true; } }
private boolean ifReplayableBackoffAndReturnTrue(HttpCommand command) { command.incrementFailureCount(); if (!command.isReplayable()) { logger.error("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { imposeBackoffExponentialDelay(command.getFailureCount(), "server error: " + command.toString()); return true; } }
private boolean ifReplayableBackoffAndReturnTrue(HttpCommand command) { command.incrementFailureCount(); if (!command.isReplayable()) { logger.error("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { imposeBackoffExponentialDelay(command.getFailureCount(), "server error: " + command.toString()); return true; } }
private boolean ifReplayableBackoffAndReturnTrue(HttpCommand command) { command.incrementFailureCount(); if (!command.isReplayable()) { logger.error("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { imposeBackoffExponentialDelay(command.getFailureCount(), "server error: " + command.toString()); return true; } }
private boolean ifReplayableBackoffAndReturnTrue(HttpCommand command) { command.incrementFailureCount(); if (!command.isReplayable()) { logger.error("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { imposeBackoffExponentialDelay(command.getFailureCount(), "server error: " + command.toString()); return true; } }
private boolean ifReplayableBackoffAndReturnTrue(HttpCommand command) { command.incrementFailureCount(); if (!command.isReplayable()) { logger.error("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { imposeBackoffExponentialDelay(command.getFailureCount(), "server error: " + command.toString()); return true; } }
public void testQueueDeletedRecentlyRetriesWhen60DoesntTry() { SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class), createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100); HttpCommand command = createHttpCommandForFailureCount(60); Stopwatch watch = Stopwatch.createStarted(); assertFalse(retry.shouldRetryRequestOnError(command, response, error)); assertEquals(command.getFailureCount(), 61); assertTrue(watch.stop().elapsed(TimeUnit.MILLISECONDS) < 100); }
public void testQueueDeletedRecentlyRetriesWhen59SleepsAndTries() { SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class), createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100); HttpCommand command = createHttpCommandForFailureCount(59); Stopwatch watch = Stopwatch.createStarted(); assertTrue(retry.shouldRetryRequestOnError(command, response, error)); assertEquals(command.getFailureCount(), 60); // allow for slightly inaccurate system timers assertTrue(watch.stop().elapsed(TimeUnit.MILLISECONDS) >= 98); }
public void testQueueDeletedRecentlyRetriesWhen60DoesntTry() { SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class), createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100); HttpCommand command = createHttpCommandForFailureCount(60); Stopwatch watch = new Stopwatch().start(); assertFalse(retry.shouldRetryRequestOnError(command, response, error)); assertEquals(command.getFailureCount(), 61); assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) < 100); }
public void testQueueDeletedRecentlyRetriesWhen59SleepsAndTries() { SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class), createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100); HttpCommand command = createHttpCommandForFailureCount(59); Stopwatch watch = new Stopwatch().start(); assertTrue(retry.shouldRetryRequestOnError(command, response, error)); assertEquals(command.getFailureCount(), 60); // allow for slightly inaccurate system timers assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) >= 98); }
@Test void testIncrementsFailureCount() throws InterruptedException, IOException, SecurityException, NoSuchMethodException { HttpCommand command = createCommand(); HttpResponse response = HttpResponse.builder().statusCode(400).build(); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 1); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 2); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 3); }
@Test void testIncrementsFailureCount() throws InterruptedException, IOException, SecurityException, NoSuchMethodException { HttpCommand command = createCommand(); HttpResponse response = HttpResponse.builder().statusCode(400).build(); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 1); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 2); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 3); }
@Test public void testGet500WithoutError() { AtmosUtils utils = createMock(AtmosUtils.class); BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class); HttpCommand command = createMock(HttpCommand.class); expect(command.getFailureCount()).andReturn(0).once(); expect(command.incrementFailureCount()).andReturn(1).once(); replay(utils, backoffLimitedRetryHandler, command); AtmosServerErrorRetryHandler retry = new AtmosServerErrorRetryHandler(backoffLimitedRetryHandler, utils); assertFalse(retry.shouldRetryRequest(command, HttpResponse.builder().statusCode(500).build())); verify(utils, backoffLimitedRetryHandler, command); }
@Test(timeOut = TEST_SAFE_TIMEOUT) public void testIncrementsFailureCount() { HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://localhost").build()); HttpResponse response = HttpResponse.builder().statusCode(429).build(); rateLimitRetryHandler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 1); rateLimitRetryHandler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 2); rateLimitRetryHandler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 3); }
HttpCommand createHttpCommandForFailureCount(final int failureCount) { HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://localhost").build()); while (command.getFailureCount() != failureCount) command.incrementFailureCount(); return command; } }
HttpCommand createHttpCommandForFailureCount(final int failureCount) { HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://localhost").build()); while (command.getFailureCount() != failureCount) command.incrementFailureCount(); return command; } }