Search in sources :

Example 26 with NodeCursor

use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.

the class ParallelNodeCursorTestBase method shouldScanAllNodesFromMultipleThreads.

@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<NodeCursor> scan = read.allNodesScan();
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, 32));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, 32));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, 32));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, 32));
        // then
        LongList ids1 = future1.get();
        LongList ids2 = future2.get();
        LongList ids3 = future3.get();
        LongList ids4 = future4.get();
        TestUtils.assertDistinct(ids1, ids2, ids3, ids4);
        LongList concat = TestUtils.concat(ids1, ids2, ids3, ids4).toSortedList();
        assertEquals(NODE_IDS, concat);
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Test(org.junit.jupiter.api.Test)

Example 27 with NodeCursor

use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.

the class ParallelNodeCursorTransactionStateTestBase method scanShouldSeeAddedNodes.

@Test
void scanShouldSeeAddedNodes() throws Exception {
    int size = 100;
    MutableLongSet existing = createNodes(size);
    MutableLongSet added = LongSets.mutable.empty();
    try (KernelTransaction tx = beginTransaction()) {
        for (int i = 0; i < size; i++) {
            added.add(tx.dataWrite().nodeCreate());
        }
        try (NodeCursor cursor = tx.cursors().allocateNodeCursor(NULL)) {
            Scan<NodeCursor> scan = tx.dataRead().allNodesScan();
            MutableLongSet seen = LongSets.mutable.empty();
            while (scan.reserveBatch(cursor, 17)) {
                while (cursor.next()) {
                    long nodeId = cursor.nodeReference();
                    assertTrue(seen.add(nodeId));
                    assertTrue(existing.remove(nodeId) || added.remove(nodeId));
                }
            }
            // make sure we have seen all nodes
            assertTrue(existing.isEmpty());
            assertTrue(added.isEmpty());
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 28 with NodeCursor

use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.

the class KernelReadTracerTest method shouldTraceRelationshipTraversal.

@Test
void shouldTraceRelationshipTraversal() {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (NodeCursor nodeCursor = cursors.allocateNodeCursor(NULL);
        RelationshipTraversalCursor cursor = cursors.allocateRelationshipTraversalCursor(NULL)) {
        // when
        cursor.setTracer(tracer);
        read.singleNode(foo, nodeCursor);
        assertTrue(nodeCursor.next());
        nodeCursor.relationships(cursor, ALL_RELATIONSHIPS);
        assertTrue(cursor.next());
        tracer.assertEvents(OnRelationship(cursor.relationshipReference()));
        cursor.removeTracer();
        assertTrue(cursor.next());
        tracer.assertEvents();
        cursor.setTracer(tracer);
        assertTrue(cursor.next());
        tracer.assertEvents(OnRelationship(cursor.relationshipReference()));
        // skip last two
        assertTrue(cursor.next());
        assertTrue(cursor.next());
        tracer.clear();
        assertFalse(cursor.next());
        tracer.assertEvents();
    }
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 29 with NodeCursor

use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.

the class ManagedTestCursors method allocateFullAccessNodeCursor.

@Override
public NodeCursor allocateFullAccessNodeCursor(CursorContext cursorContext) {
    NodeCursor n = cursors.allocateFullAccessNodeCursor(cursorContext);
    allCursors.add(n);
    return n;
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor)

Example 30 with NodeCursor

use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.

the class ManagedTestCursors method allocateNodeCursor.

@Override
public NodeCursor allocateNodeCursor(CursorContext cursorContext) {
    NodeCursor n = cursors.allocateNodeCursor(cursorContext);
    allCursors.add(n);
    return n;
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor)

Aggregations

NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)113 Test (org.junit.jupiter.api.Test)85 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)62 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)30 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)26 Read (org.neo4j.internal.kernel.api.Read)20 Write (org.neo4j.internal.kernel.api.Write)17 Degrees (org.neo4j.storageengine.api.Degrees)11 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)10 ArrayList (java.util.ArrayList)8 ExecutorService (java.util.concurrent.ExecutorService)7 LongList (org.eclipse.collections.api.list.primitive.LongList)7 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)7 CachingExpandInto (org.neo4j.internal.kernel.api.helpers.CachingExpandInto)6 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)5 RelationshipSelection (org.neo4j.storageengine.api.RelationshipSelection)5 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)4 Future (java.util.concurrent.Future)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)3 NotFoundException (org.neo4j.graphdb.NotFoundException)3