Search in sources :

Example 21 with MutableLongList

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

the class DynamicIndexStoreViewTest method shouldVisitAllRelationshipsWithoutTokenIndexes.

@Test
void shouldVisitAllRelationshipsWithoutTokenIndexes() {
    StubStorageCursors cursors = new StubStorageCursors().withoutTokenIndexes();
    IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
    int targetType = 1;
    int notTargetType = 2;
    int[] targetTypeArray = { targetType };
    String targetPropertyKey = "key";
    Value propertyValue = Values.stringValue("value");
    MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
    long id = 0;
    int wantedPropertyUpdates = 5;
    for (int i = 0; i < wantedPropertyUpdates; i++) {
        // Relationship fitting our target
        cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
        relationshipsWithTargetType.add(id++);
        // Relationship with different type
        cursors.withRelationship(id, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
        relationshipsWithTargetType.add(id++);
    }
    int targetPropertyKeyId = cursors.propertyKeyTokenHolder().getIdByName(targetPropertyKey);
    IntPredicate propertyKeyIdFilter = value -> value == targetPropertyKeyId;
    DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
    TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
    TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
    StoreScan storeScan = storeView.visitRelationships(targetTypeArray, propertyKeyIdFilter, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
    storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
    assertThat(tokenConsumer.batches.size()).isEqualTo(1);
    assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexPrototype.forSchema(org.neo4j.internal.schema.IndexPrototype.forSchema) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) Predicates(org.neo4j.function.Predicates) LongLists(org.eclipse.collections.impl.factory.primitive.LongLists) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Value(org.neo4j.values.storable.Value) NULL(org.neo4j.io.pagecache.tracing.PageCacheTracer.NULL) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NullLogProvider(org.neo4j.logging.NullLogProvider) IntPredicate(java.util.function.IntPredicate) Supplier(java.util.function.Supplier) Values(org.neo4j.values.storable.Values) StorageReader(org.neo4j.storageengine.api.StorageReader) JobSchedulerFactory(org.neo4j.kernel.impl.scheduler.JobSchedulerFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) Mockito.when(org.mockito.Mockito.when) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) NO_LOCKS(org.neo4j.kernel.impl.locking.Locks.NO_LOCKS) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) NO_LOCK_SERVICE(org.neo4j.lock.LockService.NO_LOCK_SERVICE) DESCRIPTOR(org.neo4j.kernel.impl.index.schema.TokenIndexProvider.DESCRIPTOR) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) NODE(org.neo4j.common.EntityType.NODE) SchemaDescriptor.forAnyEntityTokens(org.neo4j.internal.schema.SchemaDescriptor.forAnyEntityTokens) Mockito.mock(org.mockito.Mockito.mock) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) IntPredicate(java.util.function.IntPredicate) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Value(org.neo4j.values.storable.Value) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) Test(org.junit.jupiter.api.Test)

Example 22 with MutableLongList

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

the class GenerateIndexUpdatesStepTest method allNodeIds.

private static long[] allNodeIds(StubStorageCursors data) {
    try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL)) {
        cursor.scan();
        MutableLongList ids = LongLists.mutable.empty();
        while (cursor.next()) {
            ids.add(cursor.entityReference());
        }
        return ids.toArray();
    }
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 23 with MutableLongList

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

the class DetectRandomSabotageIT method createNodes.

private MutableLongList createNodes(GraphDatabaseAPI db) {
    MutableLongList nodeIds = LongLists.mutable.empty();
    try (Transaction tx = db.beginTx()) {
        for (int i = 0; i < NUMBER_OF_NODES; i++) {
            Node node = tx.createNode(labels(random.selection(TOKEN_NAMES, 0, TOKEN_NAMES.length, false)));
            setRandomProperties(node);
            nodeIds.add(node.getId());
        }
        tx.commit();
    }
    return nodeIds;
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Example 24 with MutableLongList

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

the class DetectRandomSabotageIT method setUp.

@BeforeEach
protected void setUp() {
    dbms = getDbms(directory.homePath());
    db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
    // Create some nodes
    MutableLongList nodeIds = createNodes(db);
    // Force some nodes to be dense nodes and some to have only a single relationship
    MutableLongSet singleRelationshipNodes = LongSets.mutable.empty();
    MutableLongSet denseNodes = LongSets.mutable.empty();
    while (singleRelationshipNodes.size() < 5) {
        singleRelationshipNodes.add(nodeIds.get(random.nextInt(nodeIds.size())));
    }
    while (denseNodes.size() < 5) {
        long nodeId = nodeIds.get(random.nextInt(nodeIds.size()));
        if (!singleRelationshipNodes.contains(nodeId)) {
            denseNodes.add(nodeId);
        }
    }
    // Connect them with some relationships
    createRelationships(db, nodeIds, singleRelationshipNodes);
    // Make the dense nodes dense by creating many relationships to or from them
    createAdditionalRelationshipsForDenseNodes(db, nodeIds, denseNodes);
    // Delete some entities
    deleteSomeEntities(db, nodeIds, singleRelationshipNodes, denseNodes);
    // Create some indexes and constraints
    createSchema(db);
    neoStores = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    resolver = db.getDependencyResolver();
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with MutableLongList

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

the class TxStateIndexChanges method indexUpdatesForScanAndFilter.

// HELPERS
private static AddedAndRemoved indexUpdatesForScanAndFilter(ReadableTransactionState txState, IndexDescriptor descriptor, PropertyIndexQuery filter, IndexOrder indexOrder) {
    Map<ValueTuple, ? extends LongDiffSets> updates = getUpdates(txState, descriptor, indexOrder);
    if (updates == null) {
        return EMPTY_ADDED_AND_REMOVED;
    }
    MutableLongList added = LongLists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : updates.entrySet()) {
        ValueTuple key = entry.getKey();
        if (filter == null || filter.acceptsValue(key.valueAt(0))) {
            LongDiffSets diffSet = entry.getValue();
            added.addAll(diffSet.getAdded());
            removed.addAll(diffSet.getRemoved());
        }
    }
    return new AddedAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) ValueTuple(org.neo4j.values.storable.ValueTuple) NavigableMap(java.util.NavigableMap) Map(java.util.Map) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

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