testServerCloseSocketInputProvidesData() — netty Function Reference
Architecture documentation for the testServerCloseSocketInputProvidesData() function in HttpClientCodecTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 327ec659_e29e_87dc_59e2_519c04baf487["testServerCloseSocketInputProvidesData()"] c395f8e2_08a9_4e0c_820e_5851189d51c7["HttpClientCodecTest"] 327ec659_e29e_87dc_59e2_519c04baf487 -->|defined in| c395f8e2_08a9_4e0c_820e_5851189d51c7 style 327ec659_e29e_87dc_59e2_519c04baf487 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java lines 126–202
@Test
public void testServerCloseSocketInputProvidesData() throws InterruptedException {
ServerBootstrap sb = new ServerBootstrap();
Bootstrap cb = new Bootstrap();
final CountDownLatch serverChannelLatch = new CountDownLatch(1);
final CountDownLatch responseReceivedLatch = new CountDownLatch(1);
try {
sb.group(new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory()));
sb.channel(NioServerSocketChannel.class);
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
// Don't use the HttpServerCodec, because we don't want to have content-length or anything added.
ch.pipeline().addLast(new HttpRequestDecoder(4096, 8192, 8192, true));
ch.pipeline().addLast(new HttpObjectAggregator(4096));
ch.pipeline().addLast(new SimpleChannelInboundHandler<FullHttpRequest>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) {
// This is just a simple demo...don't block in IO
assertTrue(ctx.channel() instanceof SocketChannel);
final SocketChannel sChannel = (SocketChannel) ctx.channel();
/**
* The point of this test is to not add any content-length or content-encoding headers
* and the client should still handle this.
* See <a href="https://tools.ietf.org/html/rfc7230#section-3.3.3">RFC 7230, 3.3.3</a>.
*/
sChannel.writeAndFlush(Unpooled.wrappedBuffer(("HTTP/1.0 200 OK\r\n" +
"Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n" +
"Content-Type: text/html\r\n\r\n").getBytes(CharsetUtil.ISO_8859_1)))
.addListener(future -> {
assertTrue(future.isSuccess());
sChannel.writeAndFlush(Unpooled.wrappedBuffer(
"<html><body>hello half closed!</body></html>\r\n"
.getBytes(CharsetUtil.ISO_8859_1)))
.addListener(f -> {
assertTrue(f.isSuccess());
sChannel.shutdownOutput();
});
});
}
});
serverChannelLatch.countDown();
}
});
cb.group(new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()));
cb.channel(NioSocketChannel.class);
cb.option(ChannelOption.ALLOW_HALF_CLOSURE, true);
cb.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(new HttpClientCodec(4096, 8192, 8192, true, true));
ch.pipeline().addLast(new HttpObjectAggregator(4096));
ch.pipeline().addLast(new SimpleChannelInboundHandler<FullHttpResponse>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) {
responseReceivedLatch.countDown();
}
});
}
});
Channel serverChannel = sb.bind(new InetSocketAddress(0)).sync().channel();
int port = ((InetSocketAddress) serverChannel.localAddress()).getPort();
ChannelFuture ccf = cb.connect(new InetSocketAddress(NetUtil.LOCALHOST, port));
assertTrue(ccf.awaitUninterruptibly().isSuccess());
Channel clientChannel = ccf.channel();
assertTrue(serverChannelLatch.await(5, SECONDS));
clientChannel.writeAndFlush(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
assertTrue(responseReceivedLatch.await(5, SECONDS));
} finally {
sb.config().group().shutdownGracefully().syncUninterruptibly();
sb.config().childGroup().shutdownGracefully().syncUninterruptibly();
cb.config().group().shutdownGracefully().syncUninterruptibly();
}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does testServerCloseSocketInputProvidesData() do?
testServerCloseSocketInputProvidesData() is a function in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java.
Where is testServerCloseSocketInputProvidesData() defined?
testServerCloseSocketInputProvidesData() is defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java at line 126.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free