Search in sources :

Example 51 with NodeCursor

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

the class CachingExpandIntoTest method shouldNotRecomputeAnythingIfSameNodesAndTypes.

@Test
void shouldNotRecomputeAnythingIfSameNodesAndTypes() throws Exception {
    // Given
    CachingExpandInto expandInto = new CachingExpandInto(mock(Read.class), OUTGOING, memoryTracker);
    findConnections(expandInto, mockCursor(), 42, 43, 100, 101);
    NodeCursor cursor = mockCursor();
    // When
    findConnections(expandInto, cursor, 42, 43, 100, 101);
    // Then
    verifyNoInteractions(cursor);
    assertReleasesHeap(expandInto);
}
Also used : Read(org.neo4j.internal.kernel.api.Read) CachingExpandInto(org.neo4j.internal.kernel.api.helpers.CachingExpandInto) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 52 with NodeCursor

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

the class CachingExpandIntoTest method shouldComputeDegreeOfStartAndEndNodeEveryTimeIfCacheIsFull.

@Test
void shouldComputeDegreeOfStartAndEndNodeEveryTimeIfCacheIsFull() throws Exception {
    // Given
    CachingExpandInto expandInto = new CachingExpandInto(mock(Read.class), OUTGOING, memoryTracker, 0, true);
    NodeCursor cursor = mockCursor();
    // When
    findConnections(expandInto, cursor, 42, 43);
    findConnections(expandInto, cursor, 42, 43);
    findConnections(expandInto, cursor, 42, 43);
    findConnections(expandInto, cursor, 42, 43);
    findConnections(expandInto, cursor, 42, 43);
    // Then, only call 5 times for 42 and 5 times for 43
    verify(cursor, times(10)).degree(any(RelationshipSelection.class));
    assertReleasesHeap(expandInto);
}
Also used : Read(org.neo4j.internal.kernel.api.Read) CachingExpandInto(org.neo4j.internal.kernel.api.helpers.CachingExpandInto) RelationshipSelection(org.neo4j.storageengine.api.RelationshipSelection) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 53 with NodeCursor

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

the class TransactionImpl method allNodesByLabelWithoutIndex.

private ResourceIterator<Node> allNodesByLabelWithoutIndex(KernelTransaction ktx, int labelId) {
    NodeCursor cursor = ktx.cursors().allocateNodeCursor(ktx.cursorContext());
    ktx.dataRead().allNodesScan(cursor);
    var filetredCursor = new FilteringNodeCursorWrapper(cursor, CursorPredicates.hasLabel(labelId));
    return new CursorIterator<>(filetredCursor, NodeCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
}
Also used : FilteringNodeCursorWrapper(org.neo4j.kernel.impl.newapi.FilteringNodeCursorWrapper) CursorIterator(org.neo4j.kernel.impl.coreapi.internal.CursorIterator) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor)

Example 54 with NodeCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeBothOldAndNewRelationshipsFromSparseNode.

@Test
void shouldSeeBothOldAndNewRelationshipsFromSparseNode() throws Exception {
    long start;
    long existingRelationship;
    int one;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        start = write.nodeCreate();
        one = tx.tokenWrite().relationshipTypeGetOrCreateForName("ONE");
        existingRelationship = write.relationshipCreate(start, one, write.nodeCreate());
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        int two = tx.tokenWrite().relationshipTypeGetOrCreateForName("TWO");
        long newRelationship = write.relationshipCreate(start, two, 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());
            assertFalse(node.supportsFastDegreeLookup());
            Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
            for (int t : degrees.types()) {
                if (t == one) {
                    assertEquals(1, degrees.outgoingDegree(t));
                    assertEquals(0, degrees.incomingDegree(t));
                    assertRelationships(OUTGOING, node, t, traversal, existingRelationship);
                } else if (t == two) {
                    assertEquals(1, degrees.outgoingDegree(t));
                    assertEquals(0, degrees.incomingDegree(t));
                    assertRelationships(OUTGOING, node, t, traversal, newRelationship);
                } 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)

Example 55 with NodeCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeBothOldAndNewRelationshipsFromDenseNode.

@Test
void shouldSeeBothOldAndNewRelationshipsFromDenseNode() throws Exception {
    long start;
    long existingRelationship;
    int one, bulk;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        start = write.nodeCreate();
        one = tx.tokenWrite().relationshipTypeGetOrCreateForName("ONE");
        existingRelationship = write.relationshipCreate(start, one, write.nodeCreate());
        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();
        int two = tx.tokenWrite().relationshipTypeGetOrCreateForName("TWO");
        long newRelationship = write.relationshipCreate(start, two, 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 == one) {
                    assertEquals(1, degrees.outgoingDegree(t));
                    assertEquals(0, degrees.incomingDegree(t));
                    assertRelationships(OUTGOING, node, t, traversal, existingRelationship);
                } else if (t == two) {
                    assertEquals(1, degrees.outgoingDegree(t));
                    assertEquals(0, degrees.incomingDegree(t));
                    assertRelationships(OUTGOING, node, t, traversal, newRelationship);
                } else if (t == bulk) {
                    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