Search in sources :

Example 36 with RelationshipScanCursor

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

the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsFromMultipleThreads.

@Test
void shouldScanAllRelationshipsFromMultipleThreads() throws InterruptedException, ExecutionException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
        // then
        LongList ids1 = future1.get();
        LongList ids2 = future2.get();
        LongList ids3 = future3.get();
        LongList ids4 = future4.get();
        assertDistinct(ids1, ids2, ids3, ids4);
        LongList concat = concat(ids1, ids2, ids3, ids4).toSortedList();
        assertEquals(RELATIONSHIPS, concat);
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Test(org.junit.jupiter.api.Test)

Example 37 with RelationshipScanCursor

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

the class ParallelRelationshipCursorTransactionStateTestBase method scanShouldSeeAddedRelationships.

@Test
void scanShouldSeeAddedRelationships() throws Exception {
    int size = 100;
    MutableLongSet existing = createRelationships(size);
    MutableLongSet added = LongSets.mutable.empty();
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        int type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        for (int i = 0; i < size; i++) {
            added.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
        }
        try (RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(NULL)) {
            Scan<RelationshipScanCursor> scan = tx.dataRead().allRelationshipsScan();
            MutableLongSet seen = LongSets.mutable.empty();
            while (scan.reserveBatch(cursor, 17)) {
                while (cursor.next()) {
                    long relationshipId = cursor.relationshipReference();
                    assertTrue(seen.add(relationshipId));
                    assertTrue(existing.remove(relationshipId) || added.remove(relationshipId));
                }
            }
            // make sure we have seen all relationships
            assertTrue(existing.isEmpty());
            assertTrue(added.isEmpty());
        }
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 38 with RelationshipScanCursor

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

the class PropertyCursorTestBase method assertAccessSingleRelationshipProperty.

private void assertAccessSingleRelationshipProperty(long relationshipId, Object expectedValue, ValueGroup expectedValueType) {
    // given
    try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
        PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        read.singleRelationship(relationshipId, relationship);
        assertTrue(relationship.next(), "relationship by reference");
        assertTrue(hasProperties(relationship, props), "has properties");
        relationship.properties(props);
        assertTrue(props.next(), "has properties by direct method");
        assertEquals(expectedValue, props.propertyValue(), "correct value");
        assertEquals(expectedValueType, props.propertyType(), "correct value type ");
        assertFalse(props.next(), "single property");
        read.relationshipProperties(relationship.relationshipReference(), relationship.propertiesReference(), props);
        assertTrue(props.next(), "has properties via property ref");
        assertEquals(expectedValue, props.propertyValue(), "correct value");
        assertFalse(props.next(), "single property");
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Example 39 with RelationshipScanCursor

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

the class PropertyCursorTestBase method shouldAccessAllRelationshipProperties.

@Test
void shouldAccessAllRelationshipProperties() {
    // given
    try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
        PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        read.singleRelationship(allPropsRelId, relationship);
        assertTrue(relationship.next(), "relationship by reference");
        assertTrue(hasProperties(relationship, props), "has properties");
        relationship.properties(props);
        Set<Object> values = new HashSet<>();
        while (props.next()) {
            values.add(props.propertyValue().asObject());
        }
        assertTrue(values.contains((byte) 13), BYTE_PROP);
        assertTrue(values.contains((short) 13), SHORT_PROP);
        assertTrue(values.contains(13), INT_PROP);
        assertTrue(values.contains(13L), INLINE_LONG_PROP);
        assertTrue(values.contains(Long.MAX_VALUE), LONG_PROP);
        assertTrue(values.contains(13.0f), FLOAT_PROP);
        assertTrue(values.contains(13.0), DOUBLE_PROP);
        assertTrue(values.contains(true), TRUE_PROP);
        assertTrue(values.contains(false), FALSE_PROP);
        assertTrue(values.contains('x'), CHAR_PROP);
        assertTrue(values.contains(""), EMPTY_STRING_PROP);
        assertTrue(values.contains("hello"), SHORT_STRING_PROP);
        assertTrue(values.contains(chinese), UTF_8_PROP);
        if (supportsBigProperties()) {
            assertTrue(values.contains(LONG_STRING), LONG_STRING_PROP);
            assertThat(values).as(SMALL_ARRAY_PROP).contains(new int[] { 1, 2, 3, 4 });
            assertThat(values).as(BIG_ARRAY_PROP).contains(LONG_STRING);
        }
        assertTrue(values.contains(pointValue), POINT_PROP);
        assertTrue(values.contains(dateValue.asObject()), DATE_PROP);
        int expected = supportsBigProperties() ? 18 : 15;
        assertEquals(expected, values.size(), "number of values");
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 40 with RelationshipScanCursor

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

the class PropertyCursorTestBase method shouldNotAccessNonExistentRelationshipProperties.

@Test
void shouldNotAccessNonExistentRelationshipProperties() {
    try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
        PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        read.singleRelationship(bareRelId, relationship);
        assertTrue(relationship.next(), "relationship by reference");
        assertFalse(hasProperties(relationship, props), "no properties");
        relationship.properties(props);
        assertFalse(props.next(), "no properties by direct method");
        read.relationshipProperties(relationship.relationshipReference(), relationship.propertiesReference(), props);
        assertFalse(props.next(), "no properties via property ref");
        assertFalse(relationship.next(), "only one node");
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) 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