use of org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator.MemoryBlock in project neo4j by neo4j.
the class CachingOffHeapBlockAllocatorTest method allocateAndFree.
@Test
void allocateAndFree() {
final MemoryBlock block1 = allocator.allocate(128, memoryTracker);
assertEquals(128, block1.size);
assertEquals(128, block1.size);
assertEquals(block1.size, memoryTracker.usedNativeMemory());
final MemoryBlock block2 = allocator.allocate(256, memoryTracker);
assertEquals(256, block2.size);
assertEquals(256, block2.size);
assertEquals(block1.size + block2.size, memoryTracker.usedNativeMemory());
allocator.free(block1, memoryTracker);
allocator.free(block2, memoryTracker);
assertEquals(0, memoryTracker.usedNativeMemory());
}
use of org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator.MemoryBlock in project neo4j by neo4j.
the class CachingOffHeapBlockAllocatorTest method freeAfterRelease.
@Test
void freeAfterRelease() {
final MemoryBlock block = allocator.allocate(128, memoryTracker);
allocator.release();
allocator.free(block, memoryTracker);
verify(allocator).doFree(eq(block), any());
}
use of org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator.MemoryBlock in project neo4j by neo4j.
the class CachingOffHeapBlockAllocatorTest method allocateNonCacheableSize.
@ParameterizedTest
@ValueSource(longs = { 10, 100, 256 })
void allocateNonCacheableSize(long bytes) {
final MemoryBlock block1 = allocator.allocate(bytes, memoryTracker);
allocator.free(block1, memoryTracker);
final MemoryBlock block2 = allocator.allocate(bytes, memoryTracker);
allocator.free(block2, memoryTracker);
verify(allocator, times(2)).allocateNew(eq(bytes), any());
verify(allocator).doFree(eq(block1), any());
verify(allocator).doFree(eq(block2), any());
assertEquals(0, memoryTracker.usedNativeMemory());
}
use of org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator.MemoryBlock in project neo4j by neo4j.
the class CachingOffHeapBlockAllocatorTest method allocateCacheableSize.
@ParameterizedTest
@ValueSource(longs = { 8, 64, 128 })
void allocateCacheableSize(long bytes) {
final MemoryBlock block1 = allocator.allocate(bytes, memoryTracker);
allocator.free(block1, memoryTracker);
final MemoryBlock block2 = allocator.allocate(bytes, memoryTracker);
allocator.free(block2, memoryTracker);
verify(allocator).allocateNew(eq(bytes), any());
verify(allocator, never()).doFree(any(), any());
assertEquals(0, memoryTracker.usedNativeMemory());
}
use of org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator.MemoryBlock in project neo4j by neo4j.
the class CapacityLimitingBlockAllocatorDecoratorTest method maxMemoryLimit.
@Test
void maxMemoryLimit() {
final MemoryTracker tracker = mock(MemoryTracker.class);
final OffHeapBlockAllocator allocator = mock(OffHeapBlockAllocator.class);
when(allocator.allocate(anyLong(), any(MemoryTracker.class))).then(invocation -> {
final long size = invocation.<Long>getArgument(0);
return new MemoryBlock(0, size);
});
final CapacityLimitingBlockAllocatorDecorator decorator = new CapacityLimitingBlockAllocatorDecorator(allocator, 1024);
final List<MemoryBlock> blocks = new ArrayList<>();
for (int i = 0; i < 8; i++) {
final MemoryBlock block = decorator.allocate(128, tracker);
blocks.add(block);
}
assertThrows(MemoryAllocationLimitException.class, () -> decorator.allocate(128, tracker));
decorator.free(blocks.remove(0), tracker);
assertDoesNotThrow(() -> decorator.allocate(128, tracker));
assertThrows(MemoryAllocationLimitException.class, () -> decorator.allocate(256, tracker));
decorator.free(blocks.remove(0), tracker);
assertThrows(MemoryAllocationLimitException.class, () -> decorator.allocate(256, tracker));
decorator.free(blocks.remove(0), tracker);
assertDoesNotThrow(() -> decorator.allocate(256, tracker));
}
Aggregations