Search in sources :

Example 1 with NodeChangeVisitor

use of org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache.NodeChangeVisitor in project neo4j by neo4j.

the class NodeRelationshipCacheTest method shouldVisitChangedNodes.

@Test
public void shouldVisitChangedNodes() throws Exception {
    // GIVEN
    int nodes = 10;
    cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 2, 100, base);
    cache.setHighNodeId(nodes);
    for (long nodeId = 0; nodeId < nodes; nodeId++) {
        cache.incrementCount(nodeId);
        if (random.nextBoolean()) {
            cache.incrementCount(nodeId);
        }
    }
    PrimitiveLongSet keySparseChanged = Primitive.longSet(nodes);
    PrimitiveLongSet keyDenseChanged = Primitive.longSet(nodes);
    for (int i = 0; i < nodes / 2; i++) {
        long nodeId = random.nextLong(nodes);
        cache.getAndPutRelationship(nodeId, Direction.OUTGOING, random.nextLong(1_000_000), false);
        boolean dense = cache.isDense(nodeId);
        (dense ? keyDenseChanged : keySparseChanged).add(nodeId);
    }
    {
        // WHEN (sparse)
        NodeChangeVisitor visitor = (nodeId, array) -> {
            // THEN (sparse)
            assertTrue("Unexpected sparse change reported for " + nodeId, keySparseChanged.remove(nodeId));
        };
        cache.visitChangedNodes(visitor, false);
        assertTrue("There was " + keySparseChanged.size() + " expected sparse changes that weren't reported", keySparseChanged.isEmpty());
    }
    {
        // WHEN (dense)
        NodeChangeVisitor visitor = (nodeId, array) -> {
            // THEN (dense)
            assertTrue("Unexpected dense change reported for " + nodeId, keyDenseChanged.remove(nodeId));
        };
        cache.visitChangedNodes(visitor, true);
        assertTrue("There was " + keyDenseChanged.size() + " expected dense changes that weren reported", keyDenseChanged.isEmpty());
    }
}
Also used : NodeChangeVisitor(org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache.NodeChangeVisitor) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)1 NodeChangeVisitor (org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache.NodeChangeVisitor)1