Skip to content

Commit

Permalink
Add more tests for PoolArenaMetric
Browse files Browse the repository at this point in the history
Motivation:

We should add some more tests for PoolarenaMetric

Modifications:

Add more tests

Result:

Better test coverage for metrics
  • Loading branch information
normanmaurer committed May 20, 2016
1 parent 2e352b7 commit d41f076
Showing 1 changed file with 36 additions and 0 deletions.
Expand Up @@ -36,6 +36,42 @@

public class PooledByteBufAllocatorTest {

@Test
public void testArenaMetricsNoCache() {
testArenaMetrics0(new PooledByteBufAllocator(true, 2, 2, 8192, 11, 0, 0, 0), 100, 0, 100, 100);
}

@Test
public void testArenaMetricsCache() {
testArenaMetrics0(new PooledByteBufAllocator(true, 2, 2, 8192, 11, 1000, 1000, 1000), 100, 1, 1, 0);
}

private static void testArenaMetrics0(
PooledByteBufAllocator allocator, int num, int expectedActive, int expectedAlloc, int expectedDealloc) {
for (int i = 0; i < num; i++) {
assertTrue(allocator.directBuffer().release());
assertTrue(allocator.heapBuffer().release());
}

assertArenaMetrics(allocator.directArenas(), expectedActive, expectedAlloc, expectedDealloc);
assertArenaMetrics(allocator.heapArenas(), expectedActive, expectedAlloc, expectedDealloc);
}

private static void assertArenaMetrics(
List<PoolArenaMetric> arenaMetrics, int expectedActive, int expectedAlloc, int expectedDealloc) {
int active = 0;
int alloc = 0;
int dealloc = 0;
for (PoolArenaMetric arena : arenaMetrics) {
active += arena.numActiveAllocations();
alloc += arena.numAllocations();
dealloc += arena.numDeallocations();
}
assertEquals(expectedActive, active);
assertEquals(expectedAlloc, alloc);
assertEquals(expectedDealloc, dealloc);
}

@Test
public void testPoolChunkListMetric() {
for (PoolArenaMetric arenaMetric: PooledByteBufAllocator.DEFAULT.heapArenas()) {
Expand Down

0 comments on commit d41f076

Please sign in to comment.