.withReadTimeout((int) config.readTimeout().toMillis()) .withContent("application/x-jackson-smile", smileMapper.writeValueAsBytes(p)) .send(); } catch (IOException e) { logger.error("Unable to publish Atlas metrics", e);
@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 hostnameVerificationWithHTTPS() throws IOException { HttpResponse res = new TestRequestBuilder(() -> OK, URI.create("https://foo.com/path")) .allowAllHosts() .send(); Assertions.assertEquals(200, res.status()); }
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 ok() throws IOException { HttpResponse res = HttpClient.DEFAULT .get(uri("/ok")) .addHeader("X-Status", "200") .addHeader("X-Length", "-1") .send(); Assertions.assertEquals(200, res.status()); }
@Test public void unavailableEmptyChunked() throws IOException { HttpResponse res = HttpClient.DEFAULT .get(uri("/ok")) .addHeader("X-Status", "503") .addHeader("X-Length", "0") .send(); Assertions.assertEquals(503, res.status()); }
@Test public void emptyChunked() throws IOException { HttpResponse res = HttpClient.DEFAULT .get(uri("/ok")) .addHeader("X-Status", "200") .addHeader("X-Length", "0") .send(); Assertions.assertEquals(200, res.status()); }
@Test public void unavailableEmpty() throws IOException { HttpResponse res = HttpClient.DEFAULT .get(uri("/ok")) .addHeader("X-Status", "503") .addHeader("X-Length", "-1") .send(); Assertions.assertEquals(503, res.status()); }
@Test public void okWithBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .addHeader("X-Status", "200") .withContent("text/plain", "foo") .send(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); }
@Test public void okWithCompressedBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .acceptGzip() .addHeader("X-Status", "200") .withContent("text/plain", "foo") .compress() .send() .decompress(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); } }