Home / Class/ SocketChannelNotYetConnectedTest Class — netty Architecture

SocketChannelNotYetConnectedTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f870305c_1df5_e1b8_f8dd_b59859696da0["SocketChannelNotYetConnectedTest"]
  3ecf93d7_16a2_9ab1_35bf_ec44b586892b["SocketChannelNotYetConnectedTest.java"]
  f870305c_1df5_e1b8_f8dd_b59859696da0 -->|defined in| 3ecf93d7_16a2_9ab1_35bf_ec44b586892b
  fb69054a_3ddd_d8df_fd57_3157f28a086f["testShutdownNotYetConnected()"]
  f870305c_1df5_e1b8_f8dd_b59859696da0 -->|method| fb69054a_3ddd_d8df_fd57_3157f28a086f
  1de65f73_5e60_9f27_4349_163e69130776["checkThrowable()"]
  f870305c_1df5_e1b8_f8dd_b59859696da0 -->|method| 1de65f73_5e60_9f27_4349_163e69130776
  3511d9f4_e083_f8e7_f0f0_5a4f878d632e["readMustBePendingUntilChannelIsActive()"]
  f870305c_1df5_e1b8_f8dd_b59859696da0 -->|method| 3511d9f4_e083_f8e7_f0f0_5a4f878d632e

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketChannelNotYetConnectedTest.java lines 44–124

public class SocketChannelNotYetConnectedTest extends AbstractClientSocketTest {
    @Test
    @Timeout(30)
    public void testShutdownNotYetConnected(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<Bootstrap>() {
            @Override
            public void run(Bootstrap bootstrap) throws Throwable {
                testShutdownNotYetConnected(bootstrap);
            }
        });
    }

    public void testShutdownNotYetConnected(Bootstrap cb) throws Throwable {
        SocketChannel ch = (SocketChannel) cb.handler(new ChannelInboundHandlerAdapter())
                .bind(newSocketAddress()).syncUninterruptibly().channel();
        try {
            try {
                ch.shutdownInput().syncUninterruptibly();
                fail();
            } catch (Throwable cause) {
                checkThrowable(cause);
            }

            try {
                ch.shutdownOutput().syncUninterruptibly();
                fail();
            } catch (Throwable cause) {
                checkThrowable(cause);
            }
        } finally {
            ch.close().syncUninterruptibly();
        }
    }

    private static void checkThrowable(Throwable cause) throws Throwable {
        // Depending on OIO / NIO both are ok
        if (!(cause instanceof NotYetConnectedException) && !(cause instanceof SocketException)) {
            throw cause;
        }
    }

    @Test
    @Timeout(30)
    public void readMustBePendingUntilChannelIsActive(TestInfo info) throws Throwable {
        run(info, new Runner<Bootstrap>() {
            @Override
            public void run(Bootstrap bootstrap) throws Throwable {
                EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
                ServerBootstrap sb = new ServerBootstrap().group(group);
                Channel serverChannel = sb.childHandler(new ChannelInboundHandlerAdapter() {
                    @Override
                    public void channelActive(ChannelHandlerContext ctx) throws Exception {
                        ctx.writeAndFlush(Unpooled.copyInt(42));
                    }
                }).channel(NioServerSocketChannel.class).bind(0).sync().channel();

                final CountDownLatch readLatch = new CountDownLatch(1);
                bootstrap.handler(new ByteToMessageDecoder() {
                    @Override
                    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
                        assertFalse(ctx.channel().isActive());
                        ctx.read();
                    }

                    @Override
                    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
                        assertThat(in.readableBytes()).isLessThanOrEqualTo(Integer.BYTES);
                        if (in.readableBytes() == Integer.BYTES) {
                            assertThat(in.readInt()).isEqualTo(42);
                            readLatch.countDown();
                        }
                    }
                });
                bootstrap.connect(serverChannel.localAddress()).sync();

                readLatch.await();
                group.shutdownGracefully().await();
            }
        });
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free