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);
}
}
}
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);
}
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);
}
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();
}
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));
}
Aggregations