Search in sources :

Example 21 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method shouldSendSingleBatchIfBelowMaxSizeThreshold.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldSendSingleBatchIfBelowMaxSizeThreshold(boolean alsoWrite) throws Exception {
    // given
    StubStorageCursors data = someUniformData(10);
    TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        assertThat(sender.batches).isEmpty();
        assertThat(scanConsumer.batches.size()).isEqualTo(1);
        assertThat(scanConsumer.batches.get(0).size()).isEqualTo(10);
    } else {
        assertThat(sender.batches.size()).isEqualTo(1);
        assertThat(scanConsumer.batches).isEmpty();
    }
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method shouldGenerateEntityTokenUpdates.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateEntityTokenUpdates(boolean alsoWrite) throws Exception {
    // given
    StubStorageCursors data = someUniformData(10);
    TestTokenScanConsumer scanConsumer = new TestTokenScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, null, scanConsumer, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
    Set<TestTokenScanConsumer.Record> expectedUpdates = new HashSet<>();
    try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL)) {
        cursor.scan();
        while (cursor.next()) {
            expectedUpdates.add(new TestTokenScanConsumer.Record(cursor.entityReference(), cursor.labels()));
        }
    }
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        for (TestTokenScanConsumer.Record tokenUpdate : scanConsumer.batches.get(0)) {
            assertThat(expectedUpdates.remove(tokenUpdate)).isTrue();
        }
    } else {
        GeneratedIndexUpdates updates = sender.batches.get(0);
        updates.completeBatch();
        for (TestTokenScanConsumer.Record tokenUpdate : scanConsumer.batches.get(0)) {
            assertThat(expectedUpdates.remove(tokenUpdate)).isTrue();
        }
    }
    assertThat(expectedUpdates).isEmpty();
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) HashSet(java.util.HashSet) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project neo4j by neo4j.

the class StoreScanStageTest method shouldGenerateUpdatesInParallel.

@ValueSource(booleans = { true, false })
@ParameterizedTest(name = "parallelWrite={0}")
void shouldGenerateUpdatesInParallel(boolean parallelWrite) {
    // given
    StubStorageCursors data = someData();
    EntityIdIterator entityIdIterator = new CursorEntityIdIterator<>(data.allocateNodeCursor(NULL));
    var propertyConsumer = new ThreadCapturingPropertyConsumer();
    var tokenConsumer = new ThreadCapturingTokenConsumer();
    ControlledLockFunction lockFunction = new ControlledLockFunction();
    StoreScanStage<StorageNodeCursor> scan = new StoreScanStage<>(dbConfig, config, ct -> entityIdIterator, NO_EXTERNAL_UPDATES, new AtomicBoolean(true), data, new int[] { LABEL }, alwaysTrue(), propertyConsumer, tokenConsumer, new NodeCursorBehaviour(data), lockFunction, parallelWrite, jobScheduler, PageCacheTracer.NULL, EmptyMemoryTracker.INSTANCE);
    // when
    runScan(scan);
    // then it completes and we see > 1 threads
    assertThat(lockFunction.seenThreads.size()).isGreaterThan(1);
    if (parallelWrite) {
        assertThat(propertyConsumer.seenThreads.size()).isGreaterThan(1);
        assertThat(tokenConsumer.seenThreads.size()).isGreaterThan(1);
    } else {
        assertThat(propertyConsumer.seenThreads.size()).isEqualTo(1);
        assertThat(tokenConsumer.seenThreads.size()).isEqualTo(1);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project neo4j by neo4j.

the class RelationshipLockHelperTest method shouldTakeAllRelevantLocksForDeletion.

@ParameterizedTest
@ValueSource(ints = { 1, 10, 100, 1000 })
void shouldTakeAllRelevantLocksForDeletion(int numNodes) {
    // Given
    MutableLongObjectMap<RecordAccess.RecordProxy<RelationshipRecord, Void>> proxies = LongObjectMaps.mutable.empty();
    MutableLongBag expectedLocks = LongBags.mutable.empty();
    MutableLongSet idsToDelete = LongSets.mutable.empty();
    int maxId = numNodes * 10;
    for (int i = 0; i < numNodes; i++) {
        long id = random.nextInt(maxId);
        if (idsToDelete.add(id)) {
            VolatileRelationshipRecord record = new VolatileRelationshipRecord(id, expectedLocks, maxId);
            var proxy = mock(RecordAccess.RecordProxy.class);
            when(proxy.forReadingLinkage()).thenAnswer(invocation -> new RelationshipRecord(record.maybeChange()));
            proxies.put(id, proxy);
        }
    }
    RecordAccess<RelationshipRecord, Void> relRecords = mock(RecordAccess.class);
    when(relRecords.getOrLoad(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenAnswer(invocation -> proxies.get(invocation.getArgument(0)));
    TrackingResourceLocker locks = new TrackingResourceLocker(random, NO_MONITOR).withStrictAssertionsOn(ResourceTypes.RELATIONSHIP);
    // When
    RelationshipLockHelper.lockRelationshipsInOrder(idsAsBatch(idsToDelete), NULL_REFERENCE.longValue(), relRecords, locks, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
    // Then
    assertThat(locks.getExclusiveLocks(ResourceTypes.RELATIONSHIP).toSortedArray()).containsExactly(expectedLocks.toSet().toSortedArray());
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project neo4j by neo4j.

the class PropertyDeleterTest method shouldHandlePropertyChainDeletionOnUnusedRecord.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldHandlePropertyChainDeletionOnUnusedRecord(boolean log) {
    // given
    startStore(log);
    NodeStore nodeStore = neoStores.getNodeStore();
    NodeRecord node = nodeStore.newRecord();
    node.setId(nodeStore.nextId(NULL));
    List<PropertyBlock> properties = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        properties.add(encodedValue(i, random.nextValue()));
    }
    DirectRecordAccessSet initialChanges = new DirectRecordAccessSet(neoStores, idGeneratorFactory, NULL);
    long firstPropId = propertyCreator.createPropertyChain(node, properties.iterator(), initialChanges.getPropertyRecords());
    node.setNextProp(firstPropId);
    // should update all the changed records directly into the store
    initialChanges.commit();
    // create a cycle in the property chain A -> B
    // ^---v
    List<Value> valuesInTheFirstTwoRecords = new ArrayList<>();
    PropertyRecord firstPropRecord = propertyStore.getRecord(firstPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    readValuesFromPropertyRecord(firstPropRecord, valuesInTheFirstTwoRecords);
    long secondPropId = firstPropRecord.getNextProp();
    PropertyRecord secondPropRecord = propertyStore.getRecord(secondPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    readValuesFromPropertyRecord(secondPropRecord, valuesInTheFirstTwoRecords);
    long thirdPropId = secondPropRecord.getNextProp();
    PropertyRecord thirdPropRecord = propertyStore.getRecord(thirdPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    thirdPropRecord.setInUse(false);
    propertyStore.updateRecord(thirdPropRecord, NULL);
    // when
    DirectRecordAccessSet changes = new DirectRecordAccessSet(neoStores, idGeneratorFactory, NULL);
    deleter.deletePropertyChain(node, changes.getPropertyRecords());
    changes.commit();
    // then
    assertEquals(Record.NO_NEXT_PROPERTY.longValue(), node.getNextProp());
    assertFalse(propertyStore.getRecord(firstPropId, propertyStore.newRecord(), RecordLoad.CHECK, NULL).inUse());
    assertFalse(propertyStore.getRecord(secondPropId, propertyStore.newRecord(), RecordLoad.CHECK, NULL).inUse());
    assertLogContains("Deleted inconsistent property chain with unused record", log);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayList(java.util.ArrayList) Value(org.neo4j.values.storable.Value) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)266 ValueSource (org.junit.jupiter.params.provider.ValueSource)266 HashSet (java.util.HashSet)23 HistogramTestUtils.constructDoubleHistogram (org.HdrHistogram.HistogramTestUtils.constructDoubleHistogram)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)20 ApiResponse (org.hisp.dhis.dto.ApiResponse)15 UpdateModel (com.synopsys.integration.alert.update.model.UpdateModel)13 File (java.io.File)13 List (java.util.List)13 OffsetDateTime (java.time.OffsetDateTime)10 Map (java.util.Map)10 TimeUnit (java.util.concurrent.TimeUnit)10 TopicPartition (org.apache.kafka.common.TopicPartition)9 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)8 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)8 ZooKeeper (org.apache.zookeeper.ZooKeeper)8 JsonObject (com.google.gson.JsonObject)7 IOException (java.io.IOException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7