@Test
public void testConnectionPoolMetrics() throws InterruptedException, ExecutionException, TimeoutException {
HttpClientBuilder<ByteBuf, ByteBuf> builder = RxContexts.newHttpClientBuilder("www.google.com", 80, RxContexts.DEFAULT_CORRELATOR);
HttpClient<ByteBuf, ByteBuf> client = builder.withConnectionPoolLimitStrategy(new CompositePoolLimitDeterminationStrategy(
new MaxConnectionsBasedStrategy(100), new MaxConnectionsBasedStrategy(100))).build();
HttpClientListener listener = HttpClientListener.newHttpListener("default");
client.subscribe(listener);
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/");
client.submit(request).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<ByteBuf>>(){
@Override
public Observable<ByteBuf> call(HttpClientResponse<ByteBuf> t1) {
return t1.getContent();
}
}).map(new Func1<ByteBuf, String>(){
@Override
public String call(ByteBuf t1) {
return t1.toString(Charset.defaultCharset());
}
}).toBlocking().toFuture().get(1, TimeUnit.MINUTES);
Assert.assertEquals("Unexpected connection count.", 1, listener.getConnectionCount());
Assert.assertEquals("Unexpected pool acquire count.", 1, listener.getPoolAcquires());
}