Search in sources :

Example 16 with MutableLongList

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

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

the class ParallelNodeLabelScanTransactionStateTestBase method createNodesWithLabel.

private LongList createNodesWithLabel(Write write, int label, int size) throws KernelException {
    MutableLongList ids = LongLists.mutable.empty();
    for (int i = 0; i < size; i++) {
        long node = write.nodeCreate();
        write.nodeAddLabel(node, label);
        ids.add(node);
    }
    return ids;
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList)

Example 18 with MutableLongList

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

the class TestUtils method concat.

static LongList concat(List<LongList> lists) {
    MutableLongList concat = LongLists.mutable.empty();
    lists.forEach(concat::addAll);
    return concat;
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList)

Example 19 with MutableLongList

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

the class IndexedIdGeneratorTest method shouldConcurrentlyAllocateAllIdsAroundReservedIds.

@Test
void shouldConcurrentlyAllocateAllIdsAroundReservedIds() throws IOException {
    // given
    idGenerator.start(NO_FREE_IDS, NULL);
    long startingId = IdValidator.INTEGER_MINUS_ONE - 100;
    idGenerator.setHighId(startingId);
    idGenerator.markHighestWrittenAtHighId();
    // when
    Race race = new Race();
    int threads = 8;
    int allocationsPerThread = 32;
    LongList[] allocatedIds = new LongList[threads];
    for (int i = 0; i < 8; i++) {
        LongArrayList list = new LongArrayList(32);
        allocatedIds[i] = list;
        race.addContestant(() -> {
            for (int j = 0; j < allocationsPerThread; j++) {
                list.add(idGenerator.nextId(NULL));
            }
        }, 1);
    }
    race.goUnchecked();
    // then
    MutableLongList allIds = new LongArrayList(allocationsPerThread * threads);
    Stream.of(allocatedIds).forEach(allIds::addAll);
    allIds = allIds.sortThis();
    assertEquals(allocationsPerThread * threads, allIds.size());
    MutableLongIterator allIdsIterator = allIds.longIterator();
    long nextExpected = startingId;
    while (allIdsIterator.hasNext()) {
        assertEquals(nextExpected, allIdsIterator.next());
        do {
            nextExpected++;
        } while (IdValidator.isReservedId(nextExpected));
    }
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Race(org.neo4j.test.Race) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongIterator(org.eclipse.collections.api.iterator.MutableLongIterator) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with MutableLongList

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

the class DynamicIndexStoreViewTest method shouldVisitRelationshipsUsingTokenIndex.

@Test
void shouldVisitRelationshipsUsingTokenIndex() throws Throwable {
    // Given
    StubTokenIndexReader tokenReader = new StubTokenIndexReader();
    StubStorageCursors cursors = new StubStorageCursors().withTokenIndexes();
    IndexProxy indexProxy = mock(IndexProxy.class);
    IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
    IndexDescriptor descriptor = forSchema(forAnyEntityTokens(RELATIONSHIP), DESCRIPTOR).withName("index").materialise(0);
    when(indexProxy.getState()).thenReturn(InternalIndexState.ONLINE);
    when(indexProxy.getDescriptor()).thenReturn(descriptor);
    when(indexProxy.newTokenReader()).thenReturn(tokenReader);
    when(indexProxies.getIndexProxy(any())).thenReturn(indexProxy);
    int targetType = 1;
    int notTargetType = 2;
    int[] indexedTypes = { targetType };
    String targetPropertyKey = "key";
    String notTargetPropertyKey = "not-key";
    Value propertyValue = Values.stringValue("value");
    MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
    long id = 0;
    int wantedPropertyUpdates = 5;
    for (int i = 0; i < wantedPropertyUpdates; i++) {
        // Relationships that are indexed
        cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
        tokenReader.index(indexedTypes, id);
        relationshipsWithTargetType.add(id++);
        // Relationship with wrong property
        cursors.withRelationship(id++, 1, targetType, 3).properties(notTargetPropertyKey, propertyValue);
        // Relationship with wrong type
        cursors.withRelationship(id++, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
    }
    // When
    DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
    TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
    TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
    StoreScan storeScan = storeView.visitRelationships(indexedTypes, relationType -> true, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
    storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
    // Then make sure all the fitting relationships where included
    assertThat(propertyScanConsumer.batches.size()).isEqualTo(1);
    assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(wantedPropertyUpdates);
    // and that we didn't visit any more relationships than what we would get from scan store
    assertThat(tokenConsumer.batches.size()).isEqualTo(1);
    assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Value(org.neo4j.values.storable.Value) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) Test(org.junit.jupiter.api.Test)

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