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