Search in sources :

Example 71 with NodeCursor

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

the class RandomRelationshipTraversalCursorTestBase method shouldManageRandomTraversals.

@Test
void shouldManageRandomTraversals() {
    // given
    try (NodeCursor node = cursors.allocateNodeCursor(NULL);
        RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor(NULL)) {
        for (int i = 0; i < N_TRAVERSALS; i++) {
            // when
            long nodeId = NODE_IDS.get(RANDOM.nextInt(N_NODES));
            read.singleNode(nodeId, node);
            assertTrue(node.next(), "access root node");
            int[] types = node.relationshipTypes();
            assertFalse(node.next(), "single root");
            // then
            for (int type : types) {
                node.relationships(relationship, selection(type, INCOMING));
                while (relationship.next()) {
                    assertEquals(nodeId, relationship.originNodeReference(), "incoming origin");
                    relationship.otherNode(node);
                }
                node.relationships(relationship, selection(type, OUTGOING));
                while (relationship.next()) {
                    assertEquals(nodeId, relationship.originNodeReference(), "outgoing origin");
                    relationship.otherNode(node);
                }
            }
        }
    } catch (Throwable t) {
        throw new RuntimeException("Failed with random seed " + SEED, t);
    }
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 72 with NodeCursor

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

the class LabelsAcceptanceTest method shouldAllowManyLabelsAndPropertyCursor.

@Test
void shouldAllowManyLabelsAndPropertyCursor() {
    int propertyCount = 10;
    int labelCount = 15;
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = tx.createNode();
        for (int i = 0; i < propertyCount; i++) {
            node.setProperty("foo" + i, "bar");
        }
        for (int i = 0; i < labelCount; i++) {
            node.addLabel(label("label" + i));
        }
        tx.commit();
    }
    Set<Integer> seenProperties = new HashSet<>();
    Set<Integer> seenLabels = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        try (NodeCursor nodes = ktx.cursors().allocateNodeCursor(CursorContext.NULL);
            PropertyCursor propertyCursor = ktx.cursors().allocatePropertyCursor(CursorContext.NULL, INSTANCE)) {
            ktx.dataRead().singleNode(node.getId(), nodes);
            while (nodes.next()) {
                nodes.properties(propertyCursor);
                while (propertyCursor.next()) {
                    seenProperties.add(propertyCursor.propertyKey());
                }
                TokenSet labels = nodes.labels();
                for (int i = 0; i < labels.numberOfTokens(); i++) {
                    seenLabels.add(labels.token(i));
                }
            }
        }
        tx.commit();
    }
    assertEquals(propertyCount, seenProperties.size());
    assertEquals(labelCount, seenLabels.size());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenSet(org.neo4j.internal.kernel.api.TokenSet) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 73 with NodeCursor

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

the class DeepRelationshipTraversalCursorTestBase method shouldTraverseTreeOfDepthThree.

@Test
void shouldTraverseTreeOfDepthThree() {
    try (NodeCursor node = cursors.allocateNodeCursor(NULL);
        RelationshipTraversalCursor relationship1 = cursors.allocateRelationshipTraversalCursor(NULL);
        RelationshipTraversalCursor relationship2 = cursors.allocateRelationshipTraversalCursor(NULL)) {
        MutableLongSet leafs = new LongHashSet();
        long total = 0;
        // when
        read.singleNode(three_root, node);
        assertTrue(node.next(), "access root node");
        node.relationships(relationship1, selection(parentRelationshipTypeId, Direction.INCOMING));
        while (relationship1.next()) {
            relationship1.otherNode(node);
            assertTrue(node.next(), "child level 1");
            node.relationships(relationship2, selection(parentRelationshipTypeId, Direction.INCOMING));
            while (relationship2.next()) {
                leafs.add(relationship2.otherNodeReference());
                total++;
            }
        }
        // then
        assertEquals(expected_total, total, "total number of leaf nodes");
        assertEquals(expected_unique, leafs.size(), "number of distinct leaf nodes");
    }
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 74 with NodeCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseNodeCursor.

@Test
void shouldReuseNodeCursor() {
    NodeCursor c1 = cursors.allocateNodeCursor(NULL);
    read.singleNode(startNode, c1);
    c1.close();
    NodeCursor c2 = cursors.allocateNodeCursor(NULL);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 75 with NodeCursor

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

the class DefaultPooledCursorsTestBase method shouldReusePropertyCursor.

@Test
void shouldReusePropertyCursor() {
    NodeCursor node = cursors.allocateNodeCursor(NULL);
    PropertyCursor c1 = cursors.allocatePropertyCursor(NULL, INSTANCE);
    read.singleNode(propNode, node);
    node.next();
    node.properties(c1);
    node.close();
    c1.close();
    PropertyCursor c2 = cursors.allocatePropertyCursor(NULL, INSTANCE);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : 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