Search in sources :

Example 26 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class ByteBufferFactoryTest method byteBufferMustThrowOutOfBoundsAfterRelease.

@Test
void byteBufferMustThrowOutOfBoundsAfterRelease() {
    var tracker = new LocalMemoryTracker();
    ByteBuffer buffer = ByteBuffers.allocateDirect(Long.BYTES, tracker);
    buffer.get(0);
    ByteBuffers.releaseBuffer(buffer, tracker);
    assertThrows(IndexOutOfBoundsException.class, () -> buffer.get(0));
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 27 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class ByteBufferFactoryTest method doubleFreeOfByteBufferIsOkay.

@Test
void doubleFreeOfByteBufferIsOkay() {
    var tracker = new LocalMemoryTracker();
    ByteBuffer buffer = ByteBuffers.allocateDirect(Long.BYTES, tracker);
    ByteBuffers.releaseBuffer(buffer, tracker);
    // This must not throw.
    ByteBuffers.releaseBuffer(buffer, tracker);
    // And this still throws.
    assertThrows(IndexOutOfBoundsException.class, () -> buffer.get(0));
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 28 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class IndexKeyStorageTest method mustAllocateResourcesLazilyAndCleanUpOnClose.

@Test
void mustAllocateResourcesLazilyAndCleanUpOnClose() throws IOException {
    FileSystemAbstraction fs = directory.getFileSystem();
    LocalMemoryTracker allocationTracker = new LocalMemoryTracker();
    Path file = directory.file("file");
    try (UnsafeDirectByteBufferAllocator bufferFactory = new UnsafeDirectByteBufferAllocator();
        IndexKeyStorage<GenericKey> keyStorage = keyStorage(file, bufferFactory, allocationTracker)) {
        assertEquals(0, allocationTracker.usedNativeMemory(), "Expected to not have any buffers allocated yet");
        assertFalse(fs.fileExists(file), "Expected file to be created lazily");
        keyStorage.add(randomKey(1));
        assertEquals(BLOCK_SIZE, allocationTracker.usedNativeMemory(), "Expected to have exactly one buffer allocated by now");
        assertTrue(fs.fileExists(file), "Expected file to be created by now");
    }
    assertFalse(fs.fileExists(file), "Expected file to be deleted on close");
}
Also used : Path(java.nio.file.Path) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Test(org.junit.jupiter.api.Test)

Example 29 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class RecentQueryBufferTest method shouldEstimateHeapOfFullBuffer.

@Test
void shouldEstimateHeapOfFullBuffer() {
    // given
    LocalMemoryTracker memoryTracker = new LocalMemoryTracker();
    RecentQueryBuffer buffer = new RecentQueryBuffer(4, memoryTracker);
    // when
    var queries = new TruncatedQuerySnapshot[] { query("RETURN 1", EMPTY_MAP), query("RETURN 2", EMPTY_MAP), query("RETURN 3", EMPTY_MAP), query("RETURN 4", EMPTY_MAP) };
    for (TruncatedQuerySnapshot q : queries) {
        buffer.produce(q);
    }
    // then
    assertEstimatedMemory(memoryTracker, buffer, queries);
    // when
    var q2 = query("RETURN 'I'm a longer query' AS x", EMPTY_MAP);
    buffer.produce(q2);
    // then
    queries[0] = q2;
    assertEstimatedMemory(memoryTracker, buffer, queries);
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Test(org.junit.jupiter.api.Test)

Example 30 with LocalMemoryTracker

use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.

the class UnsafeDirectByteBufferFactoryTest method shouldAllocateBuffer.

@Test
void shouldAllocateBuffer() {
    // given
    MemoryTracker tracker = new LocalMemoryTracker();
    try (UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator()) {
        // when
        int bufferSize = 128;
        factory.allocate(bufferSize, tracker);
        // then
        assertEquals(bufferSize, tracker.usedNativeMemory());
    }
}
Also used : LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Aggregations

LocalMemoryTracker (org.neo4j.memory.LocalMemoryTracker)30 Test (org.junit.jupiter.api.Test)19 BeforeEach (org.junit.jupiter.api.BeforeEach)9 MemoryPools (org.neo4j.memory.MemoryPools)8 MemoryTracker (org.neo4j.memory.MemoryTracker)7 ByteBuffer (java.nio.ByteBuffer)3 Path (java.nio.file.Path)2 EmptyMemoryTracker (org.neo4j.memory.EmptyMemoryTracker)2 Channel (io.netty.channel.Channel)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 BoltChannel (org.neo4j.bolt.BoltChannel)1 UnauthenticatedChannelProtector (org.neo4j.bolt.transport.pipeline.UnauthenticatedChannelProtector)1 UnsafeUtil.initDirectByteBuffer (org.neo4j.internal.unsafe.UnsafeUtil.initDirectByteBuffer)1 UnsafeUtil.newDirectByteBuffer (org.neo4j.internal.unsafe.UnsafeUtil.newDirectByteBuffer)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 PhysicalFlushableChannel (org.neo4j.io.fs.PhysicalFlushableChannel)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 MemoryAllocator (org.neo4j.io.mem.MemoryAllocator)1 MuninnPageCache (org.neo4j.io.pagecache.impl.muninn.MuninnPageCache)1 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)1