Class NettyHttp2SelectorTest

java.lang.Object
org.apache.kafka.common.network.netty.NettyClientTestBase
org.apache.kafka.common.network.netty.NettyHttp2SelectorTest

public class NettyHttp2SelectorTest extends NettyClientTestBase
Test class to verify that NettyHttp2Selector can be used to create Kafka clients. The test currently creates and checks functionality of NetworkClient.
  • Constructor Details

    • NettyHttp2SelectorTest

      public NettyHttp2SelectorTest()
  • Method Details

    • setupNetClient

      @BeforeEach public void setupNetClient()
    • closeResources

      @AfterEach public void closeResources()
    • testApiVersionsRequest

      @Test public void testApiVersionsRequest() throws InterruptedException
      Throws:
      InterruptedException
    • testConnectMultipleTimes

      @Test public void testConnectMultipleTimes() throws InterruptedException
      Throws:
      InterruptedException
    • testPollDoesNotThrowWhenCompletedSendArrivesAfterClose

      @Test public void testPollDoesNotThrowWhenCompletedSendArrivesAfterClose() throws InterruptedException
      Integration-level reproduction of INC-11165 at the NetworkClient <-> NettyHttp2Selector boundary.

      A send completes on the netty event loop and schedules its completed-send notification onto the poll thread. The connection is then closed before that notification is drained (as a reversed cluster-link connection is when the source resets it), which clears NetworkClient's in-flight request for the node. Draining the stale notification must NOT make NetworkClient.handleCompletedSends peek a non-existent in-flight request and throw IllegalStateException("There are no in-flight requests for node ...") — the exception that, in INC-11165, escaped ClusterLinkSharedFetcherThread.doWork and deadlocked the broker.

      The cluster-link reverse path runs the same StreamChannel code via ReversableSelector; a forward connection is used here so the flow can be driven deterministically through a real NetworkClient. Regression test for KGLOBAL-9674.

      Throws:
      InterruptedException
    • testReverseStreamIsReplaced

      @Test public void testReverseStreamIsReplaced() throws IOException
      Throws:
      IOException
    • testClosingReversedStreams

      @Test public void testClosingReversedStreams() throws IOException
      Throws:
      IOException
    • testWakeupMarkerPreventsBlocking

      @Test public void testWakeupMarkerPreventsBlocking() throws InterruptedException
      Throws:
      InterruptedException
    • testPollBlocksWithoutWakeupMarkerWhenNoWork

      @Test public void testPollBlocksWithoutWakeupMarkerWhenNoWork() throws InterruptedException
      Throws:
      InterruptedException
    • testPollSwallowsExceptionFromPollTask

      @Test public void testPollSwallowsExceptionFromPollTask()
      A poll task that throws must not propagate out of NettyHttp2Selector.poll(long). Previously the whole poll-task loop was wrapped in a single try/catch that rethrew any RuntimeException, which could tear down the proxy poll thread. The fix runs each task in its own try/catch that logs and swallows the exception, matching the standard Kafka Selector, which never surfaces per-channel failures out of poll().
    • testPollTaskFailureDoesNotAbortRemainingTasks

      @Test public void testPollTaskFailureDoesNotAbortRemainingTasks()
      A single throwing poll task must not abort the remaining drained tasks. The previous tasks.forEach(Runnable::run) aborted the whole batch on the first throw; the fix isolates each task so the ones queued before and after the failing one still run.
    • testPollHandlesNullTaskOnIdleTimeout

      @Test public void testPollHandlesNullTaskOnIdleTimeout()
      When the queue is empty the blocking pollTasks.poll(timeout) returns null on idle timeout. The null guard in runPollTask preserves the prior if (op != null) semantics: poll() must return cleanly without dereferencing the null task.
    • testPollTaskErrorIsMetered

      @Test public void testPollTaskErrorIsMetered()
      A swallowed poll-task exception is surfaced via the poll-task-error meter so the otherwise-silent failure is observable. Complements testPollSwallowsExceptionFromPollTask(), which asserts the exception does not propagate.
    • testIdleTimeoutNoActiveRequest

      @Test public void testIdleTimeoutNoActiveRequest() throws Exception
      Make sure that the stream is closed when the connection times out and there is no pending request.
      Throws:
      Exception
    • testIdleTimeoutWithActiveRequest

      @Test public void testIdleTimeoutWithActiveRequest() throws Exception
      Make sure that the stream is gracefully closed when the connection times out and there is a pending request.
      Throws:
      Exception
    • testIdleTimeoutResetOnActivity

      @Test public void testIdleTimeoutResetOnActivity() throws Exception
      Make sure that receiving data resets the idle timer, preventing premature closure.
      Throws:
      Exception
    • testIdleWithMultipleConnections

      @Test public void testIdleWithMultipleConnections() throws Exception
      Verify that idle connections are closed after the idle timeout, even when multiple connections are active and were established at different times.
      Throws:
      Exception
    • testIdleWithMultipleReverseStreams

      @Test public void testIdleWithMultipleReverseStreams() throws Exception
      Verify that idle reverse streams are closed after the idle timeout, similar to regular connections.
      Throws:
      Exception