BaseHttpClient { public Future<HttpResponse<T>> request(final HttpRequest.Builder request) { return this.request(request.build()); } BaseHttpClient(HttpAsyncEngine engine); void addDefaultHeader(String key, String value); Future<HttpResponse<T>> request(final HttpRequest.Builder request); Future<HttpResponse<T>> request(final HttpRequest request);  }
@Test public void testConcurrency(){ int n = 1000; final CountDownLatch latch = new CountDownLatch(n); StringHttpClient http = new StringHttpClient(new RandomResponseAndLatencyHttpEngine(1, 30)); for(int i=0;i<n;i++){ http.request(Requests .get("SOME_URL") ).consume(r -> { latch.countDown(); }); } try { latch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { } assertEquals(0, latch.getCount()); }
@Test public void test200(){ StringHttpClient http = new StringHttpClient(new StatusCodeReplyHttpAsyncEngine()); try{ http.request(Requests.get("200")).await(); http.request(Requests.get("201")).await(); http.request(Requests.get("202")).await(); http.request(Requests.get("203")).await(); http.request(Requests.get("204")).await(); http.request(Requests.get("205")).await(); http.request(Requests.get("206")).await(); }catch (Exception ex){ fail("No exception should have been thrown"); } try{ http.request(Requests.get("404")).await(); }catch (HttpException ex){ assertEquals(404, ex.getStatusCode()); }catch (Exception ex){ fail("An HttpException exception should have been thrown"); } }
@Test public void test404(){ StringHttpClient http = new StringHttpClient(new StatusCodeReplyHttpAsyncEngine()); try{ http.request(Requests.get("404")).await(); }catch (HttpException ex){ assertEquals(404, ex.getStatusCode()); }catch (Exception ex){ fail("An HttpException exception should have been thrown"); } }
@Test public void test500(){ StringHttpClient http = new StringHttpClient(new StatusCodeReplyHttpAsyncEngine()); try{ http.request(Requests.get("500")).await(); }catch (HttpException ex){ assertEquals(500, ex.getStatusCode()); }catch (Exception ex){ fail("An HttpException exception should have been thrown"); } }