Search in sources :

Example 16 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method hasPropertiesShouldSeeNewlyRemovedProperties.

@Test
void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception {
    // Given
    long relationship;
    int prop1, prop2, prop3;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        int token = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        relationship = write.relationshipCreate(write.nodeCreate(), token, write.nodeCreate());
        prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop1");
        prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop2");
        prop3 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop3");
        tx.dataWrite().relationshipSetProperty(relationship, prop1, longValue(1));
        tx.dataWrite().relationshipSetProperty(relationship, prop2, longValue(2));
        tx.dataWrite().relationshipSetProperty(relationship, prop3, longValue(3));
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction()) {
        try (RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(NULL)) {
            tx.dataRead().singleRelationship(relationship, cursor);
            assertTrue(cursor.next());
            assertTrue(hasProperties(cursor, tx));
            tx.dataWrite().relationshipRemoveProperty(relationship, prop1);
            assertTrue(hasProperties(cursor, tx));
            tx.dataWrite().relationshipRemoveProperty(relationship, prop2);
            assertTrue(hasProperties(cursor, tx));
            tx.dataWrite().relationshipRemoveProperty(relationship, prop3);
            assertFalse(hasProperties(cursor, tx));
        }
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 17 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeSingleRelationshipInTransaction.

@Test
void shouldSeeSingleRelationshipInTransaction() throws Exception {
    int label;
    long n1, n2;
    try (KernelTransaction tx = beginTransaction()) {
        n1 = tx.dataWrite().nodeCreate();
        n2 = tx.dataWrite().nodeCreate();
        // setup extra relationship to challenge the implementation
        long decoyNode = tx.dataWrite().nodeCreate();
        label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        tx.dataWrite().relationshipCreate(n2, label, decoyNode);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        long r = tx.dataWrite().relationshipCreate(n1, label, n2);
        try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL)) {
            tx.dataRead().singleRelationship(r, relationship);
            assertTrue(relationship.next(), "should find relationship");
            assertEquals(label, relationship.type());
            assertEquals(n1, relationship.sourceNodeReference());
            assertEquals(n2, relationship.targetNodeReference());
            assertEquals(r, relationship.relationshipReference());
            assertFalse(relationship.next(), "should only find one relationship");
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 18 with RelationshipScanCursor

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

the class RelationshipScanCursorTestBase method shouldAccessRelationshipLabels.

@Test
void shouldAccessRelationshipLabels() {
    // given
    Map<Integer, Integer> counts = new HashMap<>();
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        // when
        read.allRelationshipsScan(relationships);
        while (relationships.next()) {
            counts.compute(relationships.type(), (k, v) -> v == null ? 1 : v + 1);
        }
    }
    // then
    assertEquals(3, counts.size());
    int[] values = new int[3];
    int i = 0;
    for (int value : counts.values()) {
        values[i++] = value;
    }
    Arrays.sort(values);
    assertArrayEquals(new int[] { 1, 6, 6 }, values);
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 19 with RelationshipScanCursor

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

the class RelationshipScanCursorTestBase method shouldAccessRelationshipByReference.

@Test
void shouldAccessRelationshipByReference() {
    // given
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        for (long id : RELATIONSHIP_IDS) {
            // when
            read.singleRelationship(id, relationships);
            // then
            assertTrue(relationships.next(), "should access defined relationship");
            assertEquals(id, relationships.relationshipReference(), "should access the correct relationship");
            assertFalse(relationships.next(), "should only access a single relationship");
        }
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 20 with RelationshipScanCursor

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

the class RelationshipScanCursorTestBase method shouldScanRelationships.

@Test
void shouldScanRelationships() {
    // given
    List<Long> ids = new ArrayList<>();
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        // when
        read.allRelationshipsScan(relationships);
        while (relationships.next()) {
            ids.add(relationships.relationshipReference());
        }
    }
    assertEquals(RELATIONSHIP_IDS, ids);
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)53 Test (org.junit.jupiter.api.Test)40 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)28 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)16 Write (org.neo4j.internal.kernel.api.Write)16 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)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 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 Read (org.neo4j.internal.kernel.api.Read)4 Future (java.util.concurrent.Future)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)3 TokenRead (org.neo4j.internal.kernel.api.TokenRead)3 KernelException (org.neo4j.exceptions.KernelException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1