use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode.BACKGROUND_REBUILD_UPDATED in project neo4j by neo4j.
the class IndexSamplingControllerTest method shouldNotEmptyQueueConcurrently.
@Test
public void shouldNotEmptyQueueConcurrently() {
// given
final AtomicInteger totalCount = new AtomicInteger(0);
final AtomicInteger concurrentCount = new AtomicInteger(0);
final DoubleLatch jobLatch = new DoubleLatch();
final DoubleLatch testLatch = new DoubleLatch();
final ThreadLocal<Boolean> hasRun = new ThreadLocal<Boolean>() {
@Override
protected Boolean initialValue() {
return false;
}
};
IndexSamplingJobFactory jobFactory = (indexId, proxy) -> {
// make sure we execute this once per thread
if (hasRun.get()) {
return null;
}
hasRun.set(true);
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(false));
when(tracker.canExecuteMoreSamplingJobs()).thenReturn(true);
when(indexProxy.getState()).thenReturn(ONLINE);
// when running once
new Thread(runController(controller, BACKGROUND_REBUILD_UPDATED)).start();
jobLatch.startAndWaitForAllToStart();
testLatch.waitForAllToStart();
// then blocking on first job
assertEquals(1, concurrentCount.get());
assertEquals(1, totalCount.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());
}
use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode.BACKGROUND_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