upgradesPipelineInSameMethodInvocation() — netty Function Reference
Architecture documentation for the upgradesPipelineInSameMethodInvocation() function in HttpServerUpgradeHandlerTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 26606c94_ea67_e56d_6d9c_4abd98565bb9["upgradesPipelineInSameMethodInvocation()"] b1c607f7_af7c_9e8d_7626_d168a967f7a0["HttpServerUpgradeHandlerTest"] 26606c94_ea67_e56d_6d9c_4abd98565bb9 -->|defined in| b1c607f7_af7c_9e8d_7626_d168a967f7a0 style 26606c94_ea67_e56d_6d9c_4abd98565bb9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http/src/test/java/io/netty/handler/codec/http/HttpServerUpgradeHandlerTest.java lines 70–144
@Test
public void upgradesPipelineInSameMethodInvocation() {
final HttpServerCodec httpServerCodec = new HttpServerCodec();
final UpgradeCodecFactory factory = new UpgradeCodecFactory() {
@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
return new TestUpgradeCodec();
}
};
ChannelHandler testInStackFrame = new ChannelDuplexHandler() {
// marker boolean to signal that we're in the `channelRead` method
private boolean inReadCall;
private boolean writeUpgradeMessage;
private boolean writeFlushed;
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
assertFalse(inReadCall);
assertFalse(writeUpgradeMessage);
inReadCall = true;
try {
super.channelRead(ctx, msg);
// All in the same call stack, the upgrade codec should receive the message,
// written the upgrade response, and upgraded the pipeline.
assertTrue(writeUpgradeMessage);
assertFalse(writeFlushed);
assertNull(ctx.pipeline().get(HttpServerCodec.class));
assertNotNull(ctx.pipeline().get("marker"));
} finally {
inReadCall = false;
}
}
@Override
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
// We ensure that we're in the read call and defer the write so we can
// make sure the pipeline was reformed irrespective of the flush completing.
assertTrue(inReadCall);
writeUpgradeMessage = true;
ctx.channel().eventLoop().execute(new Runnable() {
@Override
public void run() {
ctx.write(msg, promise);
}
});
promise.addListener(future -> writeFlushed = true);
}
};
HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(httpServerCodec, factory);
EmbeddedChannel channel = new EmbeddedChannel(testInStackFrame, httpServerCodec, upgradeHandler);
String upgradeString = "GET / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
"Connection: Upgrade, HTTP2-Settings\r\n" +
"Upgrade: nextprotocol\r\n" +
"HTTP2-Settings: AAMAAABkAAQAAP__\r\n\r\n";
ByteBuf upgrade = Unpooled.copiedBuffer(upgradeString, CharsetUtil.US_ASCII);
assertFalse(channel.writeInbound(upgrade));
assertNull(channel.pipeline().get(HttpServerCodec.class));
assertNotNull(channel.pipeline().get("marker"));
channel.flushOutbound();
ByteBuf upgradeMessage = channel.readOutbound();
String expectedHttpResponse = "HTTP/1.1 101 Switching Protocols\r\n" +
"connection: upgrade\r\n" +
"upgrade: nextprotocol\r\n\r\n";
assertEquals(expectedHttpResponse, upgradeMessage.toString(CharsetUtil.US_ASCII));
assertTrue(upgradeMessage.release());
assertFalse(channel.finishAndReleaseAll());
}
Domain
Subdomains
Source
Frequently Asked Questions
What does upgradesPipelineInSameMethodInvocation() do?
upgradesPipelineInSameMethodInvocation() is a function in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpServerUpgradeHandlerTest.java.
Where is upgradesPipelineInSameMethodInvocation() defined?
upgradesPipelineInSameMethodInvocation() is defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpServerUpgradeHandlerTest.java at line 70.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free