Search in sources :

Example 16 with RelationshipTraversalCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeNewTypes.

@Test
void shouldSeeNewTypes() throws Exception {
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        long start = write.nodeCreate();
        int outgoing = tx.tokenWrite().relationshipTypeGetOrCreateForName("OUT");
        int incoming = tx.tokenWrite().relationshipTypeGetOrCreateForName("IN");
        int looping = tx.tokenWrite().relationshipTypeGetOrCreateForName("LOOP");
        long out = write.relationshipCreate(start, outgoing, write.nodeCreate());
        long in1 = write.relationshipCreate(write.nodeCreate(), incoming, start);
        long in2 = write.relationshipCreate(write.nodeCreate(), incoming, start);
        long loop = write.relationshipCreate(start, looping, start);
        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());
            Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
            for (int t : degrees.types()) {
                if (t == outgoing) {
                    assertEquals(1, degrees.outgoingDegree(t));
                    assertEquals(0, degrees.incomingDegree(t));
                    assertRelationships(OUTGOING, node, t, traversal, out);
                    assertNoRelationships(INCOMING, node, t, traversal);
                } else if (t == incoming) {
                    assertEquals(0, degrees.outgoingDegree(t));
                    assertEquals(2, degrees.incomingDegree(t));
                    assertRelationships(INCOMING, node, t, traversal, in1, in2);
                    assertNoRelationships(OUTGOING, node, t, traversal);
                } else if (t == looping) {
                    assertEquals(1, degrees.outgoingDegree(t));
                    assertEquals(1, degrees.incomingDegree(t));
                    assertRelationships(BOTH, node, t, traversal, loop);
                    assertRelationships(OUTGOING, node, t, traversal, loop);
                    assertRelationships(INCOMING, node, t, traversal, loop);
                } 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 17 with RelationshipTraversalCursor

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

the class CachingExpandIntoTest method findConnections.

private void findConnections(CachingExpandInto expandInto, NodeCursor cursor, long from, long to, int... types) {
    RelationshipTraversalCursor relationships = expandInto.connectingRelationships(cursor, mock(RelationshipTraversalCursor.class), from, types, to);
    // While we traverse the relationships, we estimate with the cursor, which references the CachingExpandInto
    assertEstimatesCorrectly(relationships);
    while (relationships.next()) {
        assertEstimatesCorrectly(relationships);
    }
    // Once the cursor is exhausted, it will close itself. Now we need to measure using expandInto directly again
    assertEstimatesCorrectly(expandInto);
    // Make sure that next is idempotent, even if cursor is already closed
    relationships.next();
    assertEstimatesCorrectly(expandInto);
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor)

Example 18 with RelationshipTraversalCursor

use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor 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 19 with RelationshipTraversalCursor

use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor 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)

Example 20 with RelationshipTraversalCursor

use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor 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)

Aggregations

RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)29 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)26 Test (org.junit.jupiter.api.Test)23 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)17 Write (org.neo4j.internal.kernel.api.Write)10 Read (org.neo4j.internal.kernel.api.Read)7 Degrees (org.neo4j.storageengine.api.Degrees)7 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)3 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)1 SecurityContext (org.neo4j.internal.kernel.api.security.SecurityContext)1 TestAccessMode (org.neo4j.internal.kernel.api.security.TestAccessMode)1