use of com.linkedin.r2.transport.http.client.stream.http2.Http2NettyStreamClient in project rest.li by linkedin.
the class TestHttpNettyStreamClient method testHeaderSize.
public void testHeaderSize(AbstractNettyStreamClient client, int headerSize, int expectedResult) throws Exception {
Server server = new HttpServerBuilder().headerSize(headerSize).build();
try {
server.start();
RestRequest r = new RestRequestBuilder(new URI(URL)).build();
FutureCallback<StreamResponse> cb = new FutureCallback<>();
TransportCallback<StreamResponse> callback = new TransportCallbackAdapter<>(cb);
client.streamRequest(Messages.toStreamRequest(r), new RequestContext(), new HashMap<>(), callback);
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.", e);
}
if (client instanceof HttpNettyStreamClient) {
verifyCauseChain(e, RemoteInvocationException.class, TooLongFrameException.class);
} else if (client instanceof Http2NettyStreamClient) {
verifyCauseChain(e, RemoteInvocationException.class, Http2Exception.class);
} else {
Assert.fail("Unrecognized client");
}
} finally {
server.stop();
}
}
use of com.linkedin.r2.transport.http.client.stream.http2.Http2NettyStreamClient in project rest.li by linkedin.
the class TestHttp2NettyStreamClient method testRequestTimeout.
/**
* Tests the condition that when a client request times out before the request is processed
* by the server, the servlet implementation throws when attempting to read the request entity.
*/
@Test(enabled = false)
public void testRequestTimeout() throws Exception {
final AtomicInteger serverIOExceptions = new AtomicInteger(0);
final CountDownLatch exceptionLatch = new CountDownLatch(1);
final CountDownLatch responseLatch = new CountDownLatch(1);
final CountDownLatch serverLatch = new CountDownLatch(1);
final HttpServerBuilder serverBuilder = new HttpServerBuilder();
final Server server = serverBuilder.exceptionListener(throwable -> {
if (throwable instanceof IOException) {
serverIOExceptions.incrementAndGet();
exceptionLatch.countDown();
}
}).responseLatch(serverLatch).build();
final HttpClientBuilder clientBuilder = new HttpClientBuilder(_eventLoop, _scheduler);
final Http2NettyStreamClient client = clientBuilder.setRequestTimeout(500).buildHttp2StreamClient();
try {
server.start();
// Sends the stream request
final StreamRequestBuilder builder = new StreamRequestBuilder(new URI(URL));
final StreamRequest request = builder.setMethod(METHOD).setHeader(HttpHeaderNames.HOST.toString(), HOST_NAME.toString()).build(EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(new byte[REQUEST_SIZE]))));
client.streamRequest(request, new RequestContext(), new HashMap<>(), response -> responseLatch.countDown());
// Waits for request to timeout
Thread.sleep(1000);
// Allows server to process request
serverLatch.countDown();
} finally {
if (!responseLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS)) {
Assert.fail("Timeout waiting for response latch");
}
if (!exceptionLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS)) {
Assert.fail("Timeout waiting for exception latch");
}
server.stop();
}
// Expects two IOExceptions thrown by the server. One for the initial OPTIONS upgrade request and one for
// the actual GET request.
Assert.assertEquals(serverIOExceptions.get(), 2);
}
Aggregations