use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode.TRIGGER_REBUILD_UPDATED in project neo4j by neo4j.
the class IndexSamplingControllerTest method shouldNotStartOtherSamplingWhenSamplingAllTheIndexes.
@Test
public void shouldNotStartOtherSamplingWhenSamplingAllTheIndexes() {
// given
final AtomicInteger totalCount = new AtomicInteger(0);
final AtomicInteger concurrentCount = new AtomicInteger(0);
final DoubleLatch jobLatch = new DoubleLatch();
final DoubleLatch testLatch = new DoubleLatch();
IndexSamplingJobFactory jobFactory = (indexId, proxy) -> {
if (!concurrentCount.compareAndSet(0, 1)) {
throw new IllegalStateException("count !== 0 on create");
}
totalCount.incrementAndGet();
jobLatch.waitForAllToStart();
testLatch.startAndWaitForAllToStart();
jobLatch.waitForAllToFinish();
concurrentCount.decrementAndGet();
testLatch.finish();
return null;
};
final IndexSamplingController controller = new IndexSamplingController(samplingConfig, jobFactory, jobQueue, tracker, snapshotProvider, scheduler, always(true));
when(tracker.canExecuteMoreSamplingJobs()).thenReturn(true);
when(indexProxy.getState()).thenReturn(ONLINE);
// when running once
new Thread(runController(controller, TRIGGER_REBUILD_UPDATED)).start();
jobLatch.startAndWaitForAllToStart();
testLatch.waitForAllToStart();
// then blocking on first job
assertEquals(1, concurrentCount.get());
// when running a second time
controller.sampleIndexes(BACKGROUND_REBUILD_UPDATED);
// then no concurrent job execution
jobLatch.finish();
testLatch.waitForAllToFinish();
// and finally exactly one job has run to completion
assertEquals(0, concurrentCount.get());
assertEquals(1, totalCount.get());
}
Aggregations