### Question:
KeepAliveManager { void channelIdle() { assert channel.eventLoop().inEventLoop(); assert pingWriteCompletionListener != null; if (keepAliveState != null || disallowKeepAliveWithoutActiveStreams && activeChildChannels == 0) { return; } keepAliveState = KEEP_ALIVE_ACK_PENDING; channel.writeAndFlush(new DefaultHttp2PingFrame(KEEP_ALIVE_PING_CONTENT, false)) .addListener(pingWriteCompletionListener); } KeepAliveManager(final Channel channel, @Nullable final KeepAlivePolicy keepAlivePolicy);   KeepAliveManager(final Channel channel, @Nullable final KeepAlivePolicy keepAlivePolicy,
                     final Scheduler scheduler, final IdlenessDetector idlenessDetector);   }### Answer:
@Test public void keepAliveDisallowedWithNoActiveStreams() { KeepAliveManager manager = newManager(false); manager.channelIdle(); verifyNoWrite(); verifyNoScheduledTasks(); }
@Test public void keepAliveAllowedWithNoActiveStreams() { KeepAliveManager manager = newManager(true); manager.channelIdle(); verifyWrite(instanceOf(Http2PingFrame.class)); }
@Test public void keepAliveWithActiveStreams() { KeepAliveManager manager = newManager(false); addActiveStream(manager); manager.channelIdle(); verifyWrite(instanceOf(Http2PingFrame.class)); }
@Test public void keepAliveMissingPingAck() { KeepAliveManager manager = newManager(false); addActiveStream(manager); manager.channelIdle(); verifyWrite(instanceOf(Http2PingFrame.class)); verifyChannelCloseOnMissingPingAck(verifyPingAckTimeoutScheduled()); }
@Test public void gracefulClosePendingPingsCloseConnection() throws Exception { KeepAliveManager manager = newManager(false); addActiveStream(manager); Http2PingFrame pingFrame = initiateGracefulCloseVerifyGoAwayAndPing(manager); sendGracefulClosePingAckAndVerifySecondGoAway(manager, pingFrame); assertThat("Channel closed.", channel.isOpen(), is(true)); manager.channelIdle(); verifyWrite(instanceOf(Http2PingFrame.class)); verifyChannelCloseOnMissingPingAck(verifyPingAckTimeoutScheduled()); }