Search in sources :

Example 1 with TRIGGER_REBUILD_UPDATED

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());
}
Also used : IndexMap(org.neo4j.kernel.impl.api.index.IndexMap) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) Predicates(org.neo4j.function.Predicates) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) DoubleLatch(org.neo4j.test.DoubleLatch) Mockito.when(org.mockito.Mockito.when) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) ONLINE(org.neo4j.kernel.api.index.InternalIndexState.ONLINE) TRIGGER_REBUILD_UPDATED(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode.TRIGGER_REBUILD_UPDATED) IndexMapSnapshotProvider(org.neo4j.kernel.impl.api.index.IndexMapSnapshotProvider) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) FAILED(org.neo4j.kernel.api.index.InternalIndexState.FAILED) BACKGROUND_REBUILD_UPDATED(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode.BACKGROUND_REBUILD_UPDATED) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) POPULATING(org.neo4j.kernel.api.index.InternalIndexState.POPULATING) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Test (org.junit.Test)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.never (org.mockito.Mockito.never)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 Mockito.when (org.mockito.Mockito.when)1 Predicates (org.neo4j.function.Predicates)1 FAILED (org.neo4j.kernel.api.index.InternalIndexState.FAILED)1 ONLINE (org.neo4j.kernel.api.index.InternalIndexState.ONLINE)1 POPULATING (org.neo4j.kernel.api.index.InternalIndexState.POPULATING)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 NewIndexDescriptorFactory (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory)1 IndexMap (org.neo4j.kernel.impl.api.index.IndexMap)1 IndexMapSnapshotProvider (org.neo4j.kernel.impl.api.index.IndexMapSnapshotProvider)1 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)1 BACKGROUND_REBUILD_UPDATED (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode.BACKGROUND_REBUILD_UPDATED)1 TRIGGER_REBUILD_UPDATED (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode.TRIGGER_REBUILD_UPDATED)1