Search in sources :

Example 6 with ByteBufferFactory

use of org.neo4j.io.memory.ByteBufferFactory in project neo4j by neo4j.

the class BlockBasedIndexPopulatorTest method shouldFailOnUpdatedTooLargeValue.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldFailOnUpdatedTooLargeValue(boolean updateBeforeScanCompleted) throws IndexEntryConflictException, IOException {
    // / given
    ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, SUFFICIENTLY_LARGE_BUFFER_SIZE);
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, INSTANCE);
    try {
        int size = populator.tree.keyValueSizeCap() + 1;
        if (!updateBeforeScanCompleted) {
            populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        }
        assertThrows(IllegalArgumentException.class, () -> {
            try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
                updater.process(IndexEntryUpdate.add(0, INDEX_DESCRIPTOR, generateStringValueResultingInIndexEntrySize(layout(), size)));
            }
        });
    } finally {
        populator.close(false, NULL);
    }
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ByteBufferFactory(org.neo4j.io.memory.ByteBufferFactory) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with ByteBufferFactory

use of org.neo4j.io.memory.ByteBufferFactory in project neo4j by neo4j.

the class BlockBasedIndexPopulatorTest method shouldAcceptUpdatedMaxSizeValue.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldAcceptUpdatedMaxSizeValue(boolean updateBeforeScanCompleted) throws Throwable {
    // given
    ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, SUFFICIENTLY_LARGE_BUFFER_SIZE);
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, INSTANCE);
    try {
        int size = populator.tree.keyValueSizeCap();
        GenericLayout layout = layout();
        Value value = generateStringValueResultingInIndexEntrySize(layout, size);
        IndexEntryUpdate<IndexDescriptor> update = IndexEntryUpdate.add(0, INDEX_DESCRIPTOR, value);
        Race.ThrowingRunnable updateAction = () -> {
            try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
                updater.process(update);
            }
        };
        if (updateBeforeScanCompleted) {
            updateAction.run();
            populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        } else {
            populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
            updateAction.run();
        }
        // when
        try (Seeker<GenericKey, NativeIndexValue> seek = seek(populator.tree, layout)) {
            // then
            assertTrue(seek.next());
            assertEquals(value, seek.key().asValue());
            assertFalse(seek.next());
        }
    } finally {
        populator.close(true, NULL);
    }
}
Also used : IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ByteBufferFactory(org.neo4j.io.memory.ByteBufferFactory) Race(org.neo4j.test.Race) Value(org.neo4j.values.storable.Value) Values.intValue(org.neo4j.values.storable.Values.intValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with ByteBufferFactory

use of org.neo4j.io.memory.ByteBufferFactory in project neo4j by neo4j.

the class BlockBasedIndexPopulatorTest method shouldAcceptBatchAddedMaxSizeValue.

@Test
void shouldAcceptBatchAddedMaxSizeValue() throws IndexEntryConflictException, IOException {
    // given
    ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, SUFFICIENTLY_LARGE_BUFFER_SIZE);
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, INSTANCE);
    try {
        int size = populator.tree.keyValueSizeCap();
        GenericLayout layout = layout();
        Value value = generateStringValueResultingInIndexEntrySize(layout, size);
        Collection<? extends IndexEntryUpdate<?>> data = singletonList(IndexEntryUpdate.add(0, INDEX_DESCRIPTOR, value));
        populator.add(data, NULL);
        populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        // when
        try (Seeker<GenericKey, NativeIndexValue> seek = seek(populator.tree, layout)) {
            // then
            assertTrue(seek.next());
            assertEquals(value, seek.key().asValue());
            assertFalse(seek.next());
        }
    } finally {
        populator.close(true, NULL);
    }
}
Also used : Value(org.neo4j.values.storable.Value) Values.intValue(org.neo4j.values.storable.Values.intValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) ByteBufferFactory(org.neo4j.io.memory.ByteBufferFactory) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 ByteBufferFactory (org.neo4j.io.memory.ByteBufferFactory)8 Test (org.junit.jupiter.api.Test)6 ThreadSafePeakMemoryTracker (org.neo4j.memory.ThreadSafePeakMemoryTracker)4 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)3 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 Value (org.neo4j.values.storable.Value)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 GBPTree (org.neo4j.index.internal.gbptree.GBPTree)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 IndexSample (org.neo4j.kernel.api.index.IndexSample)1 Monitors (org.neo4j.monitoring.Monitors)1 Race (org.neo4j.test.Race)1