use of org.neo4j.storageengine.api.RelationshipDirection.INCOMING in project neo4j by neo4j.
the class RelationshipChangesForNodeTest method shouldVisitRelationshipIds.
@Test
void shouldVisitRelationshipIds() {
// given
RelationshipChangesForNode changes = createRelationshipChangesForNode(REMOVE, INSTANCE);
MutableIntObjectMap<Map<RelationshipDirection, MutableLongSet>> expected = IntObjectMaps.mutable.empty();
MutableLongSet allExpected = LongSets.mutable.empty();
for (int id = 0; id < 100; id++) {
int type = random.nextInt(5);
RelationshipDirection direction = random.nextBoolean() ? random.nextBoolean() ? OUTGOING : INCOMING : LOOP;
changes.addRelationship(id, type, direction);
expected.getIfAbsentPut(type, HashMap::new).computeIfAbsent(direction, d -> LongSets.mutable.empty()).add(id);
allExpected.add(id);
}
// when
MutableLongSet allChangedIds = LongSets.mutable.empty();
changes.visitIds(allChangedIds::add);
// then
assertThat(allChangedIds).isEqualTo(allExpected);
// and when
changes.visitIdsSplit(typeIds -> {
Map<RelationshipDirection, MutableLongSet> dirMap = expected.remove(typeIds.type());
visitExpectedIds(typeIds, dirMap, OUTGOING, RelationshipModifications.NodeRelationshipTypeIds::out);
visitExpectedIds(typeIds, dirMap, INCOMING, RelationshipModifications.NodeRelationshipTypeIds::in);
visitExpectedIds(typeIds, dirMap, LOOP, RelationshipModifications.NodeRelationshipTypeIds::loop);
assertThat(dirMap).isEmpty();
return false;
}, RelationshipModifications.noAdditionalDataDecorator());
assertThat(expected).isEmpty();
}
Aggregations