Home / Class/ SocketConnectionAttemptTest Class — netty Architecture

SocketConnectionAttemptTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  c0d6b551_b352_95d7_da6e_f24e2cd37df2["SocketConnectionAttemptTest"]
  68b222bb_77f0_1868_63ff_f4d46042ff4e["SocketConnectionAttemptTest.java"]
  c0d6b551_b352_95d7_da6e_f24e2cd37df2 -->|defined in| 68b222bb_77f0_1868_63ff_f4d46042ff4e
  7dcd4c17_b23f_b45e_b3f9_8e051161da06["testConnectTimeout()"]
  c0d6b551_b352_95d7_da6e_f24e2cd37df2 -->|method| 7dcd4c17_b23f_b45e_b3f9_8e051161da06
  f0e1bcb2_7554_4ab6_4eab_9086c4ac2b25["testConnectRefused()"]
  c0d6b551_b352_95d7_da6e_f24e2cd37df2 -->|method| f0e1bcb2_7554_4ab6_4eab_9086c4ac2b25
  055ea41d_c704_d771_8df3_59063587df6a["testConnectRefusedHalfClosure()"]
  c0d6b551_b352_95d7_da6e_f24e2cd37df2 -->|method| 055ea41d_c704_d771_8df3_59063587df6a
  597a5dcd_f95f_ea5d_b03c_ef8ddd345dda["testConnectRefused0()"]
  c0d6b551_b352_95d7_da6e_f24e2cd37df2 -->|method| 597a5dcd_f95f_ea5d_b03c_ef8ddd345dda
  faa1e098_048a_7a75_e34b_9fc3b12d01ab["testConnectCancellation()"]
  c0d6b551_b352_95d7_da6e_f24e2cd37df2 -->|method| faa1e098_048a_7a75_e34b_9fc3b12d01ab
  c908e3c2_865b_b453_e224_f19cf9891338["isConnectCancellationSupported()"]
  c0d6b551_b352_95d7_da6e_f24e2cd37df2 -->|method| c908e3c2_865b_b453_e224_f19cf9891338

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketConnectionAttemptTest.java lines 50–187

public class SocketConnectionAttemptTest extends AbstractClientSocketTest {

    @Test
    @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
    public void testConnectTimeout(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<Bootstrap>() {
            @Override
            public void run(Bootstrap bootstrap) throws Throwable {
                testConnectTimeout(bootstrap);
            }
        });
    }

    public void testConnectTimeout(Bootstrap cb) throws Throwable {
        cb.handler(new TestHandler()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000);
        ChannelFuture future = cb.connect(BAD_HOST, BAD_PORT);
        try {
            assertTrue(future.await(3000));
        } finally {
            future.channel().close();
        }
    }

    @Test
    @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
    public void testConnectRefused(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<Bootstrap>() {
            @Override
            public void run(Bootstrap bootstrap) throws Throwable {
                testConnectRefused(bootstrap);
            }
        });
    }

    public void testConnectRefused(Bootstrap cb) throws Throwable {
        testConnectRefused0(cb, false);
    }

    @Test
    @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
    public void testConnectRefusedHalfClosure(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<Bootstrap>() {
            @Override
            public void run(Bootstrap bootstrap) throws Throwable {
                testConnectRefusedHalfClosure(bootstrap);
            }
        });
    }

    public void testConnectRefusedHalfClosure(Bootstrap cb) throws Throwable {
        testConnectRefused0(cb, true);
    }

    private static void testConnectRefused0(Bootstrap cb, boolean halfClosure) throws Throwable {
        final Promise<Error> errorPromise = GlobalEventExecutor.INSTANCE.newPromise();
        ChannelHandler handler = new ChannelInboundHandlerAdapter() {
            @Override
            public void channelActive(ChannelHandlerContext ctx) throws Exception {
                errorPromise.setFailure(new AssertionError("should have never been called"));
            }
        };

        cb.handler(handler);
        cb.option(ChannelOption.ALLOW_HALF_CLOSURE, halfClosure);
        ChannelFuture future = cb.connect(NetUtil.LOCALHOST, UNASSIGNED_PORT).awaitUninterruptibly();
        assertInstanceOf(ConnectException.class, future.cause());
        assertNull(errorPromise.cause());
    }

    @Test
    public void testConnectCancellation(TestInfo testInfo) throws Throwable {
        // Check if the test can be executed or should be skipped because of no network/internet connection
        // See https://github.com/netty/netty/issues/1474
        boolean badHostTimedOut = true;
        Socket socket = new Socket();
        try {
            SocketUtils.connect(socket, SocketUtils.socketAddress(BAD_HOST, BAD_PORT), 10);
        } catch (ConnectException e) {
            badHostTimedOut = false;
            // is thrown for no route to host when using Socket connect
        } catch (Exception e) {

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free