static void AllocNotNull0(PooledByteBufferAllocator allocator, int capacity)
 {
     IByteBuffer buffer = allocator.HeapBuffer(capacity);
     Assert.NotNull(buffer.Allocator);
     Assert.True(buffer.Release());
     Assert.NotNull(buffer.Allocator);
 }
Exemple #2
0
        public void FreePoolChunk()
        {
            const int   ChunkSize = 16 * 1024 * 1024;
            var         allocator = new PooledByteBufferAllocator(true, 1, 0, 8192, 11, 0, 0, 0);
            IByteBuffer buffer    = allocator.HeapBuffer(ChunkSize);
            var         arenas    = allocator.Metric.HeapArenas();

            Assert.Equal(1, arenas.Count);
            var lists = arenas[0].ChunkLists;

            Assert.Equal(6, lists.Count);

            Assert.False(lists[0].GetEnumerator().MoveNext());
            Assert.False(lists[1].GetEnumerator().MoveNext());
            Assert.False(lists[2].GetEnumerator().MoveNext());
            Assert.False(lists[3].GetEnumerator().MoveNext());
            Assert.False(lists[4].GetEnumerator().MoveNext());

            // Must end up in the 6th PoolChunkList
            Assert.True(lists[5].GetEnumerator().MoveNext());
            Assert.True(buffer.Release());

            // Should be completely removed and so all PoolChunkLists must be empty
            Assert.False(lists[0].GetEnumerator().MoveNext());
            Assert.False(lists[1].GetEnumerator().MoveNext());
            Assert.False(lists[2].GetEnumerator().MoveNext());
            Assert.False(lists[3].GetEnumerator().MoveNext());
            Assert.False(lists[4].GetEnumerator().MoveNext());
            Assert.False(lists[5].GetEnumerator().MoveNext());
        }
Exemple #3
0
        static void ArenaMetrics0(PooledByteBufferAllocator allocator, int num, int expectedActive, int expectedAlloc, int expectedDealloc)
        {
            for (int i = 0; i < num; i++)
            {
                Assert.True(allocator.HeapBuffer().Release());
            }

            AssertArenaMetrics(allocator.Metric.HeapArenas(), expectedActive, expectedAlloc, expectedDealloc);
        }
 public void TinySubpageMetric()
 {
     var allocator = new PooledByteBufferAllocator(true, 1, 1, 8192, 11, 0, 0, 0);
     IByteBuffer buffer = allocator.HeapBuffer(1);
     try
     {
         IPoolArenaMetric metric = allocator.Metric.HeapArenas()[0];
         IPoolSubpageMetric subpageMetric = metric.TinySubpages[0];
         Assert.Equal(1, subpageMetric.MaxNumElements - subpageMetric.NumAvailable);
     }
     finally
     {
         buffer.Release();
     }
 }