smokeTest() — netty Function Reference
Architecture documentation for the smokeTest() function in CodecHttp2Test.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 3bfc87d3_a3cc_9da7_8bf6_c48e7c666fe3["smokeTest()"] 9cde399d_fb6a_abb8_d6b0_5ac4951f70a0["CodecHttp2Test"] 3bfc87d3_a3cc_9da7_8bf6_c48e7c666fe3 -->|defined in| 9cde399d_fb6a_abb8_d6b0_5ac4951f70a0 style 3bfc87d3_a3cc_9da7_8bf6_c48e7c666fe3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
testsuite-jpms/src/test/java/io/netty/testsuite_jpms/test/CodecHttp2Test.java lines 65–164
@Test
public void smokeTest() throws Exception {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.channel(NioServerSocketChannel.class);
MultiThreadIoEventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
serverBootstrap.group(eventLoopGroup);
serverBootstrap.childHandler(new ChannelInitializer<>() {
@Override
protected void initChannel(Channel ch) {
ch.pipeline().addLast(Http2FrameCodecBuilder.forServer().build(), new ChannelDuplexHandler() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Http2HeadersFrame) {
Http2HeadersFrame streamFrame = (Http2HeadersFrame) msg;
if (streamFrame.isEndStream()) {
ByteBuf body = ctx.alloc().buffer();
body.writeCharSequence("Hello World", StandardCharsets.UTF_8);
Http2Headers headers = new DefaultHttp2Headers().status(OK.codeAsText());
Http2FrameStream stream = streamFrame.stream();
ctx.write(new DefaultHttp2HeadersFrame(headers).stream(stream));
ctx.write(new DefaultHttp2DataFrame(body, true).stream(stream));
}
} else {
super.channelRead(ctx, msg);
}
}
});
}
});
ChannelFuture server = serverBootstrap.bind("localhost", 8080).sync();
try {
Bootstrap clientBootstrap = new Bootstrap()
.group(eventLoopGroup)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<>() {
@Override
protected void initChannel(Channel ch) {
Http2FrameCodec http2FrameCodec = Http2FrameCodecBuilder.forClient().build();
ch.pipeline().addLast(http2FrameCodec);
ch.pipeline().addLast(new Http2MultiplexHandler(new SimpleChannelInboundHandler<>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
}
}));
}
});
CompletableFuture<String> responseFut = new CompletableFuture<>();
Channel client = clientBootstrap.handler(new ChannelInitializer<SocketChannel>() {
Http2Connection connection;
Http2ConnectionHandler connectionHandler;
@Override
protected void initChannel(SocketChannel ch) {
connection = new DefaultHttp2Connection(false);
Http2EventAdapter http2EventHandler = new Http2EventAdapter() {
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings)
throws Http2Exception {
Http2Connection.Endpoint<Http2LocalFlowController> endpoint = connection.local();
Http2Stream stream = endpoint.createStream(1, false);
Http2Headers headers = new DefaultHttp2Headers()
.method("GET")
.path("/")
.scheme("http");
ChannelPromise promise = ctx.newPromise();
Http2ConnectionEncoder encoder = connectionHandler.encoder();
encoder.writeHeaders(ctx, 1, headers, 0, true, promise);
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data,
int padding, boolean endOfStream) throws Http2Exception {
if (endOfStream) {
responseFut.complete(data.toString(StandardCharsets.UTF_8));
}
return super.onDataRead(ctx, streamId, data, padding, endOfStream);
}
};
connectionHandler = new Http2ConnectionHandlerBuilder()
Domain
Subdomains
Source
Frequently Asked Questions
What does smokeTest() do?
smokeTest() is a function in the netty codebase, defined in testsuite-jpms/src/test/java/io/netty/testsuite_jpms/test/CodecHttp2Test.java.
Where is smokeTest() defined?
smokeTest() is defined in testsuite-jpms/src/test/java/io/netty/testsuite_jpms/test/CodecHttp2Test.java at line 65.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free