Search in sources :

Example 86 with NodeCursor

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

the class LargeNodeCursorTestBase 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 87 with NodeCursor

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

the class LargeNodeCursorTestBase 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 88 with NodeCursor

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

the class NodeTransactionStateTestBase method shouldSeeNewNodePropertyInTransaction.

@Test
void shouldSeeNewNodePropertyInTransaction() throws Exception {
    long nodeId;
    String propKey1 = "prop1";
    String propKey2 = "prop2";
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        int prop1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
        int prop2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, prop1, stringValue("hello")));
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, prop2, stringValue("world")));
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor property = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(nodeId, node);
            assertTrue(node.next(), "should access node");
            node.properties(property);
            IntObjectHashMap<Value> foundProperties = IntObjectHashMap.newMap();
            while (property.next()) {
                assertNull(foundProperties.put(property.propertyKey(), property.propertyValue()), "should only find each property once");
            }
            assertThat(foundProperties).hasSize(2);
            assertThat(foundProperties.get(prop1)).isEqualTo(stringValue("hello"));
            assertThat(foundProperties.get(prop2)).isEqualTo(stringValue("world"));
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.longValue(org.neo4j.values.storable.Values.longValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 89 with NodeCursor

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

the class KernelReadTracerTest method shouldTraceSingleNode.

@Test
void shouldTraceSingleNode() {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (NodeCursor cursor = cursors.allocateNodeCursor(NULL)) {
        // when
        cursor.setTracer(tracer);
        read.singleNode(foo, cursor);
        assertTrue(cursor.next());
        tracer.assertEvents(OnNode(foo));
        read.singleNode(bar, cursor);
        assertTrue(cursor.next());
        tracer.assertEvents(OnNode(bar));
        read.singleNode(bare, cursor);
        assertTrue(cursor.next());
        tracer.assertEvents(OnNode(bare));
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 90 with NodeCursor

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

the class NodeCursorTestBase method shouldNotFindDeletedNode.

@Test
void shouldNotFindDeletedNode() {
    // given
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        // when
        read.singleNode(gone, nodes);
        // then
        assertFalse(nodes.next(), "should not access deleted node");
    }
}
Also used : 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