Search in sources :

Example 11 with LongList

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

the class ParallelRelationshipCursorTransactionStateTestBase method parallelTxStateScanStressTest.

@Test
void parallelTxStateScanStressTest() throws InterruptedException, KernelException {
    LongSet existingRelationships = createRelationships(77);
    int workers = Runtime.getRuntime().availableProcessors();
    ExecutorService threadPool = Executors.newFixedThreadPool(workers);
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    ThreadLocalRandom random = ThreadLocalRandom.current();
    try {
        for (int i = 0; i < 1000; i++) {
            MutableLongSet allRels = LongSets.mutable.withAll(existingRelationships);
            try (KernelTransaction tx = beginTransaction()) {
                int relationshipsInTx = random.nextInt(100);
                Write write = tx.dataWrite();
                int type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
                for (int j = 0; j < relationshipsInTx; j++) {
                    allRels.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
                }
                Scan<RelationshipScanCursor> scan = tx.dataRead().allRelationshipsScan();
                List<Future<LongList>> futures = new ArrayList<>(workers);
                for (int j = 0; j < workers; j++) {
                    futures.add(threadPool.submit(randomBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET)));
                }
                List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
                TestUtils.assertDistinct(lists);
                LongList concat = TestUtils.concat(lists);
                assertEquals(allRels, LongSets.immutable.withAll(concat), format("relationships=%d, seen=%d, all=%d", relationshipsInTx, concat.size(), allRels.size()));
                assertEquals(allRels.size(), concat.size(), format("relationships=%d", relationshipsInTx));
                tx.rollback();
            }
        }
    } finally {
        threadPool.shutdown();
        threadPool.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) LongSet(org.eclipse.collections.api.set.primitive.LongSet) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) LongList(org.eclipse.collections.api.list.primitive.LongList) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) ExecutorService(java.util.concurrent.ExecutorService) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Future(java.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Example 12 with LongList

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

the class ParallelNodeCursorTestBase method shouldScanAllNodesFromMultipleThreads.

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

Example 13 with LongList

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

the class GBPTreeConsistencyCheckerTestBase method shouldDetectChildPointerPointingToChildOwnedByOtherNode.

@Test
void shouldDetectChildPointerPointingToChildOwnedByOtherNode() throws IOException {
    try (GBPTree<KEY, VALUE> index = index().build()) {
        treeWithHeight(index, 2);
        GBPTreeInspection<KEY, VALUE> inspection = inspect(index);
        LongList internalNodesWithSiblings = inspection.getNodesPerLevel().get(1);
        long targetInternalNode = randomAmong(internalNodesWithSiblings);
        long otherInternalNode = randomFromExcluding(internalNodesWithSiblings, targetInternalNode);
        int otherChildPos = randomChildPos(inspection, otherInternalNode);
        int targetChildPos = randomChildPos(inspection, targetInternalNode);
        GBPTreeCorruption.IndexCorruption<KEY, VALUE> corruption = GBPTreeCorruption.copyChildPointerFromOther(targetInternalNode, otherInternalNode, targetChildPos, otherChildPos);
        index.unsafe(corruption, NULL);
        assertReportAnyStructuralInconsistency(index);
    }
}
Also used : ImmutableLongList(org.eclipse.collections.api.list.primitive.ImmutableLongList) LongList(org.eclipse.collections.api.list.primitive.LongList) Test(org.junit.jupiter.api.Test)

Example 14 with LongList

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

the class Collectors2AdditionalTest method collectLong.

@Test
public void collectLong() {
    LongList expected = SMALL_INTERVAL.collectLong(Integer::longValue, LongLists.mutable.empty());
    LongList actual = this.smallData.stream().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 15 with LongList

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

the class ParallelNodeCursorTestBase method shouldScanAllNodesFromRandomlySizedWorkers.

@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, ExecutionException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<NodeCursor> scan = read.allNodesScan();
    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.allocateNodeCursor(NULL), NODE_GET)));
        }
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        TestUtils.assertDistinct(lists);
        LongList concat = TestUtils.concat(lists).toSortedList();
        assertEquals(NODE_IDS, concat);
    } 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) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Future(java.util.concurrent.Future) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) 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