AbstractByteBufAllocator implements ByteBufAllocator { @Override public ByteBuf heapBuffer() { return heapBuffer(DEFAULT_INITIAL_CAPACITY, DEFAULT_MAX_CAPACITY); } protected  AbstractByteBufAllocator(); protected  AbstractByteBufAllocator(boolean preferDirect); @Override ByteBuf buffer(); @Override ByteBuf buffer(int initialCapacity); @Override ByteBuf buffer(int initialCapacity, int maxCapacity); @Override ByteBuf ioBuffer(); @Override ByteBuf ioBuffer(int initialCapacity); @Override ByteBuf ioBuffer(int initialCapacity, int maxCapacity); @Override ByteBuf heapBuffer(); @Override ByteBuf heapBuffer(int initialCapacity); @Override ByteBuf heapBuffer(int initialCapacity, int maxCapacity); @Override ByteBuf directBuffer(); @Override ByteBuf directBuffer(int initialCapacity); @Override ByteBuf directBuffer(int initialCapacity, int maxCapacity); @Override CompositeByteBuf compositeBuffer(); @Override CompositeByteBuf compositeBuffer(int maxNumComponents); @Override CompositeByteBuf compositeHeapBuffer(); @Override CompositeByteBuf compositeHeapBuffer(int maxNumComponents); @Override CompositeByteBuf compositeDirectBuffer(); @Override CompositeByteBuf compositeDirectBuffer(int maxNumComponents); @Override String toString(); @Override int calculateNewCapacity(int minNewCapacity, int maxCapacity);  }
@SuppressWarnings("unchecked") @Test public void testUsedHeapMemory() { T allocator = newAllocator(true); ByteBufAllocatorMetric metric = ((ByteBufAllocatorMetricProvider) allocator).metric(); assertEquals(0, metric.usedHeapMemory()); ByteBuf buffer = allocator.heapBuffer(1024, 4096); int capacity = buffer.capacity(); assertEquals(expectedUsedMemory(allocator, capacity), metric.usedHeapMemory()); buffer.capacity(capacity << 1); capacity = buffer.capacity(); assertEquals(expectedUsedMemory(allocator, capacity), metric.usedHeapMemory()); buffer.release(); assertEquals(expectedUsedMemoryAfterRelease(allocator, capacity), metric.usedHeapMemory()); }