public void testStreamIsClosedWhenRetrying() throws IOException { MockInputStream in = new MockInputStream(2); // Input stream that produces 2 bytes HttpResponse response = HttpResponse.builder().payload(newInputStreamPayload(in)).build(); response.getPayload().getContentMetadata().setContentLength(1L); HttpCommand command = mockHttpCommand(); DelegatingRetryHandler retryHandler = EasyMock.createMock(DelegatingRetryHandler.class); DelegatingErrorHandler errorHandler = EasyMock.createMock(DelegatingErrorHandler.class); expect(retryHandler.shouldRetryRequest(command, response)).andReturn(true); replay(retryHandler, errorHandler); // Verify the stream is open. This consumes one byte. assertEquals(response.getPayload().openStream().available(), 2); assertEquals(response.getPayload().openStream().read(), 1); BaseHttpCommandExecutorService<?> service = mockHttpCommandExecutorService(retryHandler, errorHandler); assertTrue(service.shouldContinue(command, response)); verify(retryHandler, errorHandler); // Verify that the response stream is closed and consumed assertFalse(in.isOpen); assertTrue(response.getPayload().openStream() == in); // The service shouldn't have changed it assertEquals(response.getPayload().openStream().available(), 0); assertEquals(response.getPayload().openStream().read(), -1); }
public void testStreamIsClosedWhenNotRetrying() throws IOException { MockInputStream in = new MockInputStream(2); // Input stream that produces 2 bytes HttpResponse response = HttpResponse.builder().payload(newInputStreamPayload(in)).build(); response.getPayload().getContentMetadata().setContentLength(1L); HttpCommand command = mockHttpCommand(); DelegatingRetryHandler retryHandler = EasyMock.createMock(DelegatingRetryHandler.class); DelegatingErrorHandler errorHandler = EasyMock.createMock(DelegatingErrorHandler.class); errorHandler.handleError(command, response); expectLastCall(); expect(retryHandler.shouldRetryRequest(command, response)).andReturn(false); replay(retryHandler, errorHandler); // Verify the stream is open. This consumes one byte. assertEquals(response.getPayload().openStream().available(), 2); assertEquals(response.getPayload().openStream().read(), 1); BaseHttpCommandExecutorService<?> service = mockHttpCommandExecutorService(retryHandler, errorHandler); assertFalse(service.shouldContinue(command, response)); verify(retryHandler, errorHandler); // Verify that the response stream is closed assertFalse(in.isOpen); assertTrue(response.getPayload().openStream() == in); assertEquals(response.getPayload().openStream().available(), 0); assertEquals(response.getPayload().openStream().read(), -1); }
assertFalse(service.shouldContinue(command, response));
if (shouldContinue(command, response)) continue; else if (ioe != null && shouldContinue(command, ioe)) { continue;
if (shouldContinue(command, response)) continue; else if (ioe != null && shouldContinue(command, ioe)) { continue;
assertFalse(service.shouldContinue(command, response));
if (shouldContinue(command, response)) continue; else if (ioe != null && shouldContinue(command, ioe)) { continue;
if (shouldContinue(command, response)) continue; else
if (shouldContinue(command, response)) continue; else
if (shouldContinue(command, response)) continue; else