Search in sources :

Example 21 with NodeCursor

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

the class NodeTransactionStateTestBase method shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction.

@Test
void shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction() throws Exception {
    // Given
    long nodeId;
    String propKey1 = "prop1";
    String propKey2 = "prop2";
    int propToken1;
    int propToken2;
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        propToken1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken1, stringValue("hello")));
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        propToken2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken2, 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);
            // property 2, start with tx state
            assertTrue(property.next());
            assertEquals(propToken2, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("world"));
            // property 1, from disk
            assertTrue(property.next());
            assertEquals(propToken1, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("hello"));
            assertFalse(property.next(), "should only find two properties");
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertThat(tx.getNodeById(nodeId).getProperty(propKey1)).isEqualTo("hello");
        assertThat(tx.getNodeById(nodeId).getProperty(propKey2)).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 22 with NodeCursor

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

the class NodeTransactionStateTestBase method propertyTypeShouldBeTxStateAware.

@Test
void propertyTypeShouldBeTxStateAware() throws Exception {
    // Given
    long node;
    try (KernelTransaction tx = beginTransaction()) {
        node = tx.dataWrite().nodeCreate();
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction()) {
        try (NodeCursor nodes = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor properties = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(node, nodes);
            assertTrue(nodes.next());
            assertFalse(hasProperties(nodes, properties));
            int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
            tx.dataWrite().nodeSetProperty(node, prop, stringValue("foo"));
            nodes.properties(properties);
            assertTrue(properties.next());
            assertThat(properties.propertyType()).isEqualTo(ValueGroup.TEXT);
        }
    }
}
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 23 with NodeCursor

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

the class NodeTransactionStateTestBase method shouldSeeLabelChangesInTransaction.

@Test
void shouldSeeLabelChangesInTransaction() throws Exception {
    long nodeId;
    int toRetain, toDelete, toAdd, toRegret;
    final String toRetainName = "ToRetain";
    final String toDeleteName = "ToDelete";
    final String toAddName = "ToAdd";
    final String toRegretName = "ToRegret";
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        toRetain = tx.token().labelGetOrCreateForName(toRetainName);
        toDelete = tx.token().labelGetOrCreateForName(toDeleteName);
        tx.dataWrite().nodeAddLabel(nodeId, toRetain);
        tx.dataWrite().nodeAddLabel(nodeId, toDelete);
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertThat(tx.getNodeById(nodeId).getLabels()).contains(label(toRetainName), label(toDeleteName));
    }
    try (KernelTransaction tx = beginTransaction()) {
        toAdd = tx.token().labelGetOrCreateForName(toAddName);
        tx.dataWrite().nodeAddLabel(nodeId, toAdd);
        tx.dataWrite().nodeRemoveLabel(nodeId, toDelete);
        toRegret = tx.token().labelGetOrCreateForName(toRegretName);
        tx.dataWrite().nodeAddLabel(nodeId, toRegret);
        tx.dataWrite().nodeRemoveLabel(nodeId, toRegret);
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
            tx.dataRead().singleNode(nodeId, node);
            assertTrue(node.next(), "should access node");
            assertLabels(node.labels(), toRetain, toAdd);
            assertTrue(node.hasLabel(toAdd));
            assertTrue(node.hasLabel(toRetain));
            assertFalse(node.hasLabel(toDelete));
            assertFalse(node.hasLabel(toRegret));
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertThat(tx.getNodeById(nodeId).getLabels()).contains(label(toRetainName), label(toAddName));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 24 with NodeCursor

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

the class ParallelNodeCursorTestBase method shouldFailForSizeHintZero.

@Test
void shouldFailForSizeHintZero() {
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        // given
        Scan<NodeCursor> scan = read.allNodesScan();
        // when
        assertThrows(IllegalArgumentException.class, () -> scan.reserveBatch(nodes, 0));
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 25 with NodeCursor

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

the class ParallelNodeCursorTestBase method shouldHandleSizeHintOverflow.

@Test
void shouldHandleSizeHintOverflow() {
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        // when
        Scan<NodeCursor> scan = read.allNodesScan();
        assertTrue(scan.reserveBatch(nodes, NUMBER_OF_NODES * 2));
        LongArrayList ids = new LongArrayList();
        while (nodes.next()) {
            ids.add(nodes.nodeReference());
        }
        assertEquals(NODE_IDS, ids);
    }
}
Also used : LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) 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