Home / Function/ testSendFile() — netty Function Reference

testSendFile() — netty Function Reference

Architecture documentation for the testSendFile() function in IoUringFileRegionTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  7e33ab5a_9bbd_d0ff_0c28_5940bed9cb15["testSendFile()"]
  822eedc3_f683_9f83_1a1a_638117b1d243["IoUringFileRegionTest"]
  7e33ab5a_9bbd_d0ff_0c28_5940bed9cb15 -->|defined in| 822eedc3_f683_9f83_1a1a_638117b1d243
  style 7e33ab5a_9bbd_d0ff_0c28_5940bed9cb15 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringFileRegionTest.java lines 44–102

    @Test
    public void testSendFile() throws IOException, InterruptedException {
        MultiThreadIoEventLoopGroup group = new MultiThreadIoEventLoopGroup(1, IoUringIoHandler.newFactory());
        String sampleString = "hello netty io_uring sendFile!";
        File inFile = File.createTempFile(UUID.randomUUID().toString(), ".tmp");
        inFile.deleteOnExit();
        Files.write(inFile.toPath(), sampleString.getBytes());
        BlockingQueue<ByteBuf> sendFileResult = new LinkedBlockingQueue<>();

        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.channel(IoUringServerSocketChannel.class);
        Channel serverChannel = serverBootstrap.group(group)
                .childHandler(new ChannelInboundHandlerAdapter() {
                    private CompositeByteBuf compositeByteBuf;

                    @Override
                    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
                        compositeByteBuf = ctx.alloc().compositeBuffer();
                    }

                    @Override
                    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
                        if (compositeByteBuf != null) {
                            compositeByteBuf.release();
                        }
                    }

                    @Override
                    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                        ByteBuf buf = (ByteBuf) msg;
                        compositeByteBuf.addComponent(true, buf);
                        if (compositeByteBuf.readableBytes() == inFile.length()) {
                            sendFileResult.put(compositeByteBuf);
                            compositeByteBuf = null;
                        }
                    }
                })
                .bind(NetUtil.LOCALHOST, 0)
                .syncUninterruptibly().channel();

        Bootstrap clientBoostrap = new Bootstrap();
        clientBoostrap.group(group)
                .channel(IoUringSocketChannel.class)
                .handler(new ChannelInboundHandlerAdapter());
        Channel clientChannel = clientBoostrap.connect(serverChannel.localAddress()).syncUninterruptibly().channel();
        clientChannel.writeAndFlush(new DefaultFileRegion(inFile, 0, Files.size(inFile.toPath()))).sync();
        ByteBuf result = sendFileResult.take();
        ByteBuf expected = Unpooled.copiedBuffer(sampleString, StandardCharsets.US_ASCII);
        try {
            assertEquals(expected, result);
        } finally {
            result.release();
            expected.release();
        }

        serverChannel.close().syncUninterruptibly();
        clientChannel.close().syncUninterruptibly();
        group.shutdownGracefully();
    }

Domain

Subdomains

Frequently Asked Questions

What does testSendFile() do?
testSendFile() is a function in the netty codebase, defined in transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringFileRegionTest.java.
Where is testSendFile() defined?
testSendFile() is defined in transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringFileRegionTest.java at line 44.

Analyze Your Own Codebase

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

Try Supermodel Free