use of io.netty.channel.embedded.EmbeddedChannel in project rest.li by linkedin.
the class TestChannelPoolHandler method testConnectionClose.
@Test(dataProvider = "connectionClose")
public void testConnectionClose(String headerName, String headerValue) {
EmbeddedChannel ch = new EmbeddedChannel(new ChannelPoolHandler());
FakePool pool = new FakePool();
ch.attr(ChannelPoolHandler.CHANNEL_POOL_ATTR_KEY).set(pool);
RestResponse response = new RestResponseBuilder().setHeader(headerName, headerValue).build();
ch.writeInbound(response);
Assert.assertTrue(pool.isDisposeCalled());
Assert.assertFalse(pool.isPutCalled());
}
use of io.netty.channel.embedded.EmbeddedChannel in project rest.li by linkedin.
the class TestChannelPoolStreamHandler method testConnectionClose.
@Test(dataProvider = "connectionClose")
public void testConnectionClose(String headerName, List<String> headerValue) {
EmbeddedChannel ch = getChannel();
FakePool pool = new FakePool();
ch.attr(ChannelPoolStreamHandler.CHANNEL_POOL_ATTR_KEY).set(pool);
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.ACCEPTED);
HttpContent lastChunk = new DefaultLastHttpContent();
response.headers().set(headerName, headerValue);
ch.writeInbound(response);
ch.writeInbound(lastChunk);
Assert.assertTrue(pool.isDisposeCalled());
Assert.assertFalse(pool.isPutCalled());
}
use of io.netty.channel.embedded.EmbeddedChannel in project rest.li by linkedin.
the class TestChannelPoolStreamHandler method testConnectionKeepAlive.
@Test(dataProvider = "connectionKeepAlive")
public void testConnectionKeepAlive(String headerName, List<String> headerValue) {
EmbeddedChannel ch = getChannel();
FakePool pool = new FakePool();
ch.attr(ChannelPoolStreamHandler.CHANNEL_POOL_ATTR_KEY).set(pool);
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.ACCEPTED);
HttpContent lastChunk = new DefaultLastHttpContent();
response.headers().set(headerName, headerValue);
ch.writeInbound(response);
ch.writeInbound(lastChunk);
Assert.assertFalse(pool.isDisposeCalled());
Assert.assertTrue(pool.isPutCalled());
}
use of io.netty.channel.embedded.EmbeddedChannel in project rest.li by linkedin.
the class TestRAPClientCodec method testRequestEncoder.
@Test(dataProvider = "restRequest")
public void testRequestEncoder(String uri, RestRequest request) {
final EmbeddedChannel ch = new EmbeddedChannel(new RAPClientCodec());
ch.writeOutbound(request);
FullHttpRequest nettyRequest = (FullHttpRequest) ch.readOutbound();
Assert.assertEquals(nettyRequest.uri(), uri);
Assert.assertEquals(nettyRequest.method(), HttpMethod.valueOf(request.getMethod()));
Assert.assertEquals(nettyRequest.content().toString(CHARSET), request.getEntity().asString(CHARSET));
Assert.assertEquals(nettyRequest.headers().get(HttpHeaderNames.HOST), HOST);
assertList(nettyRequest.headers().getAll(HttpConstants.REQUEST_COOKIE_HEADER_NAME), request.getCookies());
for (String name : request.getHeaders().keySet()) {
Assert.assertEquals(nettyRequest.headers().get(name), request.getHeader(name));
}
ch.finish();
}
use of io.netty.channel.embedded.EmbeddedChannel in project rest.li by linkedin.
the class TestRAPClientCodec method testResponseDecoder.
@Test(dataProvider = "responseData")
public void testResponseDecoder(int status, String entity, HttpHeaders headers, String[] cookies) {
final EmbeddedChannel ch = new EmbeddedChannel(new RAPClientCodec());
ByteBuf content = Unpooled.copiedBuffer(entity, CHARSET);
FullHttpResponse nettyResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(status), content);
nettyResponse.headers().set(headers);
for (String cookie : cookies) {
nettyResponse.headers().add(HttpHeaderNames.SET_COOKIE, cookie);
}
ch.writeInbound(nettyResponse);
RestResponse response = (RestResponse) ch.readInbound();
Assert.assertEquals(response.getStatus(), status);
Assert.assertEquals(response.getEntity().asString(CHARSET), entity);
assertList(response.getCookies(), nettyResponse.headers().getAll(HttpConstants.RESPONSE_COOKIE_HEADER_NAME));
for (Map.Entry<String, String> header : nettyResponse.headers()) {
if (!header.getKey().equalsIgnoreCase(HttpConstants.RESPONSE_COOKIE_HEADER_NAME)) {
List<String> values = response.getHeaderValues(header.getKey());
Assert.assertNotNull(values);
Assert.assertTrue(values.contains(header.getValue()));
}
}
// make sure the incoming ByteBuf is released
Assert.assertEquals(content.refCnt(), 0);
ch.finish();
}
Aggregations