use of com.linkedin.r2.transport.http.client.HttpClientBuilder in project rest.li by linkedin.
the class TestHttpNettyClient method testResponseSize.
public void testResponseSize(int responseSize, int expectedResult) throws InterruptedException, IOException, TimeoutException {
TestServer testServer = new TestServer();
HttpNettyClient client = new HttpClientBuilder(_eventLoop, _scheduler).setRequestTimeout(50000).setIdleTimeout(10000).setShutdownTimeout(500).setMaxResponseSize(TEST_MAX_RESPONSE_SIZE).buildRestClient();
RestRequest r = new RestRequestBuilder(testServer.getResponseOfSizeURI(responseSize)).build();
FutureCallback<RestResponse> cb = new FutureCallback<>();
TransportCallback<RestResponse> callback = new TransportCallbackAdapter<>(cb);
client.restRequest(r, new RequestContext(), new HashMap<>(), callback);
try {
cb.get(30, TimeUnit.SECONDS);
if (expectedResult == TOO_LARGE) {
Assert.fail("Max response size exceeded, expected exception. ");
}
} catch (ExecutionException e) {
if (expectedResult == RESPONSE_OK) {
Assert.fail("Unexpected ExecutionException, response was <= max response size.");
}
verifyCauseChain(e, RemoteInvocationException.class, TooLongFrameException.class);
}
testServer.shutdown();
}
use of com.linkedin.r2.transport.http.client.HttpClientBuilder in project rest.li by linkedin.
the class TestHttpNettyClient method testShutdown.
@Test
public void testShutdown() throws ExecutionException, TimeoutException, InterruptedException {
HttpNettyClient client = new HttpClientBuilder(_eventLoop, _scheduler).setRequestTimeout(500).setIdleTimeout(10000).setShutdownTimeout(500).buildRestClient();
FutureCallback<None> shutdownCallback = new FutureCallback<>();
client.shutdown(shutdownCallback);
shutdownCallback.get(30, TimeUnit.SECONDS);
// Now verify a new request will also fail
RestRequest r = new RestRequestBuilder(URI.create("http://no.such.host.linkedin.com")).build();
FutureCallback<RestResponse> callback = new FutureCallback<>();
client.restRequest(r, new RequestContext(), new HashMap<>(), new TransportCallbackAdapter<>(callback));
try {
callback.get(30, TimeUnit.SECONDS);
} catch (ExecutionException e) {
// Expected
}
}
use of com.linkedin.r2.transport.http.client.HttpClientBuilder in project rest.li by linkedin.
the class TestHttpNettyClient method testMakingOutboundHttpsRequest.
@Test(enabled = false)
public void testMakingOutboundHttpsRequest() throws NoSuchAlgorithmException, InterruptedException, ExecutionException, TimeoutException {
SSLContext context = SSLContext.getDefault();
SSLParameters sslParameters = context.getDefaultSSLParameters();
HttpNettyClient client = new HttpClientBuilder(_eventLoop, _scheduler).setSSLContext(context).setSSLParameters(sslParameters).buildRestClient();
RestRequest r = new RestRequestBuilder(URI.create("https://www.howsmyssl.com/a/check")).build();
FutureCallback<RestResponse> cb = new FutureCallback<>();
TransportCallback<RestResponse> callback = new TransportCallbackAdapter<>(cb);
client.restRequest(r, new RequestContext(), new HashMap<>(), callback);
cb.get(30, TimeUnit.SECONDS);
}
use of com.linkedin.r2.transport.http.client.HttpClientBuilder in project rest.li by linkedin.
the class TestHttpNettyClient method testPoolStatsProviderManager.
@Test
public void testPoolStatsProviderManager() throws InterruptedException, ExecutionException, TimeoutException {
final CountDownLatch setLatch = new CountDownLatch(1);
final CountDownLatch removeLatch = new CountDownLatch(1);
AbstractJmxManager manager = new AbstractJmxManager() {
@Override
public void onProviderCreate(PoolStatsProvider provider) {
setLatch.countDown();
}
@Override
public void onProviderShutdown(PoolStatsProvider provider) {
removeLatch.countDown();
}
};
HttpNettyClient client = new HttpClientBuilder(_eventLoop, _scheduler).setJmxManager(manager).buildRestClient();
// test setPoolStatsProvider
try {
setLatch.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Assert.fail("PoolStatsAware setPoolStatsProvider didn't get called when creating channel pool.");
}
// test removePoolStatsProvider
FutureCallback<None> shutdownCallback = new FutureCallback<>();
client.shutdown(shutdownCallback);
try {
removeLatch.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Assert.fail("PoolStatsAware removePoolStatsProvider didn't get called when shutting down channel pool.");
}
shutdownCallback.get(30, TimeUnit.SECONDS);
}
use of com.linkedin.r2.transport.http.client.HttpClientBuilder in project rest.li by linkedin.
the class TestHttpNettyClient method testHeaderSize.
public void testHeaderSize(int headerSize, int expectedResult) throws InterruptedException, IOException, TimeoutException {
TestServer testServer = new TestServer();
HttpNettyClient client = new HttpClientBuilder(_eventLoop, _scheduler).setRequestTimeout(5000000).setIdleTimeout(10000).setShutdownTimeout(500).setMaxHeaderSize(TEST_MAX_HEADER_SIZE).buildRestClient();
RestRequest r = new RestRequestBuilder(testServer.getResponseWithHeaderSizeURI(headerSize)).build();
FutureCallback<RestResponse> cb = new FutureCallback<>();
TransportCallback<RestResponse> callback = new TransportCallbackAdapter<>(cb);
client.restRequest(r, new RequestContext(), new HashMap<>(), callback);
try {
RestResponse response = cb.get(300, TimeUnit.SECONDS);
if (expectedResult == TOO_LARGE) {
Assert.fail("Max header size exceeded, expected exception. ");
}
} catch (ExecutionException e) {
if (expectedResult == RESPONSE_OK) {
Assert.fail("Unexpected ExecutionException, header was <= max header size.");
}
verifyCauseChain(e, RemoteInvocationException.class, TooLongFrameException.class);
}
testServer.shutdown();
}
Aggregations