@Test public void retry2() { AtomicInteger attempts = new AtomicInteger(); boolean failed = false; try { HttpResponseSupplier supplier = () -> { attempts.incrementAndGet(); throw new IOException("failed"); }; new TestRequestBuilder(supplier).withRetries(2).send(); } catch (IOException e) { failed = true; } Assertions.assertEquals(3, attempts.get()); Assertions.assertTrue(failed); }
@Test public void retry0() throws Exception { Assertions.assertThrows(IOException.class, () -> new TestRequestBuilder(() -> { throw new IOException("failed"); }).send()); }
private void retryStatus(HttpResponse expectedRes, int expectedAttempts) throws IOException { AtomicInteger attempts = new AtomicInteger(); HttpResponseSupplier supplier = () -> { attempts.incrementAndGet(); return expectedRes; }; HttpResponse res = new TestRequestBuilder(supplier) .withInitialRetryDelay(0L) .withRetries(2) .send(); Assertions.assertEquals(expectedAttempts, attempts.get()); Assertions.assertEquals(expectedRes.status(), res.status()); }
@Test public void hostnameVerificationWithHTTP() throws IOException { Assertions.assertThrows(IllegalStateException.class, () -> new TestRequestBuilder(() -> OK).allowAllHosts()); }
@Test public void ok() throws IOException { HttpResponse res = new TestRequestBuilder(() -> OK).send(); Assertions.assertEquals(200, res.status()); }
@Test public void hostnameVerificationWithHTTPS() throws IOException { HttpResponse res = new TestRequestBuilder(() -> OK, URI.create("https://foo.com/path")) .allowAllHosts() .send(); Assertions.assertEquals(200, res.status()); }