Search in sources :

Example 1 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project eclipse-collections by eclipse.

the class Collectors2AdditionalTest method collectLongParallel.

@Test
public void collectLongParallel() {
    LongList expected = LARGE_INTERVAL.collectLong(Integer::longValue, LongLists.mutable.empty());
    LongList actual = this.bigData.parallelStream().collect(Collectors2.collectLong(each -> (long) each, LongLists.mutable::empty));
    Assert.assertEquals(expected, actual);
}
Also used : BigInteger(java.math.BigInteger) LongLists(org.eclipse.collections.impl.factory.primitive.LongLists) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) LongList(org.eclipse.collections.api.list.primitive.LongList) PartitionMutableBag(org.eclipse.collections.api.partition.bag.PartitionMutableBag) DoubleLists(org.eclipse.collections.impl.factory.primitive.DoubleLists) Verify(org.eclipse.collections.impl.test.Verify) MutableList(org.eclipse.collections.api.list.MutableList) ShortList(org.eclipse.collections.api.list.primitive.ShortList) PartitionMutableSet(org.eclipse.collections.api.partition.set.PartitionMutableSet) ArrayList(java.util.ArrayList) PartitionFastList(org.eclipse.collections.impl.partition.list.PartitionFastList) BigDecimal(java.math.BigDecimal) Functions(org.eclipse.collections.impl.block.factory.Functions) ByteLists(org.eclipse.collections.impl.factory.primitive.ByteLists) Map(java.util.Map) Interval(org.eclipse.collections.impl.list.Interval) PartitionHashBag(org.eclipse.collections.impl.partition.bag.PartitionHashBag) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) BigInteger(java.math.BigInteger) DoubleList(org.eclipse.collections.api.list.primitive.DoubleList) PartitionMutableList(org.eclipse.collections.api.partition.list.PartitionMutableList) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) CharLists(org.eclipse.collections.impl.factory.primitive.CharLists) CharList(org.eclipse.collections.api.list.primitive.CharList) IntList(org.eclipse.collections.api.list.primitive.IntList) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Bags(org.eclipse.collections.impl.factory.Bags) BooleanLists(org.eclipse.collections.impl.factory.primitive.BooleanLists) PartitionUnifiedSet(org.eclipse.collections.impl.partition.set.PartitionUnifiedSet) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) Collectors(java.util.stream.Collectors) BooleanList(org.eclipse.collections.api.list.primitive.BooleanList) FloatLists(org.eclipse.collections.impl.factory.primitive.FloatLists) List(java.util.List) ShortLists(org.eclipse.collections.impl.factory.primitive.ShortLists) ByteList(org.eclipse.collections.api.list.primitive.ByteList) IntLists(org.eclipse.collections.impl.factory.primitive.IntLists) FloatList(org.eclipse.collections.api.list.primitive.FloatList) Lists(org.eclipse.collections.impl.factory.Lists) Sets(org.eclipse.collections.impl.factory.Sets) Assert(org.junit.Assert) LongList(org.eclipse.collections.api.list.primitive.LongList) LongLists(org.eclipse.collections.impl.factory.primitive.LongLists) Test(org.junit.Test)

Example 2 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class TokenIndexAccessorTest method readerShouldFindManyWithOtherTokens.

@ParameterizedTest
@EnumSource(IndexOrder.class)
void readerShouldFindManyWithOtherTokens(IndexOrder indexOrder) throws Exception {
    // Given
    int tokenId = 1;
    long[] entityIds = new long[] { 1, 2, 3, 64, 65, 1000, 2001 };
    long[] otherEntityIds = new long[] { 1, 2, 4, 64, 66, 1000, 2000 };
    addToIndex(tokenId, entityIds);
    addToIndex(2, otherEntityIds);
    LongList expectedIds = LongLists.immutable.of(entityIds);
    // When
    assertReaderFindsExpected(indexOrder, tokenId, expectedIds);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongList(org.eclipse.collections.api.list.primitive.LongList) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class ParallelNodeLabelScanTestBase method shouldScanAllNodesFromRandomlySizedWorkers.

@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        List<Future<LongList>> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeLabelIndexCursor(NULL), NODE_GET)));
        }
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        assertDistinct(lists);
        assertEquals(FOO_NODES, LongSets.immutable.withAll(concat(lists)));
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : 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 4 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class ParallelNodeLabelScanTransactionStateTestBase method createNodesWithLabel.

private LongList createNodesWithLabel(int label, int size) throws KernelException {
    LongList ids;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        ids = createNodesWithLabel(write, label, size);
        tx.commit();
    }
    return ids;
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList)

Example 5 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class ParallelNodeLabelScanTransactionStateTestBase method shouldScanAllNodesFromMultipleThreads.

@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException, KernelException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    int size = 1024;
    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);
        // when
        Supplier<NodeLabelIndexCursor> allocateCursor = () -> cursors.allocateNodeLabelIndexCursor(tx.cursorContext());
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
        // 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);
        assertEquals(ids.toSortedList(), concat.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) 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)

Aggregations

LongList (org.eclipse.collections.api.list.primitive.LongList)29 Test (org.junit.jupiter.api.Test)23 ExecutorService (java.util.concurrent.ExecutorService)19 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)19 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)18 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)12 ArrayList (java.util.ArrayList)11 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)11 Future (java.util.concurrent.Future)9 Read (org.neo4j.internal.kernel.api.Read)8 Write (org.neo4j.internal.kernel.api.Write)8 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)6 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 NodeLabelIndexCursor (org.neo4j.internal.kernel.api.NodeLabelIndexCursor)5 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)3 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 List (java.util.List)2