Home / Class/ SocketRstTest Class — netty Architecture

SocketRstTest Class — netty Architecture

Architecture documentation for the SocketRstTest class in SocketRstTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  49269f3a_ca3a_ac33_2872_1943eba9e232["SocketRstTest"]
  e1ae8299_c80f_9779_d7a0_9adf96b6033b["SocketRstTest.java"]
  49269f3a_ca3a_ac33_2872_1943eba9e232 -->|defined in| e1ae8299_c80f_9779_d7a0_9adf96b6033b
  d1200b2d_a1e8_24ed_5021_2bdcd5a95c09["assertRstOnCloseException()"]
  49269f3a_ca3a_ac33_2872_1943eba9e232 -->|method| d1200b2d_a1e8_24ed_5021_2bdcd5a95c09
  a68e8401_69b3_66a0_c0c5_1a2ed1b42757["testSoLingerZeroCausesOnlyRstOnClose()"]
  49269f3a_ca3a_ac33_2872_1943eba9e232 -->|method| a68e8401_69b3_66a0_c0c5_1a2ed1b42757
  207214ac_7915_0b64_51b4_e6f78865db6a["testNoRstIfSoLingerOnClose()"]
  49269f3a_ca3a_ac33_2872_1943eba9e232 -->|method| 207214ac_7915_0b64_51b4_e6f78865db6a

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketRstTest.java lines 38–161

public class SocketRstTest extends AbstractSocketTest {
    protected void assertRstOnCloseException(IOException cause, Channel clientChannel) {
        if (Locale.getDefault() == Locale.US || Locale.getDefault() == Locale.UK) {
            assertTrue(cause.getMessage().contains("reset") || cause.getMessage().contains("closed"),
                "actual message: " + cause.getMessage());
        }
    }

    @Test
    @Timeout(value = 30)
    public void testSoLingerZeroCausesOnlyRstOnClose(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
            @Override
            public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
                testSoLingerZeroCausesOnlyRstOnClose(serverBootstrap, bootstrap);
            }
        });
    }

    public void testSoLingerZeroCausesOnlyRstOnClose(ServerBootstrap sb, Bootstrap cb) throws Throwable {
        final AtomicReference<Channel> serverChannelRef = new AtomicReference<Channel>();
        final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
        final CountDownLatch latch = new CountDownLatch(1);
        final CountDownLatch latch2 = new CountDownLatch(1);
        // SO_LINGER=0 means that we must send ONLY a RST when closing (not a FIN + RST).
        sb.childOption(ChannelOption.SO_LINGER, 0);
        sb.childHandler(new ChannelInitializer<Channel>() {
            @Override
            protected void initChannel(Channel ch) throws Exception {
                serverChannelRef.compareAndSet(null, ch);
                latch.countDown();
            }
        });
        cb.handler(new ChannelInitializer<Channel>() {
            @Override
            protected void initChannel(Channel ch) throws Exception {
                ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                    @Override
                    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
                        throwableRef.compareAndSet(null, cause);
                    }

                    @Override
                    public void channelInactive(ChannelHandlerContext ctx) {
                        latch2.countDown();
                    }
                });
            }
        });
        Channel sc = sb.bind().sync().channel();
        Channel cc = cb.connect(sc.localAddress()).sync().channel();

        // Wait for the server to get setup.
        latch.await();

        // The server has SO_LINGER=0 and so it must send a RST when close is called.
        serverChannelRef.get().close();

        // Wait for the client to get channelInactive.
        latch2.await();

        // Verify the client received a RST.
        Throwable cause = throwableRef.get();
        assertTrue(cause instanceof IOException,
            "actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]");

        assertRstOnCloseException((IOException) cause, cc);
    }

    @Test
    @Timeout(value = 30)
    public void testNoRstIfSoLingerOnClose(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
            @Override
            public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
                testNoRstIfSoLingerOnClose(serverBootstrap, bootstrap);
            }
        });
    }

    public void testNoRstIfSoLingerOnClose(ServerBootstrap sb, Bootstrap cb) throws Throwable {

Frequently Asked Questions

What is the SocketRstTest class?
SocketRstTest is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketRstTest.java.
Where is SocketRstTest defined?
SocketRstTest is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketRstTest.java at line 38.

Analyze Your Own Codebase

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

Try Supermodel Free