@Test public void executeShouldRetryIfStatusCodeIsGreaterThan400AndReturnResponseIsRetryIsSuccess() throws Exception { RequestException requestException1 = mock(RequestException.class); ArgumentCaptor<RequestException> requestException2 = ArgumentCaptor.forClass(RequestException.class); Response badResponse = mock(Response.class); when(badResponse.getStatusCode()).thenReturn(123); when(retryHandler.retry(requestException1, 2)).thenReturn(true); when(retryHandler.retry(requestException2.capture(), eq(3))).thenReturn(true); when(mockRequestExecutor.execute(request)).thenThrow(requestException1).thenReturn(badResponse, expected); Response actual = toTest.execute(request); assertSame(expected, actual); verify(requestException1).dispose(); }
public Response execute(Request request) throws Exception { RetryHandler retryHandler = request.getMethodConfig().getRetryHandler(); RequestException exception = null; Response response; int attemptCount = 1; do { Disposables.dispose(exception); response = null; try { response = delegate.execute(request); if(response.getStatusCode() >= minErrorStatusCode) { exception = new RequestException("Request failed - status code: " + response.getStatusCode(), response); }else{ return response; } } catch (RequestException e) { exception = e; } }while(retryHandler.retry(exception, ++attemptCount)); if(response != null) { return response; } throw exception; }
RetryingRequestExecutor implements RequestExecutor { public Response execute(Request request) throws Exception { RetryHandler retryHandler = request.getMethodConfig().getRetryHandler(); RequestException exception = null; Response response; int attemptCount = 1; do { Disposables.dispose(exception); response = null; try { response = delegate.execute(request); if(response.getStatusCode() >= minErrorStatusCode) { exception = new RequestException("Request failed - status code: " + response.getStatusCode(), response); }else{ return response; } } catch (RequestException e) { exception = e; } }while(retryHandler.retry(exception, ++attemptCount)); if(response != null) { return response; } throw exception; } }
RetryingRequestExecutor implements RequestExecutor { public Response execute(Request request) throws Exception { RetryHandler retryHandler = request.getMethodConfig().getRetryHandler(); RequestException exception = null; Response response; int attemptCount = 1; do { Disposables.dispose(exception); response = null; try { response = delegate.execute(request); if(response.getStatusCode() >= minErrorStatusCode) { exception = new RequestException("Request failed - status code: " + response.getStatusCode(), response); }else{ return response; } } catch (RequestException e) { exception = e; } }while(retryHandler.retry(exception, ++attemptCount)); if(response != null) { return response; } throw exception; } RetryingRequestExecutor(RequestExecutor delegate, int minErrorStatusCode); }
RetryingRequestExecutor implements RequestExecutor { public Response execute(Request request) throws Exception { RetryHandler retryHandler = request.getMethodConfig().getRetryHandler(); RequestException exception = null; Response response; int attemptCount = 1; do { Disposables.dispose(exception); response = null; try { response = delegate.execute(request); if(response.getStatusCode() >= minErrorStatusCode) { exception = new RequestException("Request failed - status code: " + response.getStatusCode(), response); }else{ return response; } } catch (RequestException e) { exception = e; } }while(retryHandler.retry(exception, ++attemptCount)); if(response != null) { return response; } throw exception; } RetryingRequestExecutor(RequestExecutor delegate, int minErrorStatusCode); Response execute(Request request); }
RetryingRequestExecutor implements RequestExecutor { public Response execute(Request request) throws Exception { RetryHandler retryHandler = request.getMethodConfig().getRetryHandler(); RequestException exception = null; Response response; int attemptCount = 1; do { Disposables.dispose(exception); response = null; try { response = delegate.execute(request); if(response.getStatusCode() >= minErrorStatusCode) { exception = new RequestException("Request failed - status code: " + response.getStatusCode(), response); }else{ return response; } } catch (RequestException e) { exception = e; } }while(retryHandler.retry(exception, ++attemptCount)); if(response != null) { return response; } throw exception; } RetryingRequestExecutor(RequestExecutor delegate, int minErrorStatusCode); Response execute(Request request);  }