use of com.linkedin.r2.transport.common.bridge.client.TransportCallbackAdapter in project rest.li by linkedin.
the class TestHttpNettyStreamClient method testMakingOutboundHttpsRequest.
@Test(enabled = false)
public void testMakingOutboundHttpsRequest() throws NoSuchAlgorithmException, InterruptedException, ExecutionException, TimeoutException {
SSLContext context = SSLContext.getDefault();
SSLParameters sslParameters = context.getDefaultSSLParameters();
HttpNettyStreamClient client = new HttpClientBuilder(_eventLoop, _scheduler).setSSLContext(context).setSSLParameters(sslParameters).buildStream();
RestRequest r = new RestRequestBuilder(URI.create("https://www.howsmyssl.com/a/check")).build();
FutureCallback<StreamResponse> cb = new FutureCallback<StreamResponse>();
TransportCallback<StreamResponse> callback = new TransportCallbackAdapter<StreamResponse>(cb);
client.streamRequest(Messages.toStreamRequest(r), new RequestContext(), new HashMap<String, String>(), callback);
cb.get(30, TimeUnit.SECONDS);
}
use of com.linkedin.r2.transport.common.bridge.client.TransportCallbackAdapter in project rest.li by linkedin.
the class TestHttpNettyClient method testNoChannelTimeout.
@Test
public void testNoChannelTimeout() throws InterruptedException {
HttpNettyClient client = new HttpNettyClient(new NoCreations(_scheduler), _scheduler, 500, 500, 1024 * 1024 * 2);
RestRequest r = new RestRequestBuilder(URI.create("http://localhost/")).build();
FutureCallback<RestResponse> cb = new FutureCallback<RestResponse>();
TransportCallback<RestResponse> callback = new TransportCallbackAdapter<RestResponse>(cb);
client.restRequest(r, new RequestContext(), new HashMap<String, String>(), callback);
try {
// This timeout needs to be significantly larger than the getTimeout of the netty client;
// we're testing that the client will generate its own timeout
cb.get(30, TimeUnit.SECONDS);
Assert.fail("Get was supposed to time out");
} catch (TimeoutException e) {
// TimeoutException means the timeout for Future.get() elapsed and nothing happened.
// Instead, we are expecting our callback to be invoked before the future timeout
// with a timeout generated by the HttpNettyClient.
Assert.fail("Unexpected TimeoutException, should have been ExecutionException", e);
} catch (ExecutionException e) {
verifyCauseChain(e, RemoteInvocationException.class, TimeoutException.class);
}
}
use of com.linkedin.r2.transport.common.bridge.client.TransportCallbackAdapter in project rest.li by linkedin.
the class TestHttpNettyClient method testShutdownStuckInPool.
@Test
public void testShutdownStuckInPool() throws InterruptedException, ExecutionException, TimeoutException {
// Test that shutdown works when the outstanding request is stuck in the pool waiting for a channel
HttpNettyClient client = new HttpNettyClient(new NoCreations(_scheduler), _scheduler, 60000, 1, 1024 * 1024 * 2);
RestRequest r = new RestRequestBuilder(URI.create("http://some.host/")).build();
FutureCallback<RestResponse> futureCallback = new FutureCallback<RestResponse>();
client.restRequest(r, new RequestContext(), new HashMap<String, String>(), new TransportCallbackAdapter<RestResponse>(futureCallback));
FutureCallback<None> shutdownCallback = new FutureCallback<None>();
client.shutdown(shutdownCallback);
shutdownCallback.get(30, TimeUnit.SECONDS);
try {
futureCallback.get(30, TimeUnit.SECONDS);
Assert.fail("get should have thrown exception");
} catch (ExecutionException e) {
verifyCauseChain(e, RemoteInvocationException.class, TimeoutException.class);
}
}
use of com.linkedin.r2.transport.common.bridge.client.TransportCallbackAdapter in project rest.li by linkedin.
the class TestHttpNettyStreamClient method testNoResponseTimeout.
@Test(dataProvider = "noResponseClients")
public void testNoResponseTimeout(AbstractNettyStreamClient client) throws Exception {
CountDownLatch responseLatch = new CountDownLatch(1);
Server server = new HttpServerBuilder().responseLatch(responseLatch).build();
try {
server.start();
RestRequest r = new RestRequestBuilder(new URI(URL)).build();
FutureCallback<StreamResponse> cb = new FutureCallback<StreamResponse>();
TransportCallback<StreamResponse> callback = new TransportCallbackAdapter<StreamResponse>(cb);
client.streamRequest(Messages.toStreamRequest(r), new RequestContext(), new HashMap<String, String>(), callback);
// This timeout needs to be significantly larger than the getTimeout of the netty client;
// we're testing that the client will generate its own timeout
cb.get(30, TimeUnit.SECONDS);
Assert.fail("Get was supposed to time out");
} catch (TimeoutException e) {
// TimeoutException means the timeout for Future.get() elapsed and nothing happened.
// Instead, we are expecting our callback to be invoked before the future timeout
// with a timeout generated by the HttpNettyClient.
Assert.fail("Unexpected TimeoutException, should have been ExecutionException", e);
} catch (ExecutionException e) {
verifyCauseChain(e, RemoteInvocationException.class, TimeoutException.class);
} finally {
responseLatch.countDown();
server.stop();
}
}
use of com.linkedin.r2.transport.common.bridge.client.TransportCallbackAdapter 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).buildRest();
RestRequest r = new RestRequestBuilder(testServer.getResponseOfSizeURI(responseSize)).build();
FutureCallback<RestResponse> cb = new FutureCallback<RestResponse>();
TransportCallback<RestResponse> callback = new TransportCallbackAdapter<RestResponse>(cb);
client.restRequest(r, new RequestContext(), new HashMap<String, String>(), 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();
}
Aggregations