Search in sources :

Example 81 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class GenericBlockBasedIndexPopulatorTest method shouldThrowOnDuplicatedValuesFromExternalUpdates.

@Test
void shouldThrowOnDuplicatedValuesFromExternalUpdates() throws IOException {
    // given
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(UNIQUE_INDEX_DESCRIPTOR);
    try {
        // when
        Value duplicate = Values.of("duplicate");
        ValueIndexEntryUpdate<?> firstExternalUpdate = ValueIndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate);
        ValueIndexEntryUpdate<?> secondExternalUpdate = ValueIndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate);
        assertThrows(IndexEntryConflictException.class, () -> {
            try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
                updater.process(firstExternalUpdate);
                updater.process(secondExternalUpdate);
            }
            populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        });
    } finally {
        populator.close(true, NULL);
    }
}
Also used : Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 82 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class IndexAccessorTests method shouldHandleCloseWithoutCallsToProcess.

@Test
void shouldHandleCloseWithoutCallsToProcess() throws Exception {
    // given
    IndexUpdater updater = accessor.newUpdater(ONLINE, NULL);
    // when
    updater.close();
// then
// ... should be fine
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 83 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater 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 84 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater 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 85 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class NativeIndexAccessorTests method shouldIndexAdd.

@Test
void shouldIndexAdd() throws Exception {
    // given
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
    try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
        // when
        processAll(updater, updates);
    }
    // then
    forceAndCloseAccessor();
    valueUtil.verifyUpdates(updates, this::getTree);
}
Also used : ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Aggregations

IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)94 Test (org.junit.jupiter.api.Test)61 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)13 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)9 Value (org.neo4j.values.storable.Value)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)7 CursorContext (org.neo4j.io.pagecache.context.CursorContext)7 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)6 SwallowingIndexUpdater (org.neo4j.kernel.impl.api.index.SwallowingIndexUpdater)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Transaction (org.neo4j.graphdb.Transaction)4 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)4 SchemaIndexTestHelper.mockIndexProxy (org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy)4 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)4 HashMap (java.util.HashMap)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3