Search in sources :

Example 1 with INCOMING

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();
}
Also used : RelationshipModifications(org.neo4j.storageengine.api.txstate.RelationshipModifications) RandomExtension(org.neo4j.test.extension.RandomExtension) OUTGOING(org.neo4j.storageengine.api.RelationshipDirection.OUTGOING) Direction(org.neo4j.graphdb.Direction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PrimitiveLongCollections.asArray(org.neo4j.collection.PrimitiveLongCollections.asArray) MutableIntObjectMap(org.eclipse.collections.api.map.primitive.MutableIntObjectMap) HashMap(java.util.HashMap) Function(java.util.function.Function) RelationshipDirection(org.neo4j.storageengine.api.RelationshipDirection) IntObjectMaps(org.eclipse.collections.impl.factory.primitive.IntObjectMaps) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Inject(org.neo4j.test.extension.Inject) RandomRule(org.neo4j.test.rule.RandomRule) Map(java.util.Map) ADD(org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.DiffStrategy.ADD) INCOMING(org.neo4j.storageengine.api.RelationshipDirection.INCOMING) LOOP(org.neo4j.storageengine.api.RelationshipDirection.LOOP) REMOVE(org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.DiffStrategy.REMOVE) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) Test(org.junit.jupiter.api.Test) LongIterator(org.eclipse.collections.api.iterator.LongIterator) RelationshipChangesForNode.createRelationshipChangesForNode(org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.createRelationshipChangesForNode) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) LongSets(org.eclipse.collections.impl.factory.primitive.LongSets) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipDirection(org.neo4j.storageengine.api.RelationshipDirection) HashMap(java.util.HashMap) RelationshipChangesForNode.createRelationshipChangesForNode(org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.createRelationshipChangesForNode) MutableIntObjectMap(org.eclipse.collections.api.map.primitive.MutableIntObjectMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 LongIterator (org.eclipse.collections.api.iterator.LongIterator)1 MutableIntObjectMap (org.eclipse.collections.api.map.primitive.MutableIntObjectMap)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 IntObjectMaps (org.eclipse.collections.impl.factory.primitive.IntObjectMaps)1 LongSets (org.eclipse.collections.impl.factory.primitive.LongSets)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 PrimitiveLongCollections.asArray (org.neo4j.collection.PrimitiveLongCollections.asArray)1 Direction (org.neo4j.graphdb.Direction)1 ADD (org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.DiffStrategy.ADD)1 REMOVE (org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.DiffStrategy.REMOVE)1 RelationshipChangesForNode.createRelationshipChangesForNode (org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.createRelationshipChangesForNode)1 INSTANCE (org.neo4j.memory.EmptyMemoryTracker.INSTANCE)1 RelationshipDirection (org.neo4j.storageengine.api.RelationshipDirection)1 INCOMING (org.neo4j.storageengine.api.RelationshipDirection.INCOMING)1 LOOP (org.neo4j.storageengine.api.RelationshipDirection.LOOP)1