PooledByteBufAllocatorTest Class — netty Architecture
Architecture documentation for the PooledByteBufAllocatorTest class in PooledByteBufAllocatorTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f8855572_2abf_1bf6_a32b_5cf6d1cf4947["PooledByteBufAllocatorTest"] cae90f9a_f201_a8e1_95cd_192dc599e5ef["PooledByteBufAllocatorTest.java"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|defined in| cae90f9a_f201_a8e1_95cd_192dc599e5ef 4e681469_9c14_67cb_5890_46b5d4b12dd2["PooledByteBufAllocator()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| 4e681469_9c14_67cb_5890_46b5d4b12dd2 f260e36d_d79f_3098_5720_34057becb167["expectedUsedMemory()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| f260e36d_d79f_3098_5720_34057becb167 f9a43daa_4d60_3f48_fc3c_e267da524d17["expectedUsedMemoryAfterRelease()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| f9a43daa_4d60_3f48_fc3c_e267da524d17 7192df7f_2c82_ba35_6dd4_2023f4e87e60["trimCaches()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| 7192df7f_2c82_ba35_6dd4_2023f4e87e60 c01568bc_ea31_779e_c501_ed06454af98b["testTrim()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| c01568bc_ea31_779e_c501_ed06454af98b e64bf923_31e9_241e_e3dc_ac03f34229aa["testPooledUnsafeHeapBufferAndUnsafeDirectBuffer()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| e64bf923_31e9_241e_e3dc_ac03f34229aa 9ca85707_202d_1269_2c41_0df2ec220449["testIOBuffersAreDirectWhenCleanerAvailableOrDirectBuffersPooled()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| 9ca85707_202d_1269_2c41_0df2ec220449 b9601684_1fea_4518_0160_fa04ca337931["testWithoutUseCacheForAllThreads()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| b9601684_1fea_4518_0160_fa04ca337931 7c1853c3_f413_66e9_4591_0a53aa815f13["testArenaMetricsNoCache()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| 7c1853c3_f413_66e9_4591_0a53aa815f13 f58189da_65a5_01e0_d257_6cd5a9e8accd["testArenaMetricsCache()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| f58189da_65a5_01e0_d257_6cd5a9e8accd d6e8f960_e95e_9559_6742_6adac6f99e0f["testArenaMetricsNoCacheAlign()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| d6e8f960_e95e_9559_6742_6adac6f99e0f 4ede93d7_0b70_b8fb_92b9_aeb3ca164186["testArenaMetricsCacheAlign()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| 4ede93d7_0b70_b8fb_92b9_aeb3ca164186 e61b0a85_1dee_f414_a1af_6f6871cab0d5["testArenaMetrics0()"] f8855572_2abf_1bf6_a32b_5cf6d1cf4947 -->|method| e61b0a85_1dee_f414_a1af_6f6871cab0d5
Relationship Graph
Source Code
buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java lines 57–1166
public class PooledByteBufAllocatorTest extends AbstractByteBufAllocatorTest<PooledByteBufAllocator> {
@Override
protected PooledByteBufAllocator newAllocator(boolean preferDirect) {
return new PooledByteBufAllocator(preferDirect);
}
@Override
protected PooledByteBufAllocator newUnpooledAllocator() {
return new PooledByteBufAllocator(0, 0, 8192, 1);
}
@Override
protected long expectedUsedMemory(PooledByteBufAllocator allocator, int capacity) {
return allocator.metric().chunkSize();
}
@Override
protected long expectedUsedMemoryAfterRelease(PooledByteBufAllocator allocator, int capacity) {
// This is the case as allocations will start in qInit and chunks in qInit will never be released until
// these are moved to q000.
// See https://www.bsdcan.org/2006/papers/jemalloc.pdf
return allocator.metric().chunkSize();
}
@Override
protected void trimCaches(PooledByteBufAllocator allocator) {
allocator.trimCurrentThreadCache();
}
@Test
public void testTrim() {
PooledByteBufAllocator allocator = newAllocator(true);
// Should return false as we never allocated from this thread yet.
assertFalse(allocator.trimCurrentThreadCache());
ByteBuf directBuffer = allocator.directBuffer();
assertTrue(directBuffer.release());
// Should return true now a cache exists for the calling thread.
assertTrue(allocator.trimCurrentThreadCache());
}
@Test
public void testPooledUnsafeHeapBufferAndUnsafeDirectBuffer() {
PooledByteBufAllocator allocator = newAllocator(true);
ByteBuf directBuffer = allocator.directBuffer();
assertInstanceOf(directBuffer,
PlatformDependent.hasUnsafe() ? PooledUnsafeDirectByteBuf.class : PooledDirectByteBuf.class);
directBuffer.release();
ByteBuf heapBuffer = allocator.heapBuffer();
assertInstanceOf(heapBuffer,
PlatformDependent.hasUnsafe() ? PooledUnsafeHeapByteBuf.class : PooledHeapByteBuf.class);
heapBuffer.release();
}
@Test
public void testIOBuffersAreDirectWhenCleanerAvailableOrDirectBuffersPooled() {
PooledByteBufAllocator allocator = newAllocator(true);
ByteBuf ioBuffer = allocator.ioBuffer();
assertTrue(ioBuffer.isDirect());
ioBuffer.release();
PooledByteBufAllocator unpooledAllocator = newUnpooledAllocator();
ioBuffer = unpooledAllocator.ioBuffer();
if (PlatformDependent.canReliabilyFreeDirectBuffers()) {
assertTrue(ioBuffer.isDirect());
} else {
assertFalse(ioBuffer.isDirect());
}
ioBuffer.release();
}
@Test
public void testWithoutUseCacheForAllThreads() {
assertThat(Thread.currentThread()).isNotInstanceOf(FastThreadLocalThread.class);
Source
Frequently Asked Questions
What is the PooledByteBufAllocatorTest class?
PooledByteBufAllocatorTest is a class in the netty codebase, defined in buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java.
Where is PooledByteBufAllocatorTest defined?
PooledByteBufAllocatorTest is defined in buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java at line 57.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free