Search in sources :

Example 1 with Scan

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

the class ParallelNodeLabelScanTestBase method shouldScanASubsetOfNodes.

@Test
void shouldScanASubsetOfNodes() {
    try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
        for (int label : ALL_LABELS) {
            Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(label);
            assertTrue(scan.reserveBatch(nodes, 11));
            MutableLongList found = LongLists.mutable.empty();
            while (nodes.next()) {
                found.add(nodes.nodeReference());
            }
            assertThat(found.size()).isGreaterThan(0);
            if (label == FOO_LABEL) {
                assertTrue(FOO_NODES.containsAll(found));
                assertTrue(found.noneSatisfy(f -> BAR_NODES.contains(f)));
            } else if (label == BAR_LABEL) {
                assertTrue(BAR_NODES.containsAll(found));
                assertTrue(found.noneSatisfy(f -> FOO_NODES.contains(f)));
            } else {
                fail();
            }
        }
    }
}
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 2 with Scan

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

the class ParallelNodeLabelScanTestBase method shouldHandleSizeHintOverflow.

@Test
void shouldHandleSizeHintOverflow() {
    try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
        // when
        Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
        assertTrue(scan.reserveBatch(nodes, NUMBER_OF_NODES * 2));
        MutableLongList ids = LongLists.mutable.empty();
        while (nodes.next()) {
            ids.add(nodes.nodeReference());
        }
        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 3 with Scan

use of org.neo4j.internal.kernel.api.Scan 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)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Executors (java.util.concurrent.Executors)3 Future (java.util.concurrent.Future)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 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 LongList (org.eclipse.collections.api.list.primitive.LongList)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)3 LongSet (org.eclipse.collections.api.set.primitive.LongSet)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)3 LongLists (org.eclipse.collections.impl.factory.primitive.LongLists)3 LongSets (org.eclipse.collections.impl.factory.primitive.LongSets)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3