@Test public void testBufferShrink() throws Exception { PooledMemoryManager mm = new PooledMemoryManager(DEFAULT_BASE_BUFFER_SIZE, 1, 0, 1, DEFAULT_HEAP_USAGE_PERCENTAGE, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); final TestProbe probe = new TestProbe(); mm.getMonitoringConfig().addProbes(probe); Buffer b = mm.allocate(13000); assertEquals(0, probe.bufferAllocated.get()); assertEquals(0, probe.bufferReleasedToPool.get()); assertEquals(4, probe.bufferAllocatedFromPool.get()); b.position(6666); b.limit(7000); b.shrink(); assertEquals(334, b.remaining()); assertEquals(0, probe.bufferAllocated.get()); assertEquals(3, probe.bufferReleasedToPool.get()); assertEquals(4, probe.bufferAllocatedFromPool.get()); b.tryDispose(); assertEquals(0, probe.bufferAllocated.get()); assertEquals(4, probe.bufferReleasedToPool.get()); assertEquals(4, probe.bufferAllocatedFromPool.get()); }
mm.getMonitoringConfig().addProbes(probe); Buffer b = mm.allocate(6666); assertEquals(0, probe.bufferAllocated.get());
@Test public void testSimpleAllocationAndDispose() throws Exception { PooledMemoryManager mm = new PooledMemoryManager(DEFAULT_BASE_BUFFER_SIZE, 1, 0, 1, DEFAULT_HEAP_USAGE_PERCENTAGE, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); final TestProbe probe = new TestProbe(); mm.getMonitoringConfig().addProbes(probe); // allocate a buffer and validate the configuration of said buffer Buffer b = mm.allocate(4096); assertEquals(4096, b.remaining()); assertTrue(!b.isComposite()); assertTrue(b.allowBufferDispose()); assertEquals(DEFAULT_BASE_BUFFER_SIZE, b.capacity()); // validate that pool returned a buffer. assertEquals(0, probe.bufferAllocated.get()); assertEquals(0, probe.bufferReleasedToPool.get()); assertEquals(1, probe.bufferAllocatedFromPool.get()); // dispose the buffer and validate the pool has returned to it's // original size b.tryDispose(); // validate that buffer was returned to the pool. assertEquals(0, probe.bufferAllocated.get()); assertEquals(1, probe.bufferReleasedToPool.get()); assertEquals(1, probe.bufferAllocatedFromPool.get()); }
isDirect); final TestProbe probe = new TestProbe(); mm.getMonitoringConfig().addProbes(probe);
mm.getMonitoringConfig().addProbes(probe);
mm.getMonitoringConfig().addProbes(probe);