Search in sources :

Example 11 with Degrees

use of org.neo4j.storageengine.api.Degrees in project neo4j by neo4j.

the class CachingExpandIntoTest method shouldComputeDegreeWithoutType.

@Test
void shouldComputeDegreeWithoutType() throws Exception {
    // GIVEN
    long node;
    try (KernelTransaction tx = transaction()) {
        Write write = tx.dataWrite();
        node = nodeWithDegree(tx, 42);
        relate(tx, node, "R1", write.nodeCreate());
        relate(tx, node, "R2", write.nodeCreate());
        relate(tx, write.nodeCreate(), "R3", node);
        relate(tx, node, "R4", node);
        tx.commit();
    }
    try (KernelTransaction tx = transaction()) {
        Read read = tx.dataRead();
        CursorFactory cursors = tx.cursors();
        try (NodeCursor nodes = cursors.allocateNodeCursor(tx.cursorContext())) {
            CachingExpandInto expand = new CachingExpandInto(tx.dataRead(), OUTGOING, MEMORY_TRACKER);
            read.singleNode(node, nodes);
            assertThat(nodes.next()).isEqualTo(true);
            assertThat(nodes.supportsFastDegreeLookup()).isEqualTo(true);
            Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
            assertThat(degrees.outgoingDegree()).isEqualTo(45);
            assertThat(degrees.incomingDegree()).isEqualTo(2);
            assertThat(degrees.totalDegree()).isEqualTo(46);
        }
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) 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)11 Degrees (org.neo4j.storageengine.api.Degrees)11 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 Test (org.junit.jupiter.api.Test)9 Read (org.neo4j.internal.kernel.api.Read)9 Write (org.neo4j.internal.kernel.api.Write)9 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)7 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)2 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)2 ArrayList (java.util.ArrayList)1 KernelException (org.neo4j.exceptions.KernelException)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 TokenRead (org.neo4j.internal.kernel.api.TokenRead)1 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)1 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)1 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)1 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)1 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)1