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();
}
}
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());
}
Aggregations