Class NettyHttp2SelectorStreamChannelTest

java.lang.Object
org.apache.kafka.common.network.netty.NettyHttp2SelectorStreamChannelTest

public class NettyHttp2SelectorStreamChannelTest extends Object
Test class to test methods in the NettyHttp2Selector.StreamChannel class.
  • 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

      @BeforeEach public void serializeResponse() throws IOException
      Serialize a response that can then be processed.
      Throws:
      IOException
    • testHandleDataEmptyBuffer

      @Test public void testHandleDataEmptyBuffer()
      Test NettyStream.StreamHandler.handleData(ByteBuf) method to make sure it can handle empty buffer.
    • testHandleDataPartialResponseBuffer

      @ParameterizedTest @ValueSource(booleans={true,false}) public void testHandleDataPartialResponseBuffer(boolean addEmptyBuffer)
      Test NettyStream.StreamHandler.handleData(ByteBuf) method to make sure it can handle buffers with partial response data.
    • testHandleDataCompleteResponseBuffer

      @Test public void testHandleDataCompleteResponseBuffer()
      Test NettyStream.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

      @Test public void testStartSend() throws InterruptedException
      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 when NettyHttp2Selector.StreamChannel.startSend(NetworkSend) is invoked when the stream is in closing state.
      Throws:
      InterruptedException
      ExecutionException
    • 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 of testCompletedSendDroppedWhenStreamClosedBeforePoll(). 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

      @Test public void testErrorOnSendClosesStream() throws Exception
      Throw exception when processing send and check if that closes the stream
      Throws:
      Exception
    • 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 public void testGracefulDisconnectWithPendingReceive() throws InterruptedException
      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 public void testNotifyOnlyDisconnectWithPendingReceive() throws InterruptedException
      Test that for NOTIFY_ONLY mode, stream is closed immediately even with pending receives.
      Throws:
      InterruptedException
    • testGracefulDisconnectFullFlow

      @Test public void testGracefulDisconnectFullFlow() throws InterruptedException
      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 public void testGracefulDisconnectThenSendCausesImmediateClose() throws InterruptedException
      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 public void testSelectorDisconnectMethod() throws InterruptedException
      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 public void testMultipleDisconnectCalls() throws InterruptedException
      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 the stale-completion-dropped-send meter is incremented and no completed send is surfaced.
    • testStaleCompletionDroppedReceiveMetric

      @Test public void testStaleCompletionDroppedReceiveMetric()
      Receive-side counterpart of testStaleCompletionDroppedSendMetric(): assert the stale-completion-dropped-receive meter 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; the inflight-underflow meter must be incremented.