Search in sources :

Example 56 with NodeCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeRelationshipInTransactionBeforeCursorInitialization.

@Test
void shouldSeeRelationshipInTransactionBeforeCursorInitialization() throws Exception {
    long n1, n2;
    try (KernelTransaction tx = beginTransaction()) {
        n1 = tx.dataWrite().nodeCreate();
        n2 = tx.dataWrite().nodeCreate();
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        long r = tx.dataWrite().relationshipCreate(n1, label, n2);
        try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
            RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
            tx.dataRead().singleNode(n1, node);
            assertTrue(node.next(), "should access node");
            node.relationships(relationship, ALL_RELATIONSHIPS);
            assertTrue(relationship.next(), "should find relationship");
            assertEquals(r, relationship.relationshipReference());
            // should not be seen
            tx.dataWrite().relationshipCreate(n1, label, n2);
            assertFalse(relationship.next(), "should not find relationship added after cursor init");
        }
        tx.commit();
    }
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 57 with NodeCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeNewRelationshipPropertyInTransaction.

@Test
void shouldSeeNewRelationshipPropertyInTransaction() throws Exception {
    try (KernelTransaction tx = beginTransaction()) {
        String propKey1 = "prop1";
        String propKey2 = "prop2";
        long n1 = tx.dataWrite().nodeCreate();
        long n2 = tx.dataWrite().nodeCreate();
        int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        long r = tx.dataWrite().relationshipCreate(n1, label, n2);
        int prop1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
        int prop2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
        assertEquals(tx.dataWrite().relationshipSetProperty(r, prop1, stringValue("hello")), NO_VALUE);
        assertEquals(tx.dataWrite().relationshipSetProperty(r, prop2, stringValue("world")), NO_VALUE);
        try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
            RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL);
            PropertyCursor property = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
            tx.dataRead().singleNode(n1, node);
            assertTrue(node.next(), "should access node");
            node.relationships(relationship, ALL_RELATIONSHIPS);
            assertTrue(relationship.next(), "should access relationship");
            relationship.properties(property);
            while (property.next()) {
                if (property.propertyKey() == prop1) {
                    assertEquals(property.propertyValue(), stringValue("hello"));
                } else if (property.propertyKey() == prop2) {
                    assertEquals(property.propertyValue(), stringValue("world"));
                } else {
                    fail(property.propertyKey() + " was not the property key you were looking for");
                }
            }
            assertFalse(relationship.next(), "should only find one relationship");
        }
        tx.commit();
    }
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) 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 58 with NodeCursor

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

the class ParallelNodeCursorTestBase method shouldScanAllNodesFromRandomlySizedWorkers.

@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, ExecutionException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<NodeCursor> scan = read.allNodesScan();
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        List<Future<LongList>> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NODE_GET)));
        }
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        TestUtils.assertDistinct(lists);
        LongList concat = TestUtils.concat(lists).toSortedList();
        assertEquals(NODE_IDS, concat);
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Future(java.util.concurrent.Future) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Test(org.junit.jupiter.api.Test)

Example 59 with NodeCursor

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

the class ParallelNodeCursorTestBase method shouldScanASubsetOfNodes.

@Test
void shouldScanASubsetOfNodes() {
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        // when
        Scan<NodeCursor> scan = read.allNodesScan();
        assertTrue(scan.reserveBatch(nodes, 3));
        assertTrue(nodes.next());
        assertEquals(NODE_IDS.get(0), nodes.nodeReference());
        assertTrue(nodes.next());
        assertEquals(NODE_IDS.get(1), nodes.nodeReference());
        assertTrue(nodes.next());
        assertEquals(NODE_IDS.get(2), nodes.nodeReference());
        assertFalse(nodes.next());
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 60 with NodeCursor

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

the class ParallelNodeCursorTestBase method shouldScanAllNodesInBatches.

@Test
void shouldScanAllNodesInBatches() {
    // given
    LongArrayList ids = new LongArrayList();
    try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
        // when
        Scan<NodeCursor> scan = read.allNodesScan();
        while (scan.reserveBatch(nodes, 3)) {
            while (nodes.next()) {
                ids.add(nodes.nodeReference());
            }
        }
    }
    // then
    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