Search in sources :

Example 26 with EntityUpdates

use of org.neo4j.storageengine.api.EntityUpdates in project neo4j by neo4j.

the class MultiIndexPopulationConcurrentUpdatesIT method applyConcurrentChangesToPopulatedIndex.

@ParameterizedTest
@MethodSource("parameters")
void applyConcurrentChangesToPopulatedIndex(GraphDatabaseSettings.SchemaIndex schemaIndex) throws Throwable {
    List<EntityUpdates> updates = new ArrayList<>(2);
    updates.add(EntityUpdates.forEntity(color2.getId(), false).withTokens(id(COLOR_LABEL)).changed(propertyId, Values.of("green"), Values.of("pink")).build());
    updates.add(EntityUpdates.forEntity(car2.getId(), false).withTokens(id(CAR_LABEL)).changed(propertyId, Values.of("Ford"), Values.of("SAAB")).build());
    launchCustomIndexPopulation(schemaIndex, labelsNameIdMap, propertyId, new UpdateGenerator(updates));
    waitAndActivateIndexes(labelsNameIdMap, propertyId);
    try (Transaction tx = db.beginTx()) {
        Integer colorLabelId = labelsNameIdMap.get(COLOR_LABEL);
        Integer carLabelId = labelsNameIdMap.get(CAR_LABEL);
        try (var indexReader = getIndexReader(propertyId, colorLabelId)) {
            assertThat(indexReader.countIndexedEntities(color2.getId(), NULL, new int[] { propertyId }, Values.of("green"))).as(format("Should be deleted by concurrent change. Reader is: %s, ", indexReader)).isEqualTo(0);
        }
        try (var indexReader = getIndexReader(propertyId, colorLabelId)) {
            assertThat(indexReader.countIndexedEntities(color2.getId(), NULL, new int[] { propertyId }, Values.of("pink"))).as("Should be updated by concurrent change.").isEqualTo(1);
        }
        try (var indexReader = getIndexReader(propertyId, carLabelId)) {
            assertThat(indexReader.countIndexedEntities(car2.getId(), NULL, new int[] { propertyId }, Values.of("SAAB"))).as("Should be added by concurrent change.").isEqualTo(1);
        }
    }
}
Also used : EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ArrayList(java.util.ArrayList) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with EntityUpdates

use of org.neo4j.storageengine.api.EntityUpdates in project neo4j by neo4j.

the class EntityValueUpdatesTest method useProvidedCursorForPropertiesOnRelationshipLoad.

@Test
void useProvidedCursorForPropertiesOnRelationshipLoad() {
    var cursorContext = mock(CursorContext.class);
    var relationshipCursor = mock(StorageRelationshipScanCursor.class);
    var storageReader = mock(StorageReader.class, RETURNS_MOCKS);
    when(relationshipCursor.hasProperties()).thenReturn(true);
    when(relationshipCursor.next()).thenReturn(true);
    when(storageReader.allocateRelationshipScanCursor(any())).thenReturn(relationshipCursor);
    EntityUpdates updates = EntityUpdates.forEntity(ENTITY_ID, false).withTokens(EMPTY).withTokensAfter(TOKEN).build();
    updates.valueUpdatesForIndexKeys(NODE_INDEXES, storageReader, EntityType.RELATIONSHIP, cursorContext, INSTANCE);
    verify(storageReader).allocateRelationshipScanCursor(cursorContext);
    verify(storageReader).allocatePropertyCursor(cursorContext, INSTANCE);
}
Also used : EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with EntityUpdates

use of org.neo4j.storageengine.api.EntityUpdates in project neo4j by neo4j.

the class EntityValueUpdatesTest method useProvidedCursorForPropertiesOnNodesLoad.

@Test
void useProvidedCursorForPropertiesOnNodesLoad() {
    var cursorContext = mock(CursorContext.class);
    var nodeCursor = mock(StorageNodeCursor.class);
    var storageReader = mock(StorageReader.class, RETURNS_MOCKS);
    when(nodeCursor.hasProperties()).thenReturn(true);
    when(nodeCursor.next()).thenReturn(true);
    when(storageReader.allocateNodeCursor(any())).thenReturn(nodeCursor);
    EntityUpdates updates = EntityUpdates.forEntity(ENTITY_ID, false).withTokens(EMPTY).withTokensAfter(TOKEN).build();
    updates.valueUpdatesForIndexKeys(NODE_INDEXES, storageReader, EntityType.NODE, cursorContext, INSTANCE);
    verify(storageReader).allocateNodeCursor(cursorContext);
    verify(storageReader).allocatePropertyCursor(cursorContext, INSTANCE);
}
Also used : EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with EntityUpdates

use of org.neo4j.storageengine.api.EntityUpdates in project neo4j by neo4j.

the class EntityValueUpdatesTest method shouldNotGenerateUpdateForMultipleExistingPropertiesAndTokens.

@ParameterizedTest
@EnumSource(Entity.class)
void shouldNotGenerateUpdateForMultipleExistingPropertiesAndTokens(Entity entity) {
    // When
    EntityUpdates updates = EntityUpdates.forEntity(ENTITY_ID, false).withTokens(TOKEN).existing(PROPERTY_KEY_ID_1, Values.of("Neo")).existing(PROPERTY_KEY_ID_2, Values.of(100L)).existing(PROPERTY_KEY_ID_3, Values.pointValue(CoordinateReferenceSystem.WGS84, 12.3, 45.6)).build();
    // Then
    assertThat(updates.valueUpdatesForIndexKeys(entity.indexes(), assertNoLoading(), entity.type(), NULL, INSTANCE)).isEmpty();
}
Also used : EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with EntityUpdates

use of org.neo4j.storageengine.api.EntityUpdates in project neo4j by neo4j.

the class EntityValueUpdatesTest method shouldGenerateUpdateWhenAddingMultipleTokensForNonSchemaIndex.

@Test
void shouldGenerateUpdateWhenAddingMultipleTokensForNonSchemaIndex() {
    // When
    EntityUpdates updates = EntityUpdates.forEntity(ENTITY_ID, false).withTokens(EMPTY).withTokensAfter(ALL_TOKENS).build();
    // Then
    assertThat(updates.valueUpdatesForIndexKeys(singleton(NON_SCHEMA_NODE_INDEX), propertyLoader(PROPERTY_1, PROPERTY_2, PROPERTY_3), EntityType.NODE, NULL, INSTANCE)).contains(IndexEntryUpdate.add(ENTITY_ID, NON_SCHEMA_NODE_INDEX, VALUES_123));
}
Also used : EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EntityUpdates (org.neo4j.storageengine.api.EntityUpdates)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)41 Test (org.junit.jupiter.api.Test)22 EnumSource (org.junit.jupiter.params.provider.EnumSource)21 Value (org.neo4j.values.storable.Value)6 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)4 ArrayList (java.util.ArrayList)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 Transaction (org.neo4j.graphdb.Transaction)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3 PropertyKeyValue (org.neo4j.storageengine.api.PropertyKeyValue)3 StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)2 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)1 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)1 StoragePropertyCursor (org.neo4j.storageengine.api.StoragePropertyCursor)1 StorageReader (org.neo4j.storageengine.api.StorageReader)1 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)1