Home / Class/ AbstractByteBufAllocatorTest Class — netty Architecture

AbstractByteBufAllocatorTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac["AbstractByteBufAllocatorTest"]
  9d0a3478_3208_f620_7117_b1687427fa0e["AbstractByteBufAllocatorTest.java"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|defined in| 9d0a3478_3208_f620_7117_b1687427fa0e
  85ea4270_27c9_f1fe_b13f_3d24785730ad["T()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| 85ea4270_27c9_f1fe_b13f_3d24785730ad
  2242b6b1_72ee_fc40_8131_47638d5b559a["isDirectExpected()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| 2242b6b1_72ee_fc40_8131_47638d5b559a
  07c159b3_792d_846d_6068_3f3ccd1a0914["defaultMaxCapacity()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| 07c159b3_792d_846d_6068_3f3ccd1a0914
  0b1d84c8_b84d_de44_b845_a40925437b95["defaultMaxComponents()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| 0b1d84c8_b84d_de44_b845_a40925437b95
  2f974bf5_b1d1_043f_7742_4af1bbd1b2dd["testCalculateNewCapacity()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| 2f974bf5_b1d1_043f_7742_4af1bbd1b2dd
  fa87f171_782f_d03f_d04f_dede8e06be3d["testUnsafeHeapBufferAndUnsafeDirectBuffer()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| fa87f171_782f_d03f_d04f_dede8e06be3d
  964154f2_d301_0bc6_b8d5_7b427c51c0d3["assertInstanceOf()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| 964154f2_d301_0bc6_b8d5_7b427c51c0d3
  cf2c3b1f_46c8_9f2c_c10c_17ec7c22df90["assertSameBuffer()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| cf2c3b1f_46c8_9f2c_c10c_17ec7c22df90
  44cca0ab_9460_0ecb_2128_eb77abb4dba0["directBuffersMustHaveMemoryAddress()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| 44cca0ab_9460_0ecb_2128_eb77abb4dba0
  e10fe3d2_1745_fdb4_78ac_e6a561b91625["testUsedDirectMemory()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| e10fe3d2_1745_fdb4_78ac_e6a561b91625
  da3579b5_707e_51fb_c530_090c3856ec54["testUsedDirectMemoryHuge()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| da3579b5_707e_51fb_c530_090c3856ec54
  f2d3fcd9_6f19_eae3_0895_9522237370cb["testUsedHeapMemory()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| f2d3fcd9_6f19_eae3_0895_9522237370cb
  9846edfc_16b2_83f5_111a_45bf3126ed18["testUsedHeapMemoryHuge()"]
  7ff0721a_af2d_e20c_7c69_b0b95f85fcac -->|method| 9846edfc_16b2_83f5_111a_45bf3126ed18

Relationship Graph

Source Code

buffer/src/test/java/io/netty/buffer/AbstractByteBufAllocatorTest.java lines 35–226

public abstract class AbstractByteBufAllocatorTest<T extends AbstractByteBufAllocator> extends ByteBufAllocatorTest {

    @Override
    protected abstract T newAllocator(boolean preferDirect);

    protected abstract T newUnpooledAllocator();

    @Override
    protected boolean isDirectExpected(boolean preferDirect) {
        return preferDirect && PlatformDependent.canReliabilyFreeDirectBuffers();
    }

    @Override
    protected final int defaultMaxCapacity() {
        return AbstractByteBufAllocator.DEFAULT_MAX_CAPACITY;
    }

    @Override
    protected final int defaultMaxComponents() {
        return AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS;
    }

    @Test
    public void testCalculateNewCapacity() {
        testCalculateNewCapacity(true);
        testCalculateNewCapacity(false);
    }

    private void testCalculateNewCapacity(boolean preferDirect) {
        T allocator = newAllocator(preferDirect);
        assertEquals(8, allocator.calculateNewCapacity(1, 8));
        assertEquals(7, allocator.calculateNewCapacity(1, 7));
        assertEquals(64, allocator.calculateNewCapacity(1, 129));
        assertEquals(AbstractByteBufAllocator.CALCULATE_THRESHOLD,
                allocator.calculateNewCapacity(AbstractByteBufAllocator.CALCULATE_THRESHOLD,
                        AbstractByteBufAllocator.CALCULATE_THRESHOLD + 1));
        assertEquals(AbstractByteBufAllocator.CALCULATE_THRESHOLD * 2,
                allocator.calculateNewCapacity(AbstractByteBufAllocator.CALCULATE_THRESHOLD + 1,
                        AbstractByteBufAllocator.CALCULATE_THRESHOLD * 4));
        try {
            allocator.calculateNewCapacity(8, 7);
            fail();
        } catch (IllegalArgumentException e) {
            // expected
        }

        try {
            allocator.calculateNewCapacity(-1, 8);
            fail();
        } catch (IllegalArgumentException e) {
            // expected
        }
    }

    @Test
    public void testUnsafeHeapBufferAndUnsafeDirectBuffer() {
        T allocator = newUnpooledAllocator();
        ByteBuf directBuffer = allocator.directBuffer();
        assertInstanceOf(directBuffer,
                PlatformDependent.hasUnsafe() ? UnpooledUnsafeDirectByteBuf.class : UnpooledDirectByteBuf.class);
        directBuffer.release();

        ByteBuf heapBuffer = allocator.heapBuffer();
        assertInstanceOf(heapBuffer,
                PlatformDependent.hasUnsafe() ? UnpooledUnsafeHeapByteBuf.class : UnpooledHeapByteBuf.class);
        heapBuffer.release();
    }

    protected static void assertInstanceOf(ByteBuf buffer, Class<? extends ByteBuf> clazz) {
        // Unwrap if needed
        if (buffer instanceof SimpleLeakAwareByteBuf) {
            buffer = buffer.unwrap();
        }
        assertThat(buffer).isInstanceOf(clazz);
    }

    protected static void assertSameBuffer(ByteBuf expected, ByteBuf buffer) {
        // Unwrap if needed
        assertSame(expected, buffer instanceof SimpleLeakAwareByteBuf ? buffer.unwrap() : buffer);
    }

Frequently Asked Questions

What is the AbstractByteBufAllocatorTest class?
AbstractByteBufAllocatorTest is a class in the netty codebase, defined in buffer/src/test/java/io/netty/buffer/AbstractByteBufAllocatorTest.java.
Where is AbstractByteBufAllocatorTest defined?
AbstractByteBufAllocatorTest is defined in buffer/src/test/java/io/netty/buffer/AbstractByteBufAllocatorTest.java at line 35.

Analyze Your Own Codebase

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

Try Supermodel Free