Search in sources :

Example 61 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NativeIndexAccessorTests method shouldIndexChange.

@Test
void shouldIndexChange() throws Exception {
    // given
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
    processAll(updates);
    Iterator<ValueIndexEntryUpdate<IndexDescriptor>> generator = filter(skipExisting(updates), valueCreatorUtil.randomUpdateGenerator(random));
    for (int i = 0; i < updates.length; i++) {
        ValueIndexEntryUpdate<IndexDescriptor> update = updates[i];
        Value newValue = generator.next().values()[0];
        updates[i] = change(update.getEntityId(), indexDescriptor, update.values()[0], newValue);
    }
    // when
    processAll(updates);
    // then
    forceAndCloseAccessor();
    valueUtil.verifyUpdates(updates, this::getTree);
}
Also used : ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 62 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NativeIndexAccessorTests method shouldReturnMatchingEntriesForExactPredicate.

@Test
void shouldReturnMatchingEntriesForExactPredicate() throws Exception {
    // given
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
    processAll(updates);
    // when
    var reader = accessor.newValueReader();
    for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
        Value value = update.values()[0];
        try (NodeValueIterator result = query(reader, PropertyIndexQuery.exact(0, value))) {
            assertEntityIdHits(extractEntityIds(updates, in(value)), result);
        }
    }
}
Also used : ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 63 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NativeIndexPopulatorTests method updaterShouldApplyUpdates.

@Test
void updaterShouldApplyUpdates() throws Exception {
    // given
    populator.create();
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = valueCreatorUtil.someUpdates(random);
    try (IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
        // when
        for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
            updater.process(update);
        }
    }
    // then
    populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
    populator.close(true, NULL);
    valueUtil.verifyUpdates(updates, this::getTree);
}
Also used : ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 64 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NativeIndexPopulatorTests method applyInterleaved.

void applyInterleaved(IndexEntryUpdate<IndexDescriptor>[] updates, IndexPopulator populator) throws IndexEntryConflictException {
    boolean useUpdater = true;
    Collection<IndexEntryUpdate<IndexDescriptor>> populatorBatch = new ArrayList<>();
    IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL);
    for (IndexEntryUpdate<IndexDescriptor> update : updates) {
        if (random.nextInt(100) < 20) {
            if (useUpdater) {
                updater.close();
                populatorBatch = new ArrayList<>();
            } else {
                populator.add(populatorBatch, NULL);
                updater = populator.newPopulatingUpdater(null_property_accessor, NULL);
            }
            useUpdater = !useUpdater;
        }
        if (useUpdater) {
            updater.process(update);
        } else {
            populatorBatch.add(update);
        }
    }
    if (useUpdater) {
        updater.close();
    } else {
        populator.add(populatorBatch, NULL);
    }
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 65 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NativeNonUniqueIndexPopulatorTest method shouldSampleUpdatesIfConfiguredForOnlineSampling.

@Test
void shouldSampleUpdatesIfConfiguredForOnlineSampling() throws Exception {
    // GIVEN
    try {
        populator.create();
        ValueIndexEntryUpdate<IndexDescriptor>[] scanUpdates = valueCreatorUtil.someUpdates(random);
        populator.add(asList(scanUpdates), NULL);
        Iterator<ValueIndexEntryUpdate<IndexDescriptor>> generator = valueCreatorUtil.randomUpdateGenerator(random);
        Value[] updates = new Value[5];
        updates[0] = generator.next().values()[0];
        updates[1] = generator.next().values()[0];
        updates[2] = updates[1];
        updates[3] = generator.next().values()[0];
        updates[4] = updates[3];
        try (IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
            long nodeId = 1000;
            for (Value value : updates) {
                ValueIndexEntryUpdate<IndexDescriptor> update = valueCreatorUtil.add(nodeId++, value);
                updater.process(update);
            }
        }
        // WHEN
        populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        IndexSample sample = populator.sample(NULL);
        // THEN
        assertEquals(scanUpdates.length, sample.sampleSize());
        assertEquals(countUniqueValues(scanUpdates), sample.uniqueValues());
        assertEquals(scanUpdates.length, sample.indexSize());
        assertEquals(updates.length, sample.updates());
    } finally {
        populator.close(true, NULL);
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Aggregations

IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)404 Test (org.junit.jupiter.api.Test)231 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)81 Value (org.neo4j.values.storable.Value)43 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)33 ArrayList (java.util.ArrayList)31 Transaction (org.neo4j.graphdb.Transaction)31 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)31 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)30 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)30 TokenRead (org.neo4j.internal.kernel.api.TokenRead)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)26 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)25 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)23 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)23 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)22 KernelException (org.neo4j.exceptions.KernelException)20