Example usage for io.netty.buffer PooledByteBufAllocator directBuffer

List of usage examples for io.netty.buffer PooledByteBufAllocator directBuffer

Introduction

In this page you can find the example usage for io.netty.buffer PooledByteBufAllocator directBuffer.

Prototype

@Override
    public ByteBuf directBuffer(int initialCapacity, int maxCapacity) 

Source Link

Usage

From source file:com.yahoo.pulsar.broker.stats.BookieClientsStatsGeneratorTest.java

License:Apache License

@Test
public void testJvmDirectMemoryUsedMetric() throws Exception {
    PooledByteBufAllocator allocator = new PooledByteBufAllocator( //
            true, // preferDirect
            0, // nHeapArenas,
            1, // nDirectArena
            8192, // pageSize
            11, // maxOrder
            64, // tinyCacheSize
            32, // smallCacheSize
            8 // normalCacheSize
    );/*from   www  . ja  v  a 2s .  c o m*/
    int allocateMemory = 17777216;
    long directMemory1 = JvmMetrics.getJvmDirectMemoryUsed();
    ByteBuf buf2 = allocator.directBuffer(allocateMemory, allocateMemory);
    long directMemory2 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory2, directMemory1 + allocateMemory);
    ByteBuf buf3 = allocator.directBuffer(allocateMemory, allocateMemory);
    long directMemory3 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory3, directMemory2 + allocateMemory);
    buf3.release();
    directMemory3 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory3, directMemory2);
    buf2.release();
    directMemory2 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory2, directMemory1);

}