Search in sources :

Example 66 with NodeCursor

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

the class PropertyCursorTestBase method shouldNotAccessNonExistentNodeProperties.

@Test
void shouldNotAccessNonExistentNodeProperties() {
    // given
    try (NodeCursor node = cursors.allocateNodeCursor(NULL);
        PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        read.singleNode(bareNodeId, node);
        assertTrue(node.next(), "node by reference");
        assertFalse(hasProperties(node, props), "no properties");
        node.properties(props);
        assertFalse(props.next(), "no properties by direct method");
        read.nodeProperties(node.nodeReference(), node.propertiesReference(), props);
        assertFalse(props.next(), "no properties via property ref");
        assertFalse(node.next(), "only one node");
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 67 with NodeCursor

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

the class ParallelNodeCursorTransactionStateTestBase method shouldScanAllNodesFromMultipleThreads.

@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException, TransactionFailureException, InvalidTransactionTypeKernelException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    int size = 128;
    LongArrayList ids = new LongArrayList();
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        for (int i = 0; i < size; i++) {
            ids.add(write.nodeCreate());
        }
        org.neo4j.internal.kernel.api.Read read = tx.dataRead();
        Scan<NodeCursor> scan = read.allNodesScan();
        // when
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
        // then
        LongList ids1 = future1.get();
        LongList ids2 = future2.get();
        LongList ids3 = future3.get();
        LongList ids4 = future4.get();
        TestUtils.assertDistinct(ids1, ids2, ids3, ids4);
        LongList concat = TestUtils.concat(ids1, ids2, ids3, ids4);
        assertEquals(ids.toSortedList(), concat.toSortedList());
        tx.rollback();
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Read(org.neo4j.internal.kernel.api.Read) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) LongList(org.eclipse.collections.api.list.primitive.LongList) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.jupiter.api.Test)

Example 68 with NodeCursor

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

the class ParallelNodeCursorTransactionStateTestBase method shouldScanAllNodesFromRandomlySizedWorkers.

@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, TransactionFailureException, InvalidTransactionTypeKernelException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    int size = 128;
    LongArrayList ids = new LongArrayList();
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        for (int i = 0; i < size; i++) {
            ids.add(write.nodeCreate());
        }
        Read read = tx.dataRead();
        Scan<NodeCursor> scan = read.allNodesScan();
        CursorFactory cursors = testSupport.kernelToTest().cursors();
        // 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)));
        }
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        TestUtils.assertDistinct(lists);
        LongList concat = TestUtils.concat(lists);
        assertEquals(ids.toSortedList(), concat.toSortedList());
        tx.rollback();
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) LongList(org.eclipse.collections.api.list.primitive.LongList) Read(org.neo4j.internal.kernel.api.Read) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Example 69 with NodeCursor

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

the class RelationshipTransactionStateTestBase method shouldNotSeeRelationshipDeletedInTransaction.

@Test
void shouldNotSeeRelationshipDeletedInTransaction() throws Exception {
    long n1, n2, r;
    try (KernelTransaction tx = beginTransaction()) {
        n1 = tx.dataWrite().nodeCreate();
        n2 = tx.dataWrite().nodeCreate();
        int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        r = tx.dataWrite().relationshipCreate(n1, label, n2);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        tx.dataWrite().relationshipDelete(r);
        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);
            assertFalse(relationship.next(), "should not find 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) Test(org.junit.jupiter.api.Test)

Example 70 with NodeCursor

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

the class RelationshipTransactionStateTestBase method shouldNewRelationshipBetweenAlreadyConnectedDenseNodes.

@Test
void shouldNewRelationshipBetweenAlreadyConnectedDenseNodes() throws Exception {
    long start;
    long end;
    long existingRelationship;
    int type, bulk;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        start = write.nodeCreate();
        end = write.nodeCreate();
        type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        existingRelationship = write.relationshipCreate(start, type, end);
        bulk = tx.tokenWrite().relationshipTypeGetOrCreateForName("BULK");
        for (int i = 0; i < 100; i++) {
            write.relationshipCreate(start, bulk, write.nodeCreate());
        }
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        long newRelationship = write.relationshipCreate(start, type, write.nodeCreate());
        try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
            RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
            org.neo4j.internal.kernel.api.Read read = tx.dataRead();
            read.singleNode(start, node);
            assertTrue(node.next());
            assertTrue(node.supportsFastDegreeLookup());
            Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
            for (int t : degrees.types()) {
                if (t == type) {
                    assertEquals(2, degrees.outgoingDegree(t));
                    assertEquals(0, degrees.incomingDegree(t));
                    assertRelationships(OUTGOING, node, t, traversal, existingRelationship, newRelationship);
                } else if (t == bulk) {
                    assertEquals(bulk, t);
                    assertEquals(100, degrees.outgoingDegree(t));
                    assertEquals(0, degrees.incomingDegree(t));
                } else {
                    fail(t + "  is not the type you're looking for ");
                }
            }
        }
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Read(org.neo4j.internal.kernel.api.Read) Degrees(org.neo4j.storageengine.api.Degrees) 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