Home / Function/ testSetBytesOnReadOnlyByteBufferWithPooledAlloc() — netty Function Reference

testSetBytesOnReadOnlyByteBufferWithPooledAlloc() — netty Function Reference

Architecture documentation for the testSetBytesOnReadOnlyByteBufferWithPooledAlloc() function in UnsafeByteBufUtilTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f02794d5_922b_c111_0a81_b8a46286d4cb["testSetBytesOnReadOnlyByteBufferWithPooledAlloc()"]
  9a18ae5b_9169_5444_e060_c39f7f301455["UnsafeByteBufUtilTest"]
  f02794d5_922b_c111_0a81_b8a46286d4cb -->|defined in| 9a18ae5b_9169_5444_e060_c39f7f301455
  style f02794d5_922b_c111_0a81_b8a46286d4cb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

buffer/src/test/java/io/netty/buffer/UnsafeByteBufUtilTest.java lines 60–93

    @Test
    public void testSetBytesOnReadOnlyByteBufferWithPooledAlloc() throws Exception {
        byte[] testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        int length = testData.length;

        ByteBuffer readOnlyBuffer = ByteBuffer.wrap(testData).asReadOnlyBuffer();

        int pageSize = 4096;

        // create memory pool with one page
        ByteBufAllocator alloc = new PooledByteBufAllocator(true, 1, 1, pageSize, 0);
        UnpooledDirectByteBuf targetBuffer = new UnpooledDirectByteBuf(alloc, length, length);

        ByteBuf b1 = alloc.heapBuffer(16);
        ByteBuf b2 = alloc.heapBuffer(16);

        try {
            // just check that two following buffers share same array but different offset
            assertEquals(pageSize, b1.array().length);
            assertArrayEquals(b1.array(), b2.array());
            assertNotEquals(b1.arrayOffset(), b2.arrayOffset());

            UnsafeByteBufUtil.setBytes(targetBuffer, directBufferAddress(targetBuffer.nioBuffer()), 0, readOnlyBuffer);

            byte[] check = new byte[length];
            targetBuffer.getBytes(0, check, 0, length);

            assertArrayEquals(testData, check, "The byte array's copy does not equal the original");
        } finally {
            targetBuffer.release();
            b1.release();
            b2.release();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testSetBytesOnReadOnlyByteBufferWithPooledAlloc() do?
testSetBytesOnReadOnlyByteBufferWithPooledAlloc() is a function in the netty codebase, defined in buffer/src/test/java/io/netty/buffer/UnsafeByteBufUtilTest.java.
Where is testSetBytesOnReadOnlyByteBufferWithPooledAlloc() defined?
testSetBytesOnReadOnlyByteBufferWithPooledAlloc() is defined in buffer/src/test/java/io/netty/buffer/UnsafeByteBufUtilTest.java at line 60.

Analyze Your Own Codebase

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

Try Supermodel Free