Home / Function/ listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() — netty Function Reference

listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() — netty Function Reference

Architecture documentation for the listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() function in Http2ConnectionRoundtripTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2021a1f6_d36a_c1bc_2c82_7bd08f19589c["listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection()"]
  0d6189e8_c033_39ff_d087_9019351440fe["Http2ConnectionRoundtripTest"]
  2021a1f6_d36a_c1bc_2c82_7bd08f19589c -->|defined in| 0d6189e8_c033_39ff_d087_9019351440fe
  1dd685b8_9b56_5b35_70ca_7f2bf9016254["bootstrapEnv()"]
  2021a1f6_d36a_c1bc_2c82_7bd08f19589c -->|calls| 1dd685b8_9b56_5b35_70ca_7f2bf9016254
  f8a98f5a_5b4f_5e46_24a0_b03b1f68c64a["setClientGracefulShutdownTime()"]
  2021a1f6_d36a_c1bc_2c82_7bd08f19589c -->|calls| f8a98f5a_5b4f_5e46_24a0_b03b1f68c64a
  da672232_873c_287f_a7ac_aff79739090a["setServerGracefulShutdownTime()"]
  2021a1f6_d36a_c1bc_2c82_7bd08f19589c -->|calls| da672232_873c_287f_a7ac_aff79739090a
  style 2021a1f6_d36a_c1bc_2c82_7bd08f19589c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java lines 915–991

    @Test
    public void listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() throws Exception {
        final AtomicReference<Http2Stream.State> clientStream3State = new AtomicReference<Http2Stream.State>();
        final CountDownLatch clientGoAwayLatch = new CountDownLatch(1);
        doAnswer(new Answer<Void>() {
            @Override
            public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
                clientStream3State.set(http2Client.connection().stream(3).state());
                clientGoAwayLatch.countDown();
                return null;
            }
        }).when(clientListener).onGoAwayRead(any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class));

        bootstrapEnv(1, 1, 3, 1, 1);

        // We want both sides to do graceful shutdown during the test.
        setClientGracefulShutdownTime(10000);
        setServerGracefulShutdownTime(10000);

        // Create a single stream by sending a HEADERS frame to the server.
        final Http2Headers headers = dummyHeaders();
        runInChannel(clientChannel, new Http2Runnable() {
            @Override
            public void run() throws Http2Exception {
                http2Client.encoder().writeHeaders(ctx(), 1, headers, 0, (short) 16, false, 0,
                    false, newPromise());
                http2Client.encoder().writeHeaders(ctx(), 3, headers, 0, (short) 16, false, 0,
                    false, newPromise());
                http2Client.flush(ctx());
            }
        });

        assertTrue(serverSettingsAckLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS));

        // Server has received the headers, so the stream is open
        assertTrue(requestLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS));

        runInChannel(serverChannel, new Http2Runnable() {
            @Override
            public void run() throws Http2Exception {
                http2Server.encoder().writeGoAway(serverCtx(), 1, NO_ERROR.code(), EMPTY_BUFFER, serverNewPromise());
                http2Server.flush(serverCtx());
            }
        });

        // wait for the client to receive the GO_AWAY.
        assertTrue(clientGoAwayLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS));
        verify(clientListener).onGoAwayRead(any(ChannelHandlerContext.class), eq(1), eq(NO_ERROR.code()),
            any(ByteBuf.class));
        assertEquals(Http2Stream.State.OPEN, clientStream3State.get());

        // Make sure that stream 3 has been closed which is true if it's gone.
        final CountDownLatch probeStreamCount = new CountDownLatch(1);
        final AtomicBoolean stream3Exists = new AtomicBoolean();
        final AtomicInteger streamCount = new AtomicInteger();
        runInChannel(this.clientChannel, new Http2Runnable() {
            @Override
            public void run() throws Http2Exception {
                stream3Exists.set(http2Client.connection().stream(3) != null);
                streamCount.set(http2Client.connection().numActiveStreams());
                probeStreamCount.countDown();
            }
        });
        // The stream should be closed right after
        assertTrue(probeStreamCount.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS));
        assertEquals(1, streamCount.get());
        assertFalse(stream3Exists.get());

        // Wait for the server to receive a GO_AWAY, but this is expected to timeout!
        assertFalse(goAwayLatch.await(1, SECONDS));
        verify(serverListener, never()).onGoAwayRead(any(ChannelHandlerContext.class), anyInt(), anyLong(),
            any(ByteBuf.class));

        // Shutdown shouldn't wait for the server to close streams
        setClientGracefulShutdownTime(0);
        setServerGracefulShutdownTime(0);
    }

Domain

Subdomains

Frequently Asked Questions

What does listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() do?
listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() is a function in the netty codebase, defined in codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java.
Where is listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() defined?
listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() is defined in codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java at line 915.
What does listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() call?
listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() calls 3 function(s): bootstrapEnv, setClientGracefulShutdownTime, setServerGracefulShutdownTime.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free