Search in sources :

Example 31 with NodeCursor

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

the class NodeCursorTestBase method shouldAccessNodesByReference.

@Test
void shouldAccessNodesByReference() {
    // given
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        for (long id : NODE_IDS) {
            // when
            read.singleNode(id, nodes);
            // then
            assertTrue(nodes.next(), "should access defined node");
            assertEquals(id, nodes.nodeReference(), "should access the correct node");
            assertFalse(nodes.next(), "should only access a single node");
        }
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 32 with NodeCursor

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

the class NodeCursorTestBase method shouldReadLabels.

@Test
void shouldReadLabels() {
    // given
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        TokenSet labels;
        // when
        read.singleNode(foo, nodes);
        // then
        assertTrue(nodes.next(), "should access defined node");
        labels = nodes.labels();
        assertEquals(1, labels.numberOfTokens(), "number of labels");
        int fooLabel = labels.token(0);
        assertTrue(nodes.hasLabel(fooLabel));
        assertFalse(nodes.next(), "should only access a single node");
        // when
        read.singleNode(bar, nodes);
        // then
        assertTrue(nodes.next(), "should access defined node");
        labels = nodes.labels();
        assertEquals(1, labels.numberOfTokens(), "number of labels");
        int barLabel = labels.token(0);
        assertFalse(nodes.hasLabel(fooLabel));
        assertTrue(nodes.hasLabel(barLabel));
        assertFalse(nodes.next(), "should only access a single node");
        // when
        read.singleNode(baz, nodes);
        // then
        assertTrue(nodes.next(), "should access defined node");
        labels = nodes.labels();
        assertEquals(1, labels.numberOfTokens(), "number of labels");
        int bazLabel = labels.token(0);
        assertFalse(nodes.hasLabel(fooLabel));
        assertFalse(nodes.hasLabel(barLabel));
        assertTrue(nodes.hasLabel(bazLabel));
        assertFalse(nodes.next(), "should only access a single node");
        assertNotEquals(fooLabel, barLabel, "distinct labels");
        assertNotEquals(fooLabel, bazLabel, "distinct labels");
        assertNotEquals(barLabel, bazLabel, "distinct labels");
        // when
        read.singleNode(barbaz, nodes);
        // then
        assertTrue(nodes.next(), "should access defined node");
        labels = nodes.labels();
        assertEquals(2, labels.numberOfTokens(), "number of labels");
        if (labels.token(0) == barLabel) {
            assertEquals(bazLabel, labels.token(1));
        } else {
            assertEquals(bazLabel, labels.token(0));
            assertEquals(barLabel, labels.token(1));
        }
        assertFalse(nodes.hasLabel(fooLabel));
        assertTrue(nodes.hasLabel(barLabel));
        assertTrue(nodes.hasLabel(bazLabel));
        assertFalse(nodes.next(), "should only access a single node");
        // when
        read.singleNode(bare, nodes);
        // then
        assertTrue(nodes.next(), "should access defined node");
        labels = nodes.labels();
        assertEquals(0, labels.numberOfTokens(), "number of labels");
        assertFalse(nodes.hasLabel(fooLabel));
        assertFalse(nodes.hasLabel(barLabel));
        assertFalse(nodes.hasLabel(bazLabel));
        assertFalse(nodes.next(), "should only access a single node");
    }
}
Also used : TokenSet(org.neo4j.internal.kernel.api.TokenSet) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 33 with NodeCursor

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

the class NodeCursorTestBase method notFindNoIdNode.

@Test
void notFindNoIdNode() throws InvalidTransactionTypeKernelException {
    // given a non-commited node created in transaction
    long nodeId = tx.dataWrite().nodeCreate();
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        // when
        read.singleNode(-1, nodes);
        // then
        assertFalse(nodes.next(), "should not access any node");
    }
    // remove temporarily created node.
    tx.dataWrite().nodeDelete(nodeId);
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 34 with NodeCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseFullAccessPropertyCursor.

@Test
void shouldReuseFullAccessPropertyCursor() {
    NodeCursor node = cursors.allocateNodeCursor(NULL);
    PropertyCursor c1 = cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE);
    read.singleNode(propNode, node);
    node.next();
    node.properties(c1);
    node.close();
    c1.close();
    PropertyCursor c2 = cursors.allocateFullAccessPropertyCursor(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)

Example 35 with NodeCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseFullAccessRelationshipTraversalCursor.

@Test
void shouldReuseFullAccessRelationshipTraversalCursor() {
    NodeCursor node = cursors.allocateNodeCursor(NULL);
    RelationshipTraversalCursor c1 = cursors.allocateFullAccessRelationshipTraversalCursor(NULL);
    read.singleNode(startNode, node);
    node.next();
    node.relationships(c1, ALL_RELATIONSHIPS);
    node.close();
    c1.close();
    RelationshipTraversalCursor c2 = cursors.allocateFullAccessRelationshipTraversalCursor(NULL);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) 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