Search in sources :

Example 6 with RelationshipTraversalCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseFullAccessRelationshipTraversalCursor.

@Test
void shouldReuseFullAccessRelationshipTraversalCursor() {
    NodeCursor node = cursors.allocateNodeCursor(NULL);
    RelationshipTraversalCursor c1 = cursors.allocateFullAccessRelationshipTraversalCursor(NULL);
    read.singleNode(startNode, node);
    node.next();
    node.relationships(c1, ALL_RELATIONSHIPS);
    node.close();
    c1.close();
    RelationshipTraversalCursor c2 = cursors.allocateFullAccessRelationshipTraversalCursor(NULL);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 7 with RelationshipTraversalCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseRelationshipTraversalCursor.

@Test
void shouldReuseRelationshipTraversalCursor() {
    NodeCursor node = cursors.allocateNodeCursor(NULL);
    RelationshipTraversalCursor c1 = cursors.allocateRelationshipTraversalCursor(NULL);
    read.singleNode(startNode, node);
    node.next();
    node.relationships(c1, ALL_RELATIONSHIPS);
    node.close();
    c1.close();
    RelationshipTraversalCursor c2 = cursors.allocateRelationshipTraversalCursor(NULL);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 8 with RelationshipTraversalCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeRelationshipInTransaction.

@Test
void shouldSeeRelationshipInTransaction() 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());
            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) Test(org.junit.jupiter.api.Test)

Example 9 with RelationshipTraversalCursor

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

the class RelationshipTransactionStateTestBase method shouldNewRelationshipBetweenAlreadyConnectedSparseNodes.

@Test
void shouldNewRelationshipBetweenAlreadyConnectedSparseNodes() throws Exception {
    long start;
    long end;
    long existingRelationship;
    int type;
    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);
        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());
            assertFalse(node.supportsFastDegreeLookup());
            Degrees degrees = node.degrees(selection(type, BOTH));
            assertEquals(2, degrees.outgoingDegree());
            assertEquals(0, degrees.incomingDegree());
            assertRelationships(OUTGOING, node, type, traversal, newRelationship, existingRelationship);
        }
    }
}
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 10 with RelationshipTraversalCursor

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

the class RelationshipTransactionStateTestBase method shouldIncludeAddedRelationshipsByTypeAndDirection.

@Test
void shouldIncludeAddedRelationshipsByTypeAndDirection() throws Exception {
    int typeId1;
    int typeId2;
    long relationship1;
    long relationship2;
    long sourceNode;
    long targetNode;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        typeId1 = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        typeId2 = tx.tokenWrite().relationshipTypeGetOrCreateForName("R2");
        sourceNode = write.nodeCreate();
        relationship1 = write.relationshipCreate(sourceNode, typeId1, write.nodeCreate());
        relationship2 = write.relationshipCreate(sourceNode, typeId2, write.nodeCreate());
        targetNode = write.nodeCreate();
        tx.commit();
    }
    SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
    try (KernelTransaction tx = beginTransaction(loginContext);
        NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
        RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
        Write write = tx.dataWrite();
        // OUTGOING :R
        long r1 = write.relationshipCreate(sourceNode, typeId1, targetNode);
        // INCOMING :R
        long r2 = write.relationshipCreate(targetNode, typeId1, sourceNode);
        // LOOP :R
        long r3 = write.relationshipCreate(sourceNode, typeId1, sourceNode);
        // OUTGOING :R2
        long r4 = write.relationshipCreate(sourceNode, typeId2, targetNode);
        // INCOMING :R2
        long r5 = write.relationshipCreate(targetNode, typeId2, sourceNode);
        // LOOP :R2
        long r6 = write.relationshipCreate(sourceNode, typeId2, sourceNode);
        org.neo4j.internal.kernel.api.Read read = tx.dataRead();
        read.singleNode(sourceNode, node);
        assertTrue(node.next());
        assertRelationships(node, traversal, ALL_RELATIONSHIPS, relationship1, relationship2, r1, r2, r3, r4, r5, r6);
        assertRelationships(node, traversal, selection(OUTGOING), relationship1, relationship2, r1, r3, r4, r6);
        assertRelationships(node, traversal, selection(typeId1, BOTH), relationship1, r1, r2, r3);
        assertRelationships(node, traversal, selection(typeId1, OUTGOING), relationship1, r1, r3);
        assertRelationships(node, traversal, selection(typeId1, INCOMING), r2, r3);
        assertRelationships(node, traversal, selection(typeId2, BOTH), relationship2, r4, r5, r6);
        assertRelationships(node, traversal, selection(typeId2, OUTGOING), relationship2, r4, r6);
        assertRelationships(node, traversal, selection(typeId2, INCOMING), r5, r6);
        assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, BOTH), relationship1, relationship2, r1, r2, r3, r4, r5, r6);
        assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, OUTGOING), relationship1, relationship2, r1, r3, r4, r6);
        assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, INCOMING), r2, r3, r5, r6);
    }
}
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) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) TestAccessMode(org.neo4j.internal.kernel.api.security.TestAccessMode) 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