use of org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache.GroupVisitor in project neo4j by neo4j.
the class NodeRelationshipCacheTest method shouldKeepNextGroupIdForNextRound.
@Test
public void shouldKeepNextGroupIdForNextRound() throws Exception {
// GIVEN
cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 100, base);
long nodeId = 0;
cache.setHighNodeId(nodeId + 1);
cache.incrementCount(nodeId);
GroupVisitor groupVisitor = mock(GroupVisitor.class);
when(groupVisitor.visit(anyLong(), anyLong(), anyLong(), anyLong(), anyLong())).thenReturn(1L, 2L, 3L);
long firstRelationshipGroupId;
{
// WHEN importing the first type
long relationshipId = 10;
cache.getAndPutRelationship(nodeId, OUTGOING, relationshipId, true);
firstRelationshipGroupId = cache.getFirstRel(nodeId, groupVisitor);
// THEN
assertEquals(1L, firstRelationshipGroupId);
verify(groupVisitor).visit(nodeId, -1L, relationshipId, -1L, -1L);
// Also simulate going back again ("clearing" of the cache requires this)
cache.setForwardScan(false);
cache.getAndPutRelationship(nodeId, OUTGOING, relationshipId, false);
cache.setForwardScan(true);
}
long secondRelationshipGroupId;
{
// WHEN importing the second type
long relationshipId = 11;
cache.getAndPutRelationship(nodeId, INCOMING, relationshipId, true);
secondRelationshipGroupId = cache.getFirstRel(nodeId, groupVisitor);
// THEN
assertEquals(2L, secondRelationshipGroupId);
verify(groupVisitor).visit(nodeId, firstRelationshipGroupId, -1, relationshipId, -1L);
// Also simulate going back again ("clearing" of the cache requires this)
cache.setForwardScan(false);
cache.getAndPutRelationship(nodeId, OUTGOING, relationshipId, false);
cache.setForwardScan(true);
}
{
// WHEN importing the third type
long relationshipId = 10;
cache.getAndPutRelationship(nodeId, BOTH, relationshipId, true);
long thirdRelationshipGroupId = cache.getFirstRel(nodeId, groupVisitor);
assertEquals(3L, thirdRelationshipGroupId);
verify(groupVisitor).visit(nodeId, secondRelationshipGroupId, -1L, -1L, relationshipId);
}
}
use of org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache.GroupVisitor in project neo4j by neo4j.
the class NodeRelationshipCacheTest method shouldObserveFirstRelationshipAsEmptyInEachDirection.
@Test
public void shouldObserveFirstRelationshipAsEmptyInEachDirection() throws Exception {
// GIVEN
cache = new NodeRelationshipCache(NumberArrayFactory.AUTO, 1, 100, base);
int nodes = 100;
Direction[] directions = Direction.values();
GroupVisitor groupVisitor = mock(GroupVisitor.class);
cache.setForwardScan(true);
cache.setHighNodeId(nodes + 1);
for (int i = 0; i < nodes; i++) {
assertEquals(-1L, cache.getFirstRel(nodes, groupVisitor));
cache.incrementCount(i);
long previous = cache.getAndPutRelationship(i, directions[i % directions.length], random.nextInt(1_000_000), true);
assertEquals(-1L, previous);
}
// WHEN
cache.setForwardScan(false);
for (int i = 0; i < nodes; i++) {
long previous = cache.getAndPutRelationship(i, directions[i % directions.length], random.nextInt(1_000_000), false);
assertEquals(-1L, previous);
}
// THEN
cache.setForwardScan(true);
for (int i = 0; i < nodes; i++) {
assertEquals(-1L, cache.getFirstRel(nodes, groupVisitor));
}
}
Aggregations