Search in sources :

Example 1 with IndexEntryUpdate.add

use of org.neo4j.kernel.api.index.IndexEntryUpdate.add in project neo4j by neo4j.

the class SimpleIndexPopulatorCompatibility method shouldApplyUpdatesIdempotently.

@Test
public void shouldApplyUpdatesIdempotently() throws Exception {
    // GIVEN
    IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.empty());
    IndexPopulator populator = indexProvider.getPopulator(17, descriptor, indexSamplingConfig);
    populator.create();
    populator.configureSampling(true);
    long nodeId = 1;
    final String propertyValue = "value1";
    PropertyAccessor propertyAccessor = (nodeId1, propertyKeyId) -> Property.stringProperty(propertyKeyId, propertyValue);
    // this update (using add())...
    populator.add(singletonList(IndexEntryUpdate.add(nodeId, descriptor.schema(), propertyValue)));
    // ...is the same as this update (using update())
    try (IndexUpdater updater = populator.newPopulatingUpdater(propertyAccessor)) {
        updater.process(add(nodeId, descriptor.schema(), propertyValue));
    }
    populator.close(true);
    // then
    IndexAccessor accessor = indexProvider.getOnlineAccessor(17, descriptor, indexSamplingConfig);
    try (IndexReader reader = accessor.newReader()) {
        int propertyKeyId = descriptor.schema().getPropertyId();
        PrimitiveLongIterator nodes = reader.query(IndexQuery.exact(propertyKeyId, propertyValue));
        assertEquals(asSet(1L), PrimitiveLongCollections.toSet(nodes));
    }
    accessor.close();
}
Also used : Arrays(java.util.Arrays) Config(org.neo4j.kernel.configuration.Config) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) Test(org.junit.Test) Property(org.neo4j.kernel.api.properties.Property) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Collections.singletonList(java.util.Collections.singletonList) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Ignore(org.junit.Ignore) IndexEntryUpdate.add(org.neo4j.kernel.api.index.IndexEntryUpdate.add) FAILED(org.neo4j.kernel.api.index.InternalIndexState.FAILED) Assert.fail(org.junit.Assert.fail) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) Assert.assertEquals(org.junit.Assert.assertEquals) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Aggregations

Arrays (java.util.Arrays)1 Collections.singletonList (java.util.Collections.singletonList)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.fail (org.junit.Assert.fail)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 PrimitiveLongCollections (org.neo4j.collection.primitive.PrimitiveLongCollections)1 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)1 Iterators.asSet (org.neo4j.helpers.collection.Iterators.asSet)1 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)1 IndexEntryUpdate.add (org.neo4j.kernel.api.index.IndexEntryUpdate.add)1 FAILED (org.neo4j.kernel.api.index.InternalIndexState.FAILED)1 Property (org.neo4j.kernel.api.properties.Property)1 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)1 OrderedPropertyValues (org.neo4j.kernel.api.schema_new.OrderedPropertyValues)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 NewIndexDescriptorFactory (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory)1 Config (org.neo4j.kernel.configuration.Config)1 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)1 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)1