Search in sources :

Example 1 with RelationshipScanCursor

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

the class ParallelRelationshipCursorTestBase method shouldFailForSizeHintZero.

@Test
void shouldFailForSizeHintZero() {
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        // given
        Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
        // when
        assertThrows(IllegalArgumentException.class, () -> scan.reserveBatch(relationships, 0));
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 2 with RelationshipScanCursor

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

the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsFromRandomlySizedWorkers.

@Test
void shouldScanAllRelationshipsFromRandomlySizedWorkers() throws InterruptedException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        List<Future<LongList>> futures = new ArrayList<>();
        for (int i = 0; i < 11; i++) {
            futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET)));
        }
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        assertDistinct(lists);
        LongList concat = concat(lists).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) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Future(java.util.concurrent.Future) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Test(org.junit.jupiter.api.Test)

Example 3 with RelationshipScanCursor

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

the class ParallelRelationshipCursorTestBase method shouldScanASubsetOfRelationships.

@Test
void shouldScanASubsetOfRelationships() {
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        // when
        Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
        assertTrue(scan.reserveBatch(relationships, 3));
        assertTrue(relationships.next());
        assertEquals(RELATIONSHIPS.get(0), relationships.relationshipReference());
        assertTrue(relationships.next());
        assertEquals(RELATIONSHIPS.get(1), relationships.relationshipReference());
        assertTrue(relationships.next());
        assertEquals(RELATIONSHIPS.get(2), relationships.relationshipReference());
        assertFalse(relationships.next());
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 4 with RelationshipScanCursor

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

the class ParallelRelationshipCursorTestBase method shouldHandleSizeHintOverflow.

@Test
void shouldHandleSizeHintOverflow() {
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        // when
        Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
        assertTrue(scan.reserveBatch(relationships, NUMBER_OF_RELATIONSHIPS * 2));
        LongArrayList ids = new LongArrayList();
        while (relationships.next()) {
            ids.add(relationships.relationshipReference());
        }
        assertEquals(RELATIONSHIPS, ids);
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Test(org.junit.jupiter.api.Test)

Example 5 with RelationshipScanCursor

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

the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsFromMultipleThreadWithBigSizeHints.

@Test
void shouldScanAllRelationshipsFromMultipleThreadWithBigSizeHints() throws InterruptedException, ExecutionException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        Supplier<RelationshipScanCursor> allocateRelCursor = () -> cursors.allocateRelationshipScanCursor(NULL);
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateRelCursor, REL_GET, 100));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateRelCursor, REL_GET, 100));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateRelCursor, REL_GET, 100));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateRelCursor, REL_GET, 100));
        // 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)

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