|
Expand Up
|
@@ -992,6 +992,103 @@ public void gracefulShutdownIndefiniteTimeoutTest() throws Exception { |
|
|
verify(executor, never()).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class)); |
|
|
} |
|
|
|
|
|
@ParameterizedTest |
|
|
@ValueSource(longs = { 30000, -1 }) |
|
|
public void gracefulShutdownCompletesWhenGoAwayClosesLastStream(long gracefulShutdownTimeoutMillis) { |
|
|
Http2ConnectionHandler serverHandler = new Http2ConnectionHandlerBuilder() |
|
|
.server(true).frameListener(new Http2FrameAdapter()).build(); |
|
|
EmbeddedChannel server = new EmbeddedChannel(serverHandler); |
|
|
EmbeddedChannel client = newClientChannel(gracefulShutdownTimeoutMillis); |
|
|
Http2ConnectionHandler clientHandler = client.pipeline().get(Http2ConnectionHandler.class); |
|
|
try { |
|
|
exchangeFrames(client, server); |
|
|
writeHeadersOnStream3(clientHandler, client); |
|
|
|
|
|
// Close via the pipeline: EmbeddedChannel.close() would cancel the graceful shutdown timeout task. |
|
|
ChannelFuture closeFuture = client.pipeline().close(); |
|
|
assertFalse(closeFuture.isDone()); |
|
|
|
|
|
// The server shuts down before it has seen stream 3 and answers with a GOAWAY that does not include it. |
|
|
client.releaseOutbound(); |
|
|
serverHandler.goAway(server.pipeline().firstContext(), 0, Http2Error.NO_ERROR.code(), |
|
|
Unpooled.EMPTY_BUFFER, server.newPromise()); |
|
|
server.flush(); |
|
|
exchangeFrames(server, client); |
|
|
client.runPendingTasks(); |
|
|
|
|
|
assertEquals(0, clientHandler.connection().numActiveStreams()); |
|
|
assertTrue(closeFuture.isSuccess(), "close() must complete once the GOAWAY closed the last stream"); |
|
|
assertFalse(client.isOpen()); |
|
|
} finally { |
|
|
client.finishAndReleaseAll(); |
|
|
server.finishAndReleaseAll(); |
|
|
} |
|
|
} |
|
|
|
|
|
@ParameterizedTest |
|
|
@ValueSource(longs = { 30000, -1 }) |
|
|
public void gracefulShutdownCompletesWhenChannelBecomesInactive(long gracefulShutdownTimeoutMillis) { |
|
|
Http2ConnectionHandler serverHandler = new Http2ConnectionHandlerBuilder() |
|
|
.server(true).frameListener(new Http2FrameAdapter()).build(); |
|
|
EmbeddedChannel server = new EmbeddedChannel(serverHandler); |
|
|
EmbeddedChannel client = newClientChannel(gracefulShutdownTimeoutMillis); |
|
|
Http2ConnectionHandler clientHandler = client.pipeline().get(Http2ConnectionHandler.class); |
|
|
try { |
|
|
exchangeFrames(client, server); |
|
|
writeHeadersOnStream3(clientHandler, client); |
|
|
|
|
|
// Close via the pipeline: EmbeddedChannel.close() would cancel the graceful shutdown timeout task. |
|
|
ChannelFuture closeFuture = client.pipeline().close(); |
|
|
assertFalse(closeFuture.isDone()); |
|
|
|
|
|
// The connection is lost while the graceful shutdown waits for stream 3. |
|
|
client.unsafe().close(client.voidPromise()); |
|
|
client.runPendingTasks(); |
|
|
|
|
|
assertFalse(client.isOpen()); |
|
|
assertEquals(0, clientHandler.connection().numActiveStreams()); |
|
|
assertTrue(closeFuture.isSuccess(), "close() must complete once the channel is closed"); |
|
|
} finally { |
|
|
client.finishAndReleaseAll(); |
|
|
server.finishAndReleaseAll(); |
|
|
} |
|
|
} |
|
|
|
|
|
private static EmbeddedChannel newClientChannel(long gracefulShutdownTimeoutMillis) { |
|
|
EmbeddedChannel client = new EmbeddedChannel(new Http2ConnectionHandlerBuilder() |
|
|
.server(false).frameListener(new Http2FrameAdapter()) |
|
|
.gracefulShutdownTimeoutMillis(gracefulShutdownTimeoutMillis).build()); |
|
|
// The graceful shutdown timeout must not elapse during the test. |
|
|
client.freezeTime(); |
|
|
return client; |
|
|
} |
|
|
|
|
|
private static void writeHeadersOnStream3(Http2ConnectionHandler clientHandler, EmbeddedChannel client) { |
|
|
ChannelHandlerContext ctx = client.pipeline().context(clientHandler); |
|
|
clientHandler.encoder().writeHeaders(ctx, 3, |
|
|
new DefaultHttp2Headers().method("GET").path("/").scheme("http").authority("netty.io"), |
|
|
0, false, ctx.newPromise()); |
|
|
client.flush(); |
|
|
assertEquals(1, clientHandler.connection().numActiveStreams()); |
|
|
} |
|
|
|
|
|
private static void exchangeFrames(EmbeddedChannel from, EmbeddedChannel to) { |
|
|
for (int i = 0; i < 5; i++) { |
|
|
transferFrames(from, to); |
|
|
transferFrames(to, from); |
|
|
} |
|
|
} |
|
|
|
|
|
private static void transferFrames(EmbeddedChannel from, EmbeddedChannel to) { |
|
|
for (Object msg; (msg = from.readOutbound()) != null;) { |
|
|
if (to.isOpen()) { |
|
|
to.writeInbound(msg); |
|
|
} else { |
|
|
ReferenceCountUtil.release(msg); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
@Test |
|
|
public void writeMultipleRstFramesForSameStream() throws Exception { |
|
|
handler = newHandler(); |
|
Expand Down
|
|