Home / Function/ pauseResumeTest() — netty Function Reference

pauseResumeTest() — netty Function Reference

Architecture documentation for the pauseResumeTest() function in PcapWriteHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  771aee7b_e62b_042d_2acf_2737cf101a99["pauseResumeTest()"]
  e9f4993c_4935_9405_4fab_0bbc9030a673["PcapWriteHandlerTest"]
  771aee7b_e62b_042d_2acf_2737cf101a99 -->|defined in| e9f4993c_4935_9405_4fab_0bbc9030a673
  201e7e9e_c23c_b328_ecb1_117026fc1c03["InetSocketAddress()"]
  771aee7b_e62b_042d_2acf_2737cf101a99 -->|calls| 201e7e9e_c23c_b328_ecb1_117026fc1c03
  style 771aee7b_e62b_042d_2acf_2737cf101a99 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java lines 1037–1097

    @Test
    public void pauseResumeTest() throws Exception {
        final byte[] payload = "Meow".getBytes();
        final InetSocketAddress serverAddr = new InetSocketAddress("1.1.1.1", 1234);
        final InetSocketAddress clientAddr = new InetSocketAddress("2.2.2.2", 3456);

        DiscardingStatsOutputStream discardingStatsOutputStream = new DiscardingStatsOutputStream();
        PcapWriteHandler pcapWriteHandler = PcapWriteHandler.builder()
                                                            .forceTcpChannel(serverAddr, clientAddr, true)
                                                            .build(discardingStatsOutputStream);

        // Verify that no writes have been called yet.
        assertEquals(0, discardingStatsOutputStream.writesCalled());

        // Create a new 'EmbeddedChannel' and add the 'PcapWriteHandler'
        EmbeddedChannel embeddedChannel = new EmbeddedChannel(pcapWriteHandler);

        for (int i = 0; i < 10; i++) {
            assertTrue(embeddedChannel.writeInbound(Unpooled.wrappedBuffer(payload)));
        }

        // Since we have written 10 times, we should have a value greater than 0.
        // We can't say it will be 10 exactly because there will be pcap headers also.
        final int initialWritesCalled = discardingStatsOutputStream.writesCalled();
        assertThat(initialWritesCalled).isGreaterThan(0);

        // Pause the Pcap
        pcapWriteHandler.pause();
        assertEquals(State.PAUSED, pcapWriteHandler.state());
        assertFalse(pcapWriteHandler.isWriting());

        // Write 100 times. No writes should be called in OutputStream.
        for (int i = 0; i < 100; i++) {
            assertTrue(embeddedChannel.writeInbound(Unpooled.wrappedBuffer(payload)));
        }

        // Current stats and previous stats should be same.
        assertEquals(initialWritesCalled, discardingStatsOutputStream.writesCalled());

        // Let's resume the Pcap now.
        pcapWriteHandler.resume();
        assertEquals(State.WRITING, pcapWriteHandler.state());
        assertTrue(pcapWriteHandler.isWriting());

        // Write 100 times. Writes should be called in OutputStream now.
        for (int i = 0; i < 100; i++) {
            assertTrue(embeddedChannel.writeInbound(Unpooled.wrappedBuffer(payload)));
        }

        // Verify we have written more than before.
        assertThat(discardingStatsOutputStream.writesCalled()).isGreaterThan(initialWritesCalled);

        // Close PcapWriteHandler again. This should be a no-op.
        pcapWriteHandler.close();

        // State should still be CLOSED. No change.
        assertEquals(State.CLOSED, pcapWriteHandler.state());

        // Close the 'EmbeddedChannel'.
        assertTrue(embeddedChannel.finishAndReleaseAll());
    }

Domain

Subdomains

Frequently Asked Questions

What does pauseResumeTest() do?
pauseResumeTest() is a function in the netty codebase, defined in handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java.
Where is pauseResumeTest() defined?
pauseResumeTest() is defined in handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java at line 1037.
What does pauseResumeTest() call?
pauseResumeTest() calls 1 function(s): InetSocketAddress.

Analyze Your Own Codebase

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

Try Supermodel Free