Home / Class/ SocketCancelWriteTest Class — netty Architecture

SocketCancelWriteTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  9d02f309_eb53_3406_9e0a_789662ca3c96["SocketCancelWriteTest"]
  26f938ac_c9e2_e435_62bb_812a46f54bb3["SocketCancelWriteTest.java"]
  9d02f309_eb53_3406_9e0a_789662ca3c96 -->|defined in| 26f938ac_c9e2_e435_62bb_812a46f54bb3
  1f19ca6c_1e34_b7c3_792c_7882b2c7045d["testCancelWrite()"]
  9d02f309_eb53_3406_9e0a_789662ca3c96 -->|method| 1f19ca6c_1e34_b7c3_792c_7882b2c7045d

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketCancelWriteTest.java lines 37–127

public class SocketCancelWriteTest extends AbstractSocketTest {

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

    public void testCancelWrite(ServerBootstrap sb, Bootstrap cb) throws Throwable {
        final TestHandler sh = new TestHandler();
        final TestHandler ch = new TestHandler();
        final ByteBuf a = Unpooled.buffer().writeByte('a');
        final ByteBuf b = Unpooled.buffer().writeByte('b');
        final ByteBuf c = Unpooled.buffer().writeByte('c');
        final ByteBuf d = Unpooled.buffer().writeByte('d');
        final ByteBuf e = Unpooled.buffer().writeByte('e');

        cb.handler(ch);
        sb.childHandler(sh);

        Channel sc = sb.bind().sync().channel();
        Channel cc = cb.connect(sc.localAddress()).sync().channel();

        ChannelFuture f = cc.write(a);
        assertTrue(f.cancel(false));
        cc.writeAndFlush(b);
        cc.write(c);
        ChannelFuture f2 = cc.write(d);
        assertTrue(f2.cancel(false));
        cc.writeAndFlush(e);

        while (sh.counter < 3) {
            if (sh.exception.get() != null) {
                break;
            }
            if (ch.exception.get() != null) {
                break;
            }
            Thread.sleep(50);
        }
        sh.channel.close().sync();
        ch.channel.close().sync();
        sc.close().sync();

        if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) {
            throw sh.exception.get();
        }
        if (sh.exception.get() != null) {
            throw sh.exception.get();
        }
        if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) {
            throw ch.exception.get();
        }
        if (ch.exception.get() != null) {
            throw ch.exception.get();
        }
        assertEquals(0, ch.counter);
        assertEquals(Unpooled.wrappedBuffer(new byte[]{'b', 'c', 'e'}), sh.received);
    }

    private static class TestHandler extends SimpleChannelInboundHandler<ByteBuf> {
        volatile Channel channel;
        final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
        volatile int counter;
        final ByteBuf received = Unpooled.buffer();
        @Override
        public void channelActive(ChannelHandlerContext ctx)
                throws Exception {
            channel = ctx.channel();
        }

        @Override
        public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
            counter += in.readableBytes();
            received.writeBytes(in);
        }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free