Search in sources :

Example 16 with NodeLabelIndexCursor

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

the class ParallelNodeLabelScanTestBase method shouldFailForSizeHintZero.

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

Example 17 with NodeLabelIndexCursor

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

the class ParallelNodeLabelScanTestBase method shouldScanAllNodesFromMultipleThreads.

@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(BAR_LABEL);
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        Supplier<NodeLabelIndexCursor> allocateCursor = () -> cursors.allocateNodeLabelIndexCursor(NULL);
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
        // then
        LongList ids1 = future1.get();
        LongList ids2 = future2.get();
        LongList ids3 = future3.get();
        LongList ids4 = future4.get();
        assertDistinct(ids1, ids2, ids3, ids4);
        assertEquals(BAR_NODES, LongSets.immutable.withAll(concat(ids1, ids2, ids3, ids4)));
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : 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) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 18 with NodeLabelIndexCursor

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

the class ParallelNodeLabelScanTestBase method shouldScanAllNodesInBatches.

@Test
void shouldScanAllNodesInBatches() {
    // given
    try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
        // when
        Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
        MutableLongList ids = LongLists.mutable.empty();
        while (scan.reserveBatch(nodes, 3)) {
            while (nodes.next()) {
                ids.add(nodes.nodeReference());
            }
        }
        // then
        assertEquals(FOO_NODES.size(), ids.size());
        assertTrue(FOO_NODES.containsAll(ids));
        assertTrue(ids.noneSatisfy(f -> BAR_NODES.contains(f)));
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) TestUtils.concat(org.neo4j.kernel.impl.newapi.TestUtils.concat) TestUtils.randomBatchWorker(org.neo4j.kernel.impl.newapi.TestUtils.randomBatchWorker) LongLists(org.eclipse.collections.impl.factory.primitive.LongLists) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Scan(org.neo4j.internal.kernel.api.Scan) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Write(org.neo4j.internal.kernel.api.Write) Future(java.util.concurrent.Future) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ToLongFunction(java.util.function.ToLongFunction) ExecutorService(java.util.concurrent.ExecutorService) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) Collectors(java.util.stream.Collectors) TestUtils.assertDistinct(org.neo4j.kernel.impl.newapi.TestUtils.assertDistinct) Executors(java.util.concurrent.Executors) TestUtils.singleBatchWorker(org.neo4j.kernel.impl.newapi.TestUtils.singleBatchWorker) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) KernelException(org.neo4j.exceptions.KernelException) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LongSets(org.eclipse.collections.impl.factory.primitive.LongSets) LongSet(org.eclipse.collections.api.set.primitive.LongSet) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 19 with NodeLabelIndexCursor

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

the class ParallelNodeLabelScanTransactionStateTestBase method shouldScanAllNodesFromRandomlySizedWorkers.

@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, KernelException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    int size = 2000;
    try (KernelTransaction tx = beginTransaction()) {
        int label = tx.tokenWrite().labelGetOrCreateForName("L");
        LongList ids = createNodesWithLabel(tx.dataWrite(), label, size);
        Read read = tx.dataRead();
        Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(label);
        CursorFactory cursors = testSupport.kernelToTest().cursors();
        // when
        List<Future<LongList>> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeLabelIndexCursor(tx.cursorContext()), NODE_GET)));
        }
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        assertDistinct(lists);
        assertEquals(ids.toSortedList(), concat(lists).toSortedList());
        tx.rollback();
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 20 with NodeLabelIndexCursor

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

the class ParallelNodeLabelScanTransactionStateTestBase method shouldReserveBatchFromTxState.

@Test
void shouldReserveBatchFromTxState() throws KernelException {
    try (KernelTransaction tx = beginTransaction()) {
        int label = tx.tokenWrite().labelGetOrCreateForName("L");
        createNodesWithLabel(tx.dataWrite(), label, 11);
        try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
            Scan<NodeLabelIndexCursor> scan = tx.dataRead().nodeLabelScan(label);
            assertTrue(scan.reserveBatch(cursor, 5));
            assertEquals(5, count(cursor));
            assertTrue(scan.reserveBatch(cursor, 4));
            assertEquals(4, count(cursor));
            assertTrue(scan.reserveBatch(cursor, 6));
            assertEquals(2, count(cursor));
            // now we should have fetched all nodes
            while (scan.reserveBatch(cursor, 3)) {
                assertFalse(cursor.next());
            }
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Aggregations

NodeLabelIndexCursor (org.neo4j.internal.kernel.api.NodeLabelIndexCursor)25 Test (org.junit.jupiter.api.Test)23 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)19 TokenPredicate (org.neo4j.internal.kernel.api.TokenPredicate)11 ExecutorService (java.util.concurrent.ExecutorService)8 LongList (org.eclipse.collections.api.list.primitive.LongList)8 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)8 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)8 ArrayList (java.util.ArrayList)7 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)7 Future (java.util.concurrent.Future)6 Read (org.neo4j.internal.kernel.api.Read)4 Write (org.neo4j.internal.kernel.api.Write)4 List (java.util.List)3 ExecutionException (java.util.concurrent.ExecutionException)3 Executors (java.util.concurrent.Executors)3 TimeUnit (java.util.concurrent.TimeUnit)3 Supplier (java.util.function.Supplier)3 ToLongFunction (java.util.function.ToLongFunction)3 Collectors (java.util.stream.Collectors)3