Search in sources :

Example 6 with MutableLongList

use of org.eclipse.collections.api.list.primitive.MutableLongList 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 7 with MutableLongList

use of org.eclipse.collections.api.list.primitive.MutableLongList 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 8 with MutableLongList

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

the class ParallelRelationshipCursorTestBase method createTestGraph.

@Override
public void createTestGraph(GraphDatabaseService graphDb) {
    try (Transaction tx = graphDb.beginTx()) {
        MutableLongList list = new LongArrayList(NUMBER_OF_RELATIONSHIPS);
        for (int i = 0; i < NUMBER_OF_RELATIONSHIPS; i++) {
            list.add(tx.createNode().createRelationshipTo(tx.createNode(), RelationshipType.withName("R")).getId());
        }
        RELATIONSHIPS = list;
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)

Example 9 with MutableLongList

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

the class ParallelNodeCursorTestBase method createTestGraph.

@Override
public void createTestGraph(GraphDatabaseService graphDb) {
    try (Transaction tx = graphDb.beginTx()) {
        MutableLongList list = new LongArrayList(NUMBER_OF_NODES);
        for (int i = 0; i < NUMBER_OF_NODES; i++) {
            list.add(tx.createNode().getId());
        }
        NODE_IDS = list;
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)

Example 10 with MutableLongList

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

the class RelationshipLockHelperTest method canIterateWhileAddingAndRemoving.

@Test
void canIterateWhileAddingAndRemoving() {
    MutableLongList shuffle = LongLists.mutable.empty();
    SortedLockList sortedListIterator = new SortedLockList(0);
    int maxValue = 1000;
    for (int i = 0; i < 1000; i++) {
        int value = random.nextInt(maxValue);
        sortedListIterator.add(value);
        shuffle.add(value);
        assertThat(sortedListIterator.underlyingList().toArray()).isSorted();
    }
    while (sortedListIterator.next()) {
        long value = sortedListIterator.currentHighestLockedId();
        long toAdd = random.nextInt(maxValue);
        sortedListIterator.add(toAdd);
        assertThat(value).isEqualTo(sortedListIterator.currentHighestLockedId());
        if (shuffle.notEmpty()) {
            long toRemove = shuffle.removeAtIndex(shuffle.size() - 1);
            if (toRemove != value) {
                sortedListIterator.remove(toRemove);
            }
            assertThat(value).isEqualTo(sortedListIterator.currentHighestLockedId());
        }
        if (random.nextInt(10) == 0) {
            int backoff = random.nextInt(5);
            while (sortedListIterator.prev() && backoff-- > 0) {
            // do nothing
            }
        }
    }
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) SortedLockList(org.neo4j.internal.recordstorage.RelationshipLockHelper.SortedLockList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)30 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)8 Test (org.junit.jupiter.api.Test)8 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 ArrayList (java.util.ArrayList)5 LongLists (org.eclipse.collections.impl.factory.primitive.LongLists)5 Supplier (java.util.function.Supplier)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 LongList (org.eclipse.collections.api.list.primitive.LongList)4 Test (org.junit.Test)4 KernelException (org.neo4j.exceptions.KernelException)4 Transaction (org.neo4j.graphdb.Transaction)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 List (java.util.List)3 Map (java.util.Map)3 NavigableMap (java.util.NavigableMap)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