@Test void testDisallowsExcessiveRetries() throws InterruptedException, IOException, SecurityException, NoSuchMethodException { HttpCommand command = createCommand(); HttpResponse response = HttpResponse.builder().statusCode(400).build(); assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 1 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 2 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 3 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 4 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 5 assertEquals(handler.shouldRetryRequest(command, response), false); // Failure 6 }
@Test void testDisallowsExcessiveRetries() throws InterruptedException, IOException, SecurityException, NoSuchMethodException { HttpCommand command = createCommand(); HttpResponse response = HttpResponse.builder().statusCode(400).build(); assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 1 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 2 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 3 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 4 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 5 assertEquals(handler.shouldRetryRequest(command, response), false); // Failure 6 }
@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 void testInputStreamIsNotClosed() throws SecurityException, NoSuchMethodException, IOException { HttpCommand command = createCommand(); HttpResponse response = HttpResponse.builder().statusCode(500).build(); InputStream inputStream = new InputStream() { int count = 2; @Override public void close() { fail("The retry handler should not close the response stream"); } @Override public int read() throws IOException { return count < 0 ? -1 : --count; } @Override public int available() throws IOException { return count < 0 ? 0 : count; } }; response.setPayload(Payloads.newInputStreamPayload(inputStream)); response.getPayload().getContentMetadata().setContentLength(1L); assertEquals(response.getPayload().openStream().available(), 2); assertEquals(response.getPayload().openStream().read(), 1); handler.shouldRetryRequest(command, response); assertEquals(response.getPayload().openStream().available(), 1); assertEquals(response.getPayload().openStream().read(), 0); }
@Test void testClosesInputStream() throws InterruptedException, IOException, SecurityException, NoSuchMethodException { HttpCommand command = createCommand();