use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldNotRunASampleJobWhichIsAlreadyRunning.
@Test
public void shouldNotRunASampleJobWhichIsAlreadyRunning() throws Throwable {
// given
when(config.jobLimit()).thenReturn(2);
JobScheduler jobScheduler = new Neo4jJobScheduler();
jobScheduler.init();
IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
final DoubleLatch latch = new DoubleLatch();
// when
final AtomicInteger count = new AtomicInteger(0);
assertTrue(jobTracker.canExecuteMoreSamplingJobs());
IndexSamplingJob job = new IndexSamplingJob() {
@Override
public void run() {
count.incrementAndGet();
latch.waitForAllToStart();
latch.finish();
}
@Override
public long indexId() {
return indexId12;
}
};
jobTracker.scheduleSamplingJob(job);
jobTracker.scheduleSamplingJob(job);
latch.startAndWaitForAllToStart();
latch.waitForAllToFinish();
assertEquals(1, count.get());
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldNotAcceptMoreJobsThanAllowed.
@Test
public void shouldNotAcceptMoreJobsThanAllowed() throws Throwable {
// given
when(config.jobLimit()).thenReturn(1);
JobScheduler jobScheduler = new Neo4jJobScheduler();
jobScheduler.init();
final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
final DoubleLatch latch = new DoubleLatch();
final DoubleLatch waitingLatch = new DoubleLatch();
// when
assertTrue(jobTracker.canExecuteMoreSamplingJobs());
jobTracker.scheduleSamplingJob(new IndexSamplingJob() {
@Override
public void run() {
latch.startAndWaitForAllToStart();
latch.waitForAllToFinish();
}
@Override
public long indexId() {
return indexId12;
}
});
// then
latch.waitForAllToStart();
assertFalse(jobTracker.canExecuteMoreSamplingJobs());
final AtomicBoolean waiting = new AtomicBoolean(false);
new Thread(() -> {
waiting.set(true);
waitingLatch.startAndWaitForAllToStart();
jobTracker.waitUntilCanExecuteMoreSamplingJobs();
waiting.set(false);
waitingLatch.finish();
}).start();
waitingLatch.waitForAllToStart();
assertTrue(waiting.get());
latch.finish();
waitingLatch.waitForAllToFinish();
assertFalse(waiting.get());
// eventually we accept new jobs
while (!jobTracker.canExecuteMoreSamplingJobs()) {
Thread.yield();
}
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class IndexingServiceTest method shouldWaitForRecoveredUniquenessConstraintIndexesToBeFullyPopulated.
@Test
public void shouldWaitForRecoveredUniquenessConstraintIndexesToBeFullyPopulated() throws Exception {
// I.e. when a uniqueness constraint is created, but database crashes before that schema record
// ends up in the store, so that next start have no choice but to rebuild it.
// GIVEN
final DoubleLatch latch = new DoubleLatch();
ControlledIndexPopulator populator = new ControlledIndexPopulator(latch);
final AtomicLong indexId = new AtomicLong(-1);
IndexingService.Monitor monitor = new IndexingService.MonitorAdapter() {
@Override
public void awaitingPopulationOfRecoveredIndex(long index, NewIndexDescriptor descriptor) {
// When we see that we start to await the index to populate, notify the slow-as-heck
// populator that it can actually go and complete its job.
indexId.set(index);
latch.startAndWaitForAllToStart();
}
};
// leaving out the IndexRule here will have the index being populated from scratch
IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(0, "value", 1)), monitor);
// WHEN initializing, i.e. preparing for recovery
life.init();
// simulating an index being created as part of applying recovered transactions
long fakeOwningConstraintRuleId = 1;
indexing.createIndexes(constraintIndexRule(2, labelId, propertyKeyId, PROVIDER_DESCRIPTOR, fakeOwningConstraintRuleId));
// and then starting, i.e. considering recovery completed
life.start();
// THEN afterwards the index should be ONLINE
assertEquals(2, indexId.get());
assertEquals(ONLINE, indexing.getIndexProxy(indexId.get()).getState());
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class ControlledPopulationSchemaIndexProvider method installPopulationJobCompletionLatch.
public DoubleLatch installPopulationJobCompletionLatch() {
final DoubleLatch populationCompletionLatch = new DoubleLatch();
mockedPopulator = new IndexPopulator.Adapter() {
@Override
public void create() throws IOException {
populationCompletionLatch.startAndWaitForAllToStartAndFinish();
super.create();
}
@Override
public IndexSample sampleResult() {
return new IndexSample();
}
};
return populationCompletionLatch;
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class ContractCheckingIndexProxyTest method shouldNotCloseWhileForcing.
@Test(expected = /* THEN */
IllegalStateException.class)
public void shouldNotCloseWhileForcing() throws IOException {
// GIVEN
final DoubleLatch latch = new DoubleLatch();
final IndexProxy inner = new IndexProxyAdapter() {
@Override
public void force() {
latch.startAndWaitForAllToStartAndFinish();
}
};
final IndexProxy outer = newContractCheckingIndexProxy(inner);
outer.start();
// WHEN
runInSeparateThread(() -> outer.force());
try {
latch.waitForAllToStart();
outer.close();
} finally {
latch.finish();
}
}
Aggregations