Class NettyHttp2SelectorStreamChannelTest
java.lang.Object
org.apache.kafka.common.network.netty.NettyHttp2SelectorStreamChannelTest
Test class to test methods in the
NettyHttp2Selector.StreamChannel class.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclean()voidSerialize a response that can then be processed.voidsetup()static voidstart()static voidstop()voidReceive-side counterpart oftestCompletedSendDroppedWhenStreamClosedBeforePoll().voidA send completes on the event loop and schedules its completed-send notification onto the poll thread.voidTest disconnect on non-existent stream is a no-op.voidtestDisconnectNoPendingReceive(org.apache.kafka.common.network.Selector.CloseMode closeMode) voidTest disconnect when nettyStream is null (stream not yet initialized).voidThrow exception when processing send and check if that closes the streamvoidTest the full GRACEFUL disconnect flow: disconnect with pending responses, receive response, then verify stream is closed and added to disconnected list.voidTest that GRACEFUL disconnect with pending receives transitions to CLOSING state, and a subsequent send attempt causes immediate close with FAILED_SEND.voidTest that if there is a pending receive the stream is not closed for GRACEFUL mode.voidvoidvoidvoidTestNettyStream.StreamHandler.handleData(ByteBuf)method to make sure it can handle buffer with complete response.voidTestNettyStream.StreamHandler.handleData(ByteBuf)method to make sure it can handle empty buffer.voidtestHandleDataPartialResponseBuffer(boolean addEmptyBuffer) TestNettyStream.StreamHandler.handleData(ByteBuf)method to make sure it can handle buffers with partial response data.voidvoidTest that handleException closes the stream and adds to disconnected list.voidvoidhandleReadyForSend() can be invoked by the writability-change handler after the stream has started closing.voidvoidIf a receive completes with no matching prior send, the expected-response count goes negative; theinflight-underflowmeter must be incremented.voidvoidTest isChannelReady returns false for streams in CLOSED state.voidTest isChannelReady returns false for streams in CLOSING state.voidTest that calling disconnect multiple times is safe (idempotent).voidTest that for NOTIFY_ONLY mode, stream is closed immediately even with pending receives.voidTest that numExpectingResponses is correctly tracked through send/receive cycle.voidTest disconnect via the NettyHttp2Selector.disconnect method.voidReceive-side counterpart oftestStaleCompletionDroppedSendMetric(): assert thestale-completion-dropped-receivemeter is incremented and no completed receive is surfaced.voidA completed send whose stream is swapped/removed before the deferred poll-thread task runs is dropped (the INC-11165 survival path).voidvoidtestStartSendInClosingState(org.apache.kafka.common.network.netty.State streamState) Test behavior whenNettyHttp2Selector.StreamChannel.startSend(NetworkSend)is invoked when the stream is in closing state.voidstreamsCount()reflects the current size of the streams map: it grows as streams are registered and shrinks as they are closed.
-
Constructor Details
-
NettyHttp2SelectorStreamChannelTest
public NettyHttp2SelectorStreamChannelTest()
-
-
Method Details
-
start
@BeforeAll public static void start() -
setup
@BeforeEach public void setup() -
clean
@AfterEach public void clean() -
stop
@AfterAll public static void stop() -
serializeResponse
Serialize a response that can then be processed.- Throws:
IOException
-
testHandleDataEmptyBuffer
@Test public void testHandleDataEmptyBuffer()TestNettyStream.StreamHandler.handleData(ByteBuf)method to make sure it can handle empty buffer. -
testHandleDataPartialResponseBuffer
@ParameterizedTest @ValueSource(booleans={true,false}) public void testHandleDataPartialResponseBuffer(boolean addEmptyBuffer) TestNettyStream.StreamHandler.handleData(ByteBuf)method to make sure it can handle buffers with partial response data. -
testHandleDataCompleteResponseBuffer
@Test public void testHandleDataCompleteResponseBuffer()TestNettyStream.StreamHandler.handleData(ByteBuf)method to make sure it can handle buffer with complete response. -
testInitialized
@Test public void testInitialized() -
testHandleClose
@Test public void testHandleClose() -
testHandleException
@Test public void testHandleException() -
testStartSend
- Throws:
InterruptedException
-
testStartSendInClosingState
@ParameterizedTest @EnumSource(value=org.apache.kafka.common.network.netty.State.class, names={"CLOSING","CLOSED"}) public void testStartSendInClosingState(org.apache.kafka.common.network.netty.State streamState) throws InterruptedException, ExecutionException Test behavior whenNettyHttp2Selector.StreamChannel.startSend(NetworkSend)is invoked when the stream is in closing state. -
testHandleReadyForSendNoPendingSend
@Test public void testHandleReadyForSendNoPendingSend() -
testHandleReadyForSend
@Test public void testHandleReadyForSend() -
testHandleReadyForSendIgnoredWhenStreamNotOpen
@Test public void testHandleReadyForSendIgnoredWhenStreamNotOpen()handleReadyForSend() can be invoked by the writability-change handler after the stream has started closing. The send must not be processed on a non-open stream: it should not complete, bump numExpectingResponses, or schedule a completed-send task. -
testCompletedSendDroppedWhenStreamClosedBeforePoll
@Test public void testCompletedSendDroppedWhenStreamClosedBeforePoll()A send completes on the event loop and schedules its completed-send notification onto the poll thread. If the connection is closed before that notification is drained, the stale send must NOT be surfaced: NetworkClient has already cleared its in-flight request for the node (via disconnected()), so reporting the send would trip NetworkClient.handleCompletedSends with "There are no in-flight requests for node ...". Regression test for KGLOBAL-9674 (INC-11165). -
testCompletedReceiveDroppedWhenStreamClosedBeforePoll
@Test public void testCompletedReceiveDroppedWhenStreamClosedBeforePoll()Receive-side counterpart oftestCompletedSendDroppedWhenStreamClosedBeforePoll(). A full response is received on the event loop and schedules its completed-receive notification onto the poll thread. If the connection is closed before that notification is drained, the stale receive must NOT be surfaced: NetworkClient has already cleared its in-flight request for the node, so reporting the receive would trip NetworkClient.handleCompletedReceives.completeNext() with "There are no in-flight requests for node ...". Regression test for KGLOBAL-9674 (INC-11165). -
testErrorOnSendClosesStream
-
testHandleDataClosesStreamInClosingState
@Test public void testHandleDataClosesStreamInClosingState() -
testHandleCloseDiscardDisconnect
@Test public void testHandleCloseDiscardDisconnect() -
testDisconnectNoPendingReceive
@ParameterizedTest @EnumSource(value=org.apache.kafka.common.network.Selector.CloseMode.class, names={"GRACEFUL","NOTIFY_ONLY"}) public void testDisconnectNoPendingReceive(org.apache.kafka.common.network.Selector.CloseMode closeMode) throws InterruptedException - Throws:
InterruptedException
-
testGracefulDisconnectWithPendingReceive
Test that if there is a pending receive the stream is not closed for GRACEFUL mode. Only when the receive is complete, we close the stream.- Throws:
InterruptedException
-
testNotifyOnlyDisconnectWithPendingReceive
Test that for NOTIFY_ONLY mode, stream is closed immediately even with pending receives.- Throws:
InterruptedException
-
testGracefulDisconnectFullFlow
Test the full GRACEFUL disconnect flow: disconnect with pending responses, receive response, then verify stream is closed and added to disconnected list.- Throws:
InterruptedException
-
testGracefulDisconnectThenSendCausesImmediateClose
Test that GRACEFUL disconnect with pending receives transitions to CLOSING state, and a subsequent send attempt causes immediate close with FAILED_SEND.- Throws:
InterruptedException
-
testDisconnectWhenStreamNotInitialized
@Test public void testDisconnectWhenStreamNotInitialized()Test disconnect when nettyStream is null (stream not yet initialized). For uninitialized streams, disconnect schedules close directly on poll thread. -
testIsChannelReadyReturnsFalseForClosingStream
@Test public void testIsChannelReadyReturnsFalseForClosingStream()Test isChannelReady returns false for streams in CLOSING state. -
testIsChannelReadyReturnsFalseForClosedStream
@Test public void testIsChannelReadyReturnsFalseForClosedStream()Test isChannelReady returns false for streams in CLOSED state. -
testSelectorDisconnectMethod
Test disconnect via the NettyHttp2Selector.disconnect method.- Throws:
InterruptedException
-
testDisconnectNonExistentStream
@Test public void testDisconnectNonExistentStream()Test disconnect on non-existent stream is a no-op. -
testMultipleDisconnectCalls
Test that calling disconnect multiple times is safe (idempotent).- Throws:
InterruptedException
-
testHandleExceptionClosesStream
@Test public void testHandleExceptionClosesStream()Test that handleException closes the stream and adds to disconnected list. -
testNumExpectingResponsesTracking
@Test public void testNumExpectingResponsesTracking()Test that numExpectingResponses is correctly tracked through send/receive cycle. -
testStaleCompletionDroppedSendMetric
@Test public void testStaleCompletionDroppedSendMetric()A completed send whose stream is swapped/removed before the deferred poll-thread task runs is dropped (the INC-11165 survival path). Assert thestale-completion-dropped-sendmeter is incremented and no completed send is surfaced. -
testStaleCompletionDroppedReceiveMetric
@Test public void testStaleCompletionDroppedReceiveMetric()Receive-side counterpart oftestStaleCompletionDroppedSendMetric(): assert thestale-completion-dropped-receivemeter is incremented and no completed receive is surfaced. -
testStreamsCount
@Test public void testStreamsCount()streamsCount()reflects the current size of the streams map: it grows as streams are registered and shrinks as they are closed. The per-client cluster-link stream-count gauge (registered in ClusterLinkNetworkClient) reads this value. -
testInflightUnderflowMetric
@Test public void testInflightUnderflowMetric()If a receive completes with no matching prior send, the expected-response count goes negative; theinflight-underflowmeter must be incremented.
-