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));
}
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));
}
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");
}
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);
}
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());
}
}
Aggregations