Home / Function/ testFileRegion0() — netty Function Reference

testFileRegion0() — netty Function Reference

Architecture documentation for the testFileRegion0() function in SocketFileRegionTest.java from the netty codebase.

Function java Buffer Search calls 5 called by 5

Entity Profile

Dependency Diagram

graph TD
  6eac02da_298b_00fe_bf12_0ee99a88a418["testFileRegion0()"]
  1e616c1f_beb1_f204_7cd9_bc69aa429e6c["SocketFileRegionTest"]
  6eac02da_298b_00fe_bf12_0ee99a88a418 -->|defined in| 1e616c1f_beb1_f204_7cd9_bc69aa429e6c
  4472a528_5cc8_b9ea_f8cf_7aa5218ad79f["testFileRegion()"]
  4472a528_5cc8_b9ea_f8cf_7aa5218ad79f -->|calls| 6eac02da_298b_00fe_bf12_0ee99a88a418
  b67f3545_6695_a056_ecd3_ad536a9e140b["testCustomFileRegion()"]
  b67f3545_6695_a056_ecd3_ad536a9e140b -->|calls| 6eac02da_298b_00fe_bf12_0ee99a88a418
  b0beca37_91c2_1ad2_eb93_e73cac9b130e["testFileRegionVoidPromise()"]
  b0beca37_91c2_1ad2_eb93_e73cac9b130e -->|calls| 6eac02da_298b_00fe_bf12_0ee99a88a418
  6e865daf_bb8b_9a10_0674_33c1ba25f340["testFileRegionNotAutoRead()"]
  6e865daf_bb8b_9a10_0674_33c1ba25f340 -->|calls| 6eac02da_298b_00fe_bf12_0ee99a88a418
  e9eab5e1_7db2_b084_f73c_19af0bb013f5["testFileRegionVoidPromiseNotAutoRead()"]
  e9eab5e1_7db2_b084_f73c_19af0bb013f5 -->|calls| 6eac02da_298b_00fe_bf12_0ee99a88a418
  f57b4fd0_ce30_5126_0750_098594d0bb59["channelRead0()"]
  6eac02da_298b_00fe_bf12_0ee99a88a418 -->|calls| f57b4fd0_ce30_5126_0750_098594d0bb59
  8bcbdcff_6a4a_9210_68f3_ec9838d34fa5["channelReadComplete()"]
  6eac02da_298b_00fe_bf12_0ee99a88a418 -->|calls| 8bcbdcff_6a4a_9210_68f3_ec9838d34fa5
  7f016959_f7c8_b589_846c_4ee88d1f39be["exceptionCaught()"]
  6eac02da_298b_00fe_bf12_0ee99a88a418 -->|calls| 7f016959_f7c8_b589_846c_4ee88d1f39be
  f0916c46_958b_fb7e_b632_7b039f808296["TestHandler()"]
  6eac02da_298b_00fe_bf12_0ee99a88a418 -->|calls| f0916c46_958b_fb7e_b632_7b039f808296
  88f2a575_689a_4b7c_206b_da6357ae4b2e["FileRegionWrapper()"]
  6eac02da_298b_00fe_bf12_0ee99a88a418 -->|calls| 88f2a575_689a_4b7c_206b_da6357ae4b2e
  style 6eac02da_298b_00fe_bf12_0ee99a88a418 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java lines 169–270

    private static void testFileRegion0(
            ServerBootstrap sb, Bootstrap cb, boolean voidPromise, final boolean autoRead, boolean defaultFileRegion)
            throws Throwable {
        sb.childOption(ChannelOption.AUTO_READ, autoRead);
        cb.option(ChannelOption.AUTO_READ, autoRead);

        final int bufferSize = 1024;
        final File file = PlatformDependent.createTempFile("netty-", ".tmp", null);
        file.deleteOnExit();

        final FileOutputStream out = new FileOutputStream(file);
        final Random random = ThreadLocalRandom.current();

        // Prepend random data which will not be transferred, so that we can test non-zero start offset
        final int startOffset = random.nextInt(8192);
        for (int i = 0; i < startOffset; i ++) {
            out.write(random.nextInt());
        }

        // .. and here comes the real data to transfer.
        out.write(data, bufferSize, data.length - bufferSize);

        // .. and then some extra data which is not supposed to be transferred.
        for (int i = random.nextInt(8192); i > 0; i --) {
            out.write(random.nextInt());
        }

        out.close();

        ChannelInboundHandler ch = new SimpleChannelInboundHandler<Object>() {
            @Override
            public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
            }

            @Override
            public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
                if (!autoRead) {
                    ctx.read();
                }
            }

            @Override
            public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                ctx.close();
            }
        };
        TestHandler sh = new TestHandler(autoRead);

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

        Channel sc = sb.bind().sync().channel();

        Channel cc = cb.connect(sc.localAddress()).sync().channel();
        FileRegion region = new DefaultFileRegion(
                new RandomAccessFile(file, "r").getChannel(), startOffset, data.length - bufferSize);
        FileRegion emptyRegion = new DefaultFileRegion(new RandomAccessFile(file, "r").getChannel(), 0, 0);

        if (!defaultFileRegion) {
            region = new FileRegionWrapper(region);
            emptyRegion = new FileRegionWrapper(emptyRegion);
        }
        // Do write ByteBuf and then FileRegion to ensure that mixed writes work
        // Also, write an empty FileRegion to test if writing an empty FileRegion does not cause any issues.
        //
        // See https://github.com/netty/netty/issues/2769
        //     https://github.com/netty/netty/issues/2964
        if (voidPromise) {
            assertEquals(cc.voidPromise(), cc.write(
                    randomBufferType(cc.alloc(), data, 0, bufferSize), cc.voidPromise()));
            assertEquals(cc.voidPromise(), cc.write(emptyRegion, cc.voidPromise()));
            assertEquals(cc.voidPromise(), cc.writeAndFlush(region, cc.voidPromise()));
        } else {
            assertNotEquals(cc.voidPromise(), cc.write(
                    randomBufferType(cc.alloc(), data, 0, bufferSize)));
            assertNotEquals(cc.voidPromise(), cc.write(emptyRegion));
            assertNotEquals(cc.voidPromise(), cc.writeAndFlush(region));
        }

        while (sh.counter < data.length) {
            if (sh.exception.get() != null) {

Domain

Subdomains

Frequently Asked Questions

What does testFileRegion0() do?
testFileRegion0() is a function in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java.
Where is testFileRegion0() defined?
testFileRegion0() is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java at line 169.
What does testFileRegion0() call?
testFileRegion0() calls 5 function(s): FileRegionWrapper, TestHandler, channelRead0, channelReadComplete, exceptionCaught.
What calls testFileRegion0()?
testFileRegion0() is called by 5 function(s): testCustomFileRegion, testFileRegion, testFileRegionNotAutoRead, testFileRegionVoidPromise, testFileRegionVoidPromiseNotAutoRead.

Analyze Your Own Codebase

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

Try Supermodel Free