Search in sources :

Example 16 with Configuration

use of org.neo4j.internal.batchimport.Configuration in project neo4j by neo4j.

the class ProcessorStepTest method shouldHaveTaskQueueSizeEqualToMaxNumberOfProcessors.

@Test
void shouldHaveTaskQueueSizeEqualToMaxNumberOfProcessors() throws Exception {
    // GIVEN
    StageControl control = new SimpleStageControl();
    final CountDownLatch latch = new CountDownLatch(1);
    final int processors = 2;
    int maxProcessors = 5;
    Configuration configuration = new Configuration() {

        @Override
        public int maxNumberOfProcessors() {
            return maxProcessors;
        }
    };
    Future<Void> receiveFuture;
    try (ProcessorStep<Void> step = new BlockingProcessorStep<>(control, configuration, processors, latch)) {
        step.start(ORDER_SEND_DOWNSTREAM);
        // now at 2
        step.processors(1);
        // adding up to max processors should be fine
        for (int i = 0; i < processors + maxProcessors; /* +1 since we allow queueing one more*/
        i++) {
            step.receive(i, null);
        }
        // WHEN
        receiveFuture = t2.execute(receive(processors, step));
        t2.get().waitUntilThreadState(Thread.State.TIMED_WAITING);
        latch.countDown();
        // THEN
        receiveFuture.get();
    }
}
Also used : Configuration(org.neo4j.internal.batchimport.Configuration) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 17 with Configuration

use of org.neo4j.internal.batchimport.Configuration in project neo4j by neo4j.

the class ProcessorStepTest method shouldBeAbleToPropagatePanicOnBlockedProcessors.

private void shouldBeAbleToPropagatePanicOnBlockedProcessors(int numProcessors, int failingProcessorIndex) throws InterruptedException {
    // Given
    String exceptionMessage = "Failing just for fun";
    Configuration configuration = Configuration.DEFAULT;
    CountDownLatch latch = new CountDownLatch(1);
    TrackingPanicMonitor panicMonitor = new TrackingPanicMonitor();
    Stage stage = new Stage("Test", "Part", configuration, ORDER_SEND_DOWNSTREAM, SPAWN_THREAD, panicMonitor);
    stage.add(intProducer(configuration, stage, configuration.maxNumberOfProcessors() * 2));
    ProcessorStep<Integer> failingProcessor = null;
    for (int i = 0; i < numProcessors; i++) {
        if (failingProcessorIndex == i) {
            failingProcessor = new BlockingProcessorStep<>(stage.control(), configuration, 1, latch) {

                @Override
                protected void process(Integer batch, BatchSender sender, CursorContext cursorContext) throws Throwable {
                    // Block until the latch is released below
                    super.process(batch, sender, cursorContext);
                    // Then immediately throw exception so that a panic will be issued
                    throw new RuntimeException(exceptionMessage);
                }
            };
            stage.add(failingProcessor);
        } else {
            stage.add(intProcessor(configuration, stage));
        }
    }
    try {
        // When
        StageExecution execution = stage.execute();
        while (failingProcessor.stats().stat(Keys.received_batches).asLong() < configuration.maxNumberOfProcessors() + 1) {
            Thread.sleep(10);
        }
        latch.countDown();
        // Then
        execution.awaitCompletion();
        RuntimeException exception = assertThrows(RuntimeException.class, execution::assertHealthy);
        assertEquals(exceptionMessage, exception.getMessage());
    } finally {
        stage.close();
    }
    assertTrue(panicMonitor.hasReceivedPanic());
}
Also used : Configuration(org.neo4j.internal.batchimport.Configuration) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

Configuration (org.neo4j.internal.batchimport.Configuration)17 Test (org.junit.jupiter.api.Test)11 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 BitSet (java.util.BitSet)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)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 Extractors (org.neo4j.csv.reader.Extractors)1 RecoveryCleanupWorkCollector.immediate (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate)1