@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); }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) { return false; } if (response.getStatusCode() == 500) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); if (content != null) { try { AtmosError error = utils.parseAtmosErrorFromContent(command, response, new String(content)); if (error.getCode() == AtmosErrorCode.SERVER_BUSY.getCode()) { return backoffHandler.shouldRetryRequest(command, response); } command.incrementFailureCount(); } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } else { command.incrementFailureCount(); } return false; } return false; }
AtmosServerErrorRetryHandler implements HttpRetryHandler { public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) { return false; } if (response.getStatusCode() == 500) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); if (content != null) { try { AtmosError error = utils.parseAtmosErrorFromContent(command, response, new String(content)); if (error.getCode() == AtmosErrorCode.SERVER_BUSY.getCode()) { return backoffHandler.shouldRetryRequest(command, response); } command.incrementFailureCount(); } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } else { command.incrementFailureCount(); } return false; } return false; } }
AtmosServerErrorRetryHandler implements HttpRetryHandler { public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) { return false; } if (response.getStatusCode() == 500) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); if (content != null) { try { AtmosError error = utils.parseAtmosErrorFromContent(command, response, new String(content)); if (error.getCode() == AtmosErrorCode.SERVER_BUSY.getCode()) { return backoffHandler.shouldRetryRequest(command, response); } command.incrementFailureCount(); } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } else { command.incrementFailureCount(); } return false; } return false; } @Inject  AtmosServerErrorRetryHandler(BackoffLimitedRetryHandler backoffHandler,
            AtmosUtils utils); }
AtmosServerErrorRetryHandler implements HttpRetryHandler { public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) { return false; } if (response.getStatusCode() == 500) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); if (content != null) { try { AtmosError error = utils.parseAtmosErrorFromContent(command, response, new String(content)); if (error.getCode() == AtmosErrorCode.SERVER_BUSY.getCode()) { return backoffHandler.shouldRetryRequest(command, response); } command.incrementFailureCount(); } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } else { command.incrementFailureCount(); } return false; } return false; } @Inject  AtmosServerErrorRetryHandler(BackoffLimitedRetryHandler backoffHandler,
            AtmosUtils utils); boolean shouldRetryRequest(HttpCommand command, HttpResponse response); }
AtmosServerErrorRetryHandler implements HttpRetryHandler { public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) { return false; } if (response.getStatusCode() == 500) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); if (content != null) { try { AtmosError error = utils.parseAtmosErrorFromContent(command, response, new String(content)); if (error.getCode() == AtmosErrorCode.SERVER_BUSY.getCode()) { return backoffHandler.shouldRetryRequest(command, response); } command.incrementFailureCount(); } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } else { command.incrementFailureCount(); } return false; } return false; } @Inject  AtmosServerErrorRetryHandler(BackoffLimitedRetryHandler backoffHandler,
            AtmosUtils utils); boolean shouldRetryRequest(HttpCommand command, HttpResponse response);  }