Search in sources :

Example 81 with NodeCursor

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

the class NodeCursorTestBase method shouldNotAccessNegativeReferences.

// This is functionality which is only required for the hacky db.schema not to leak real data
@Test
void shouldNotAccessNegativeReferences() {
    // given
    try (NodeCursor node = cursors.allocateNodeCursor(NULL)) {
        // when
        read.singleNode(-2L, node);
        // then
        assertFalse(node.next(), "should not access negative reference node");
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 82 with NodeCursor

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

the class NodeCursorTestBase method shouldScanNodes.

@Test
void shouldScanNodes() {
    // given
    List<Long> ids = new ArrayList<>();
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        // when
        read.allNodesScan(nodes);
        while (nodes.next()) {
            ids.add(nodes.nodeReference());
        }
    }
    // then
    assertEquals(NODE_IDS, ids);
}
Also used : ArrayList(java.util.ArrayList) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 83 with NodeCursor

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

the class KernelReadTracerTxStateTest method shouldTraceAllNodesScan.

@Test
void shouldTraceAllNodesScan() throws Exception {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (KernelTransaction tx = beginTransaction();
        NodeCursor cursor = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
        tx.dataWrite().nodeCreate();
        tx.dataWrite().nodeCreate();
        // when
        cursor.setTracer(tracer);
        tx.dataRead().allNodesScan(cursor);
        tracer.assertEvents(ON_ALL_NODES_SCAN);
        assertTrue(cursor.next());
        tracer.assertEvents(OnNode(cursor.nodeReference()));
        assertTrue(cursor.next());
        tracer.assertEvents(OnNode(cursor.nodeReference()));
        assertFalse(cursor.next());
        tracer.assertEvents();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 84 with NodeCursor

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

the class KernelReadTracerTxStateTest method shouldTraceRelationshipTraversal.

@Test
void shouldTraceRelationshipTraversal() throws Exception {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (KernelTransaction tx = beginTransaction();
        NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
        RelationshipTraversalCursor cursor = tx.cursors().allocateRelationshipTraversalCursor(tx.cursorContext())) {
        long n1 = tx.dataWrite().nodeCreate();
        long n2 = tx.dataWrite().nodeCreate();
        long r = tx.dataWrite().relationshipCreate(n1, tx.token().relationshipTypeGetOrCreateForName("R"), n2);
        // when
        cursor.setTracer(tracer);
        tx.dataRead().singleNode(n1, nodeCursor);
        assertTrue(nodeCursor.next());
        nodeCursor.relationships(cursor, ALL_RELATIONSHIPS);
        assertTrue(cursor.next());
        tracer.assertEvents(OnRelationship(r));
        assertFalse(cursor.next());
        tracer.assertEvents();
    }
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 85 with NodeCursor

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

the class KernelReadTracerTxStateTest method shouldTracePropertyAccess.

@Test
void shouldTracePropertyAccess() throws Exception {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (KernelTransaction tx = beginTransaction();
        NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
        PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
        long n = tx.dataWrite().nodeCreate();
        int name = tx.token().propertyKey("name");
        tx.dataWrite().nodeSetProperty(n, name, Values.stringValue("Bosse"));
        // when
        propertyCursor.setTracer(tracer);
        tx.dataRead().singleNode(n, nodeCursor);
        assertTrue(nodeCursor.next());
        nodeCursor.properties(propertyCursor);
        assertTrue(propertyCursor.next());
        tracer.assertEvents(OnProperty(name));
        assertFalse(propertyCursor.next());
        tracer.assertEvents();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

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