Search in sources :

Example 1 with BOTH

use of org.neo4j.graphdb.Direction.BOTH in project neo4j by neo4j.

the class NodeRelationshipCacheTest method shouldCacheMultipleDenseNodeRelationshipHeads.

@Test
public void shouldCacheMultipleDenseNodeRelationshipHeads() {
    // GIVEN
    cache = new NodeRelationshipCache(NumberArrayFactories.HEAP, 1, INSTANCE);
    cache.setNodeCount(10);
    long nodeId = 3;
    cache.setCount(nodeId, 10, /*these do not matter ==>*/
    0, OUTGOING);
    // WHEN
    Map<Pair<Integer, Direction>, Long> firstRelationshipIds = new HashMap<>();
    int typeCount = 3;
    for (int typeId = 0, relationshipId = 0; typeId < typeCount; typeId++) {
        for (Direction direction : Direction.values()) {
            long firstRelationshipId = relationshipId++;
            cache.getAndPutRelationship(nodeId, typeId, direction, firstRelationshipId, true);
            firstRelationshipIds.put(Pair.of(typeId, direction), firstRelationshipId);
        }
    }
    AtomicInteger visitCount = new AtomicInteger();
    NodeRelationshipCache.GroupVisitor visitor = (nodeId1, typeId, out, in, loop) -> {
        visitCount.incrementAndGet();
        assertEquals(firstRelationshipIds.get(Pair.of(typeId, OUTGOING)).longValue(), out);
        assertEquals(firstRelationshipIds.get(Pair.of(typeId, INCOMING)).longValue(), in);
        assertEquals(firstRelationshipIds.get(Pair.of(typeId, BOTH)).longValue(), loop);
        return 0;
    };
    cache.getFirstRel(nodeId, visitor);
    // THEN
    assertEquals(typeCount, visitCount.get());
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Direction(org.neo4j.graphdb.Direction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) OUTGOING(org.neo4j.graphdb.Direction.OUTGOING) MutableIntObjectMap(org.eclipse.collections.api.map.primitive.MutableIntObjectMap) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) ArrayList(java.util.ArrayList) IntObjectMaps(org.eclipse.collections.impl.factory.primitive.IntObjectMaps) BOTH(org.neo4j.graphdb.Direction.BOTH) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RandomRule(org.neo4j.test.rule.RandomRule) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) After(org.junit.After) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Parameterized(org.junit.runners.Parameterized) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) INCOMING(org.neo4j.graphdb.Direction.INCOMING) Mockito.verify(org.mockito.Mockito.verify) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) List(java.util.List) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Math.max(java.lang.Math.max) Pair(org.neo4j.internal.helpers.collection.Pair) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Direction(org.neo4j.graphdb.Direction) Pair(org.neo4j.internal.helpers.collection.Pair) Test(org.junit.Test)

Aggregations

Math.max (java.lang.Math.max)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 MutableIntObjectMap (org.eclipse.collections.api.map.primitive.MutableIntObjectMap)1 MutableLongObjectMap (org.eclipse.collections.api.map.primitive.MutableLongObjectMap)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 IntObjectMaps (org.eclipse.collections.impl.factory.primitive.IntObjectMaps)1 LongObjectHashMap (org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap)1 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1