Search in sources :

Example 11 with NodeCursor

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

the class NodeTransactionStateTestBase method shouldSeeNodeInTransaction.

@Test
void shouldSeeNodeInTransaction() throws Exception {
    long nodeId;
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
            tx.dataRead().singleNode(nodeId, node);
            assertTrue(node.next(), "should access node");
            assertEquals(nodeId, node.nodeReference());
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertEquals(nodeId, tx.getNodeById(nodeId).getId());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 12 with NodeCursor

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

the class NodeTransactionStateTestBase method shouldSeeNewLabeledNodeInTransaction.

@Test
void shouldSeeNewLabeledNodeInTransaction() throws Exception {
    long nodeId;
    int labelId;
    final String labelName = "Town";
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        labelId = tx.token().labelGetOrCreateForName(labelName);
        tx.dataWrite().nodeAddLabel(nodeId, labelId);
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
            tx.dataRead().singleNode(nodeId, node);
            assertTrue(node.next(), "should access node");
            TokenSet labels = node.labels();
            assertEquals(1, labels.numberOfTokens());
            assertEquals(labelId, labels.token(0));
            assertTrue(node.hasLabel(labelId));
            assertFalse(node.hasLabel(labelId + 1));
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertThat(tx.getNodeById(nodeId).getLabels()).isEqualTo(Iterables.iterable(label(labelName)));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenSet(org.neo4j.internal.kernel.api.TokenSet) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 13 with NodeCursor

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

the class NodeTransactionStateTestBase method hasPropertiesShouldSeeNewlyRemovedProperties.

@Test
void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception {
    // Given
    long node;
    int prop1, prop2, prop3;
    try (KernelTransaction tx = beginTransaction()) {
        node = tx.dataWrite().nodeCreate();
        prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop1");
        prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop2");
        prop3 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop3");
        tx.dataWrite().nodeSetProperty(node, prop1, longValue(1));
        tx.dataWrite().nodeSetProperty(node, prop2, longValue(2));
        tx.dataWrite().nodeSetProperty(node, prop3, longValue(3));
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction()) {
        try (NodeCursor cursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor props = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(node, cursor);
            assertTrue(cursor.next());
            assertTrue(hasProperties(cursor, props));
            tx.dataWrite().nodeRemoveProperty(node, prop1);
            assertTrue(hasProperties(cursor, props));
            tx.dataWrite().nodeRemoveProperty(node, prop2);
            assertTrue(hasProperties(cursor, props));
            tx.dataWrite().nodeRemoveProperty(node, prop3);
            assertFalse(hasProperties(cursor, props));
        }
    }
}
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)

Example 14 with NodeCursor

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

the class NodeTransactionStateTestBase method shouldDiscoverDeletedNodeInTransaction.

@Test
void shouldDiscoverDeletedNodeInTransaction() throws Exception {
    long nodeId;
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        assertTrue(tx.dataWrite().nodeDelete(nodeId));
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
            tx.dataRead().singleNode(nodeId, node);
            assertFalse(node.next());
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 15 with NodeCursor

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

the class KernelReadTracerTest method shouldTraceLazySelectionRelationshipTraversal.

@Test
void shouldTraceLazySelectionRelationshipTraversal() {
    // 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());
        int type = token.relationshipType("HAS");
        nodeCursor.relationships(cursor, selection(type, Direction.OUTGOING));
        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 one
        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)

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