Search in sources :

Example 76 with NodeCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseFullAccessNodeCursor.

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

Example 77 with NodeCursor

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

the class NodeTransactionStateTestBase method hasPropertiesShouldSeeNewlyCreatedProperties.

@Test
void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception {
    // Given
    long node;
    try (KernelTransaction tx = beginTransaction()) {
        node = tx.dataWrite().nodeCreate();
        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());
            assertFalse(hasProperties(cursor, props));
            tx.dataWrite().nodeSetProperty(node, tx.tokenWrite().propertyKeyGetOrCreateForName("prop"), stringValue("foo"));
            assertTrue(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 78 with NodeCursor

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

the class NodeTransactionStateTestBase method shouldSeeRemovedThenAddedPropertyInTransaction.

@Test
void shouldSeeRemovedThenAddedPropertyInTransaction() throws Exception {
    // Given
    long nodeId;
    String propKey = "prop1";
    int propToken;
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken, stringValue("hello")));
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        assertEquals(tx.dataWrite().nodeRemoveProperty(nodeId, propToken), stringValue("hello"));
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken, 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);
            assertTrue(property.next());
            assertEquals(propToken, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("world"));
            assertFalse(property.next(), "should not find any properties");
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertThat(tx.getNodeById(nodeId).getProperty(propKey)).isEqualTo("world");
    }
}
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 79 with NodeCursor

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

the class KernelReadTracerTest method shouldStopAndRestartTracing.

@Test
void shouldStopAndRestartTracing() {
    // 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));
        cursor.removeTracer();
        read.singleNode(bar, cursor);
        assertTrue(cursor.next());
        tracer.assertEvents();
        cursor.setTracer(tracer);
        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 80 with NodeCursor

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

the class KernelReadTracerTest method shouldTraceAllNodesScan.

@Test
void shouldTraceAllNodesScan() {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    List<TraceEvent> expectedEvents = new ArrayList<>();
    expectedEvents.add(ON_ALL_NODES_SCAN);
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        // when
        nodes.setTracer(tracer);
        read.allNodesScan(nodes);
        while (nodes.next()) {
            expectedEvents.add(OnNode(nodes.nodeReference()));
        }
    }
    // then
    tracer.assertEvents(expectedEvents);
}
Also used : ArrayList(java.util.ArrayList) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) TraceEvent(org.neo4j.kernel.impl.newapi.TestKernelReadTracer.TraceEvent) 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