Search in sources :

Example 6 with RelationshipTypeIndexCursor

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

the class RelationshipTypeIndexCursorTestBase method shouldFindRelationshipsByType.

@ParameterizedTest
@EnumSource(value = IndexOrder.class)
void shouldFindRelationshipsByType(IndexOrder order) throws KernelException {
    // GIVEN
    long toDelete;
    long relTwo;
    long relThree;
    long relTwo2;
    long relThree2;
    long relThree3;
    try (KernelTransaction tx = beginTransaction()) {
        createRelationship(tx.dataWrite(), typeOne);
        relTwo = createRelationship(tx.dataWrite(), typeTwo);
        relThree = createRelationship(tx.dataWrite(), typeThree);
        toDelete = createRelationship(tx.dataWrite(), typeOne);
        relTwo2 = createRelationship(tx.dataWrite(), typeTwo);
        relThree2 = createRelationship(tx.dataWrite(), typeThree);
        relThree3 = createRelationship(tx.dataWrite(), typeThree);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        tx.dataWrite().relationshipDelete(toDelete);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        try (RelationshipTypeIndexCursor cursor = tx.cursors().allocateRelationshipTypeIndexCursor(NULL)) {
            MutableLongSet uniqueIds = new LongHashSet();
            // WHEN
            relationshipTypeScan(tx, typeOne, cursor, order);
            // THEN
            assertRelationshipCount(cursor, 1, uniqueIds);
            // WHEN
            relationshipTypeScan(tx, typeTwo, cursor, order);
            // THEN
            assertRelationships(cursor, uniqueIds, order, relTwo, relTwo2);
            // WHEN
            relationshipTypeScan(tx, typeThree, cursor, order);
            // THEN
            assertRelationships(cursor, uniqueIds, order, relThree, relThree2, relThree3);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipTypeIndexCursor(org.neo4j.internal.kernel.api.RelationshipTypeIndexCursor) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with RelationshipTypeIndexCursor

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

the class KernelReadTracerTest method shouldTraceRelationshipTypeScan.

@Test
void shouldTraceRelationshipTypeScan() throws KernelException {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    int hasId = token.relationshipTypeGetOrCreateForName("HAS");
    List<TraceEvent> expectedEvents = new ArrayList<>();
    expectedEvents.add(OnRelationshipTypeScan(hasId));
    try (RelationshipTypeIndexCursor cursor = cursors.allocateRelationshipTypeIndexCursor(NULL)) {
        // when
        cursor.setTracer(tracer);
        read.relationshipTypeScan(getTokenReadSession(tx, EntityType.RELATIONSHIP), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(hasId));
        while (cursor.next()) {
            expectedEvents.add(OnRelationship(cursor.relationshipReference()));
        }
    }
    // then
    tracer.assertEvents(expectedEvents);
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) RelationshipTypeIndexCursor(org.neo4j.internal.kernel.api.RelationshipTypeIndexCursor) ArrayList(java.util.ArrayList) TraceEvent(org.neo4j.kernel.impl.newapi.TestKernelReadTracer.TraceEvent) Test(org.junit.jupiter.api.Test)

Aggregations

RelationshipTypeIndexCursor (org.neo4j.internal.kernel.api.RelationshipTypeIndexCursor)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 TokenPredicate (org.neo4j.internal.kernel.api.TokenPredicate)2 TraceEvent (org.neo4j.kernel.impl.newapi.TestKernelReadTracer.TraceEvent)2 ArrayList (java.util.ArrayList)1