protected PooledMemoryManager createPooledMemoryManager() { return new PooledMemoryManager(); }
new PooledMemoryManager(0, 1, 0, 1, DEFAULT_HEAP_USAGE_PERCENTAGE, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); fail(); new PooledMemoryManager(1024, 0, 0, 1, DEFAULT_HEAP_USAGE_PERCENTAGE, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); } catch (IllegalArgumentException iae) { new PooledMemoryManager(1024, 1, -1, 1, DEFAULT_HEAP_USAGE_PERCENTAGE, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); } catch (IllegalArgumentException iae) { new PooledMemoryManager(1024, 2, 0, 1, DEFAULT_HEAP_USAGE_PERCENTAGE , DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); } catch (IllegalArgumentException iae) { new PooledMemoryManager(1024, 1, 0, 0, DEFAULT_HEAP_USAGE_PERCENTAGE, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); } catch (IllegalArgumentException iae) { new PooledMemoryManager(1024, 1, 0, 1, 0, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); } catch (IllegalArgumentException iae) { new PooledMemoryManager(1024, 1, 0, 1, 1, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); } catch (IllegalArgumentException iae) { new PooledMemoryManager(1024, 1, 0, 1, DEFAULT_HEAP_USAGE_PERCENTAGE,
final PooledMemoryManager mm = new PooledMemoryManager( 4096, poolsNum, 1, Runtime.getRuntime().availableProcessors(), .10f, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect);
@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()); }
new PooledMemoryManager(DEFAULT_BASE_BUFFER_SIZE, 1, 0,
final int processors = Runtime.getRuntime().availableProcessors(); final long maxMemory = Runtime.getRuntime().maxMemory(); PooledMemoryManager mm = new PooledMemoryManager(2048, 1, 0, mm = new PooledMemoryManager(2048, 1, 0,
PooledMemoryManager mm = new PooledMemoryManager(); PooledMemoryManager.Pool[] pools = mm.getPools(); assertEquals(DEFAULT_NUMBER_OF_POOLS, pools.length);
@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()); }
@Test public void testSingleBufferComplexDispose() { PooledMemoryManager mm = new PooledMemoryManager(DEFAULT_BASE_BUFFER_SIZE, 1, 0,
@Test public void testIllegalAllocationArgument() throws Exception { PooledMemoryManager mm = new PooledMemoryManager(DEFAULT_BASE_BUFFER_SIZE, 1, 0, 1, DEFAULT_HEAP_USAGE_PERCENTAGE, DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE, isDirect); // allocation request must be greater than zero try { mm.allocate(-1); fail(); } catch (IllegalArgumentException iae) { // expected } catch (Exception e) { fail(); } try { mm.allocateAtLeast(-1); fail(); } catch (IllegalArgumentException iae) { // expected } catch (Exception e) { fail(); } }
@Test public void circularityBoundaryTest() { final PooledMemoryManager mm = new PooledMemoryManager( 128, 1, 0, 1, 1024.0f / Runtime.getRuntime().maxMemory(),
new PooledMemoryManager(DEFAULT_BASE_BUFFER_SIZE, 1, 0,
@Test public void testBufferEquals() { final HeapMemoryManager hmm = new HeapMemoryManager(); final ByteBufferManager bbm = new ByteBufferManager(); final PooledMemoryManager pmm = new PooledMemoryManager(); Buffer[] buffers = new Buffer[4]; buffers[0] = Buffers.wrap(hmm, "Value#1"); buffers[1] = Buffers.wrap(bbm, "Value#1"); buffers[2] = Buffers.wrap(pmm, "Value#1"); Buffer b11 = Buffers.wrap(hmm, "Val"); Buffer b12 = Buffers.wrap(bbm, "ue"); Buffer b13 = Buffers.wrap(pmm, "#1"); Buffer tmp = Buffers.appendBuffers(bbm, b11, b12); buffers[3] = Buffers.appendBuffers(bbm, tmp, b13); for (int i = 0; i < buffers.length; i++) { for (int j = 0; j < buffers.length; j++) { assertEquals(buffers[i], buffers[j]); } } }
new PooledMemoryManager(DEFAULT_BASE_BUFFER_SIZE, 1, 0,