Search in sources :

Example 1 with Stage

use of org.neo4j.internal.batchimport.staging.Stage in project neo4j by neo4j.

the class ReadGroupsFromCacheStepTest method shouldProduceCompleteBatchesPerOwner.

@Test
void shouldProduceCompleteBatchesPerOwner() {
    // GIVEN
    Configuration config = Configuration.withBatchSize(Configuration.DEFAULT, 10);
    Iterator<RelationshipGroupRecord> groups = groups(new Group(1, 3), new Group(2, 3), // ^^^ perfect batch size
    new Group(3, 4), new Group(4, 2), // ^^^ slightly bigger than batch size
    new Group(5, 10), // ^^^ much bigger than batch size
    new Group(6, 35), new Group(7, 2)).iterator();
    final AtomicInteger processCounter = new AtomicInteger();
    Stage stage = new Stage(getClass().getSimpleName(), null, config, 0) {

        {
            add(new ReadGroupsFromCacheStep(control(), config, groups, 1));
            add(new VerifierStep(control(), config, processCounter));
        }
    };
    // WHEN processing the data
    ExecutionSupervisors.superviseDynamicExecution(stage);
    // THEN
    assertEquals(4, processCounter.get());
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Stage(org.neo4j.internal.batchimport.staging.Stage) Test(org.junit.jupiter.api.Test)

Example 2 with Stage

use of org.neo4j.internal.batchimport.staging.Stage in project neo4j by neo4j.

the class ReadEntityIdsStepUsingTokenIndexTest method shouldSeeRecentUpdatesRightInFrontOfExternalUpdatesPoint.

@Test
void shouldSeeRecentUpdatesRightInFrontOfExternalUpdatesPoint() throws Exception {
    // given
    long entityCount = 1_000 + random.nextInt(100);
    BitSet expectedEntityIds = new BitSet();
    BitSet seenEntityIds = new BitSet();
    try (var indexAccessor = indexAccessor()) {
        populateTokenIndex(indexAccessor, expectedEntityIds, entityCount);
        Configuration configuration = withBatchSize(DEFAULT, 100);
        Stage stage = new Stage("Test", null, configuration, 0) {

            {
                add(new ReadEntityIdsStep(control(), configuration, cursorContext -> new TokenIndexScanIdIterator(indexAccessor.newTokenReader(), new int[] { TOKEN_ID }, CursorContext.NULL), NULL, new ControlledUpdatesCheck(indexAccessor, expectedEntityIds), new AtomicBoolean(true)));
                add(new CollectEntityIdsStep(control(), configuration, seenEntityIds));
            }
        };
        // when
        stage.execute().awaitCompletion();
        // then
        assertThat(seenEntityIds).isEqualTo(expectedEntityIds);
    }
}
Also used : RandomExtension(org.neo4j.test.extension.RandomExtension) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Stage(org.neo4j.internal.batchimport.staging.Stage) Config(org.neo4j.configuration.Config) NULL(org.neo4j.io.pagecache.tracing.PageCacheTracer.NULL) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) GraphDatabaseSettings.preallocate_logical_logs(org.neo4j.configuration.GraphDatabaseSettings.preallocate_logical_logs) Configuration.withBatchSize(org.neo4j.internal.batchimport.Configuration.withBatchSize) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) BatchSender(org.neo4j.internal.batchimport.staging.BatchSender) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Inject(org.neo4j.test.extension.Inject) RandomRule(org.neo4j.test.rule.RandomRule) StageControl(org.neo4j.internal.batchimport.staging.StageControl) PageCache(org.neo4j.io.pagecache.PageCache) EMPTY_LONG_ARRAY(org.neo4j.collection.PrimitiveLongCollections.EMPTY_LONG_ARRAY) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) Configuration(org.neo4j.internal.batchimport.Configuration) ExternalUpdatesCheck(org.neo4j.kernel.impl.api.index.StoreScan.ExternalUpdatesCheck) TestDirectory(org.neo4j.test.rule.TestDirectory) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) TokenIndexAccessor(org.neo4j.kernel.impl.index.schema.TokenIndexAccessor) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) IndexFiles(org.neo4j.kernel.impl.index.schema.IndexFiles) Test(org.junit.jupiter.api.Test) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) ProcessorStep(org.neo4j.internal.batchimport.staging.ProcessorStep) DatabaseIndexContext(org.neo4j.kernel.impl.index.schema.DatabaseIndexContext) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) EntityType(org.neo4j.common.EntityType) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) AnyTokenSchemaDescriptor(org.neo4j.internal.schema.AnyTokenSchemaDescriptor) BitSet(java.util.BitSet) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) GraphDatabaseSettings.neo4j_home(org.neo4j.configuration.GraphDatabaseSettings.neo4j_home) DEFAULT(org.neo4j.internal.batchimport.Configuration.DEFAULT) ONLINE(org.neo4j.kernel.impl.api.index.IndexUpdateMode.ONLINE) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Configuration(org.neo4j.internal.batchimport.Configuration) BitSet(java.util.BitSet) Stage(org.neo4j.internal.batchimport.staging.Stage) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 Stage (org.neo4j.internal.batchimport.staging.Stage)2 BitSet (java.util.BitSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 EMPTY_LONG_ARRAY (org.neo4j.collection.PrimitiveLongCollections.EMPTY_LONG_ARRAY)1 EntityType (org.neo4j.common.EntityType)1 Config (org.neo4j.configuration.Config)1 DEFAULT_DATABASE_NAME (org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME)1 GraphDatabaseSettings.neo4j_home (org.neo4j.configuration.GraphDatabaseSettings.neo4j_home)1 GraphDatabaseSettings.preallocate_logical_logs (org.neo4j.configuration.GraphDatabaseSettings.preallocate_logical_logs)1 RecoveryCleanupWorkCollector.immediate (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate)1 Configuration (org.neo4j.internal.batchimport.Configuration)1 DEFAULT (org.neo4j.internal.batchimport.Configuration.DEFAULT)1 Configuration.withBatchSize (org.neo4j.internal.batchimport.Configuration.withBatchSize)1 BatchSender (org.neo4j.internal.batchimport.staging.BatchSender)1 ProcessorStep (org.neo4j.internal.batchimport.staging.ProcessorStep)1 StageControl (org.neo4j.internal.batchimport.staging.StageControl)1