use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class CheckPointSchedulerTest method shouldWaitOnStopUntilTheRunningCheckpointIsDone.
@Test
public void shouldWaitOnStopUntilTheRunningCheckpointIsDone() throws Throwable {
// given
final AtomicReference<Throwable> ex = new AtomicReference<>();
final AtomicBoolean stoppedCompleted = new AtomicBoolean();
final DoubleLatch checkPointerLatch = new DoubleLatch(1);
CheckPointer checkPointer = new CheckPointer() {
@Override
public long checkPointIfNeeded(TriggerInfo triggerInfo) throws IOException {
checkPointerLatch.startAndWaitForAllToStart();
checkPointerLatch.waitForAllToFinish();
return 42;
}
@Override
public long tryCheckPoint(TriggerInfo triggerInfo) throws IOException {
throw new RuntimeException("this should have not been called");
}
@Override
public long forceCheckPoint(TriggerInfo triggerInfo) throws IOException {
throw new RuntimeException("this should have not been called");
}
@Override
public long lastCheckPointedTransactionId() {
return 42;
}
};
final CheckPointScheduler scheduler = new CheckPointScheduler(checkPointer, jobScheduler, 20L, health);
// when
scheduler.start();
Thread runCheckPointer = new Thread() {
@Override
public void run() {
jobScheduler.runJob();
}
};
runCheckPointer.start();
checkPointerLatch.waitForAllToStart();
Thread stopper = new Thread() {
@Override
public void run() {
try {
scheduler.stop();
stoppedCompleted.set(true);
} catch (Throwable throwable) {
ex.set(throwable);
}
}
};
stopper.start();
Thread.sleep(10);
// then
assertFalse(stoppedCompleted.get());
checkPointerLatch.finish();
runCheckPointer.join();
Thread.sleep(150);
assertTrue(stoppedCompleted.get());
// just in case
stopper.join();
assertNull(ex.get());
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class IndexRestartIT method shouldBeAbleToDropIndexWhileItIsPopulating.
/* This is somewhat difficult to test since dropping an index while it's populating forces it to be cancelled
* first (and also awaiting cancellation to complete). So this is a best-effort to have the timing as close
* as possible. If this proves to be flaky, remove it right away.
*/
@Test
public void shouldBeAbleToDropIndexWhileItIsPopulating() throws Exception {
// GIVEN
startDb();
DoubleLatch populationCompletionLatch = provider.installPopulationJobCompletionLatch();
IndexDefinition index = createIndex();
// await population job to start
populationCompletionLatch.waitForAllToStart();
// WHEN
dropIndex(index, populationCompletionLatch);
// THEN
assertThat(getIndexes(db, myLabel), inTx(db, hasSize(0)));
try {
getIndexState(db, index);
fail("This index should have been deleted");
} catch (NotFoundException e) {
assertThat(e.getMessage(), CoreMatchers.containsString(myLabel.name()));
}
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class ContractCheckingIndexProxyTest method shouldNotCloseWhileCreating.
@Test(expected = /* THEN */
IllegalStateException.class)
public void shouldNotCloseWhileCreating() throws IOException {
// GIVEN
final DoubleLatch latch = new DoubleLatch();
final IndexProxy inner = new IndexProxyAdapter() {
@Override
public void start() {
latch.startAndWaitForAllToStartAndFinish();
}
};
final IndexProxy outer = newContractCheckingIndexProxy(inner);
// WHEN
runInSeparateThread(() -> outer.start());
try {
latch.waitForAllToStart();
outer.close();
} finally {
latch.finish();
}
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class ContractCheckingIndexProxyTest method shouldNotCloseWhileUpdating.
@Test(expected = /* THEN */
IllegalStateException.class)
public void shouldNotCloseWhileUpdating() throws IOException {
// GIVEN
final DoubleLatch latch = new DoubleLatch();
final IndexProxy inner = new IndexProxyAdapter() {
@Override
public IndexUpdater newUpdater(IndexUpdateMode mode) {
return super.newUpdater(mode);
}
};
final IndexProxy outer = newContractCheckingIndexProxy(inner);
outer.start();
// WHEN
runInSeparateThread(() -> {
try (IndexUpdater updater = outer.newUpdater(IndexUpdateMode.ONLINE)) {
updater.process(null);
latch.startAndWaitForAllToStartAndFinish();
} catch (IndexEntryConflictException e) {
throw new RuntimeException(e);
}
});
try {
latch.waitForAllToStart();
outer.close();
} finally {
latch.finish();
}
}
use of org.neo4j.test.DoubleLatch in project neo4j by neo4j.
the class ContractCheckingIndexProxyTest method shouldNotDropWhileCreating.
@Test(expected = /* THEN */
IllegalStateException.class)
public void shouldNotDropWhileCreating() throws IOException {
// GIVEN
final DoubleLatch latch = new DoubleLatch();
final IndexProxy inner = new IndexProxyAdapter() {
@Override
public void start() {
latch.startAndWaitForAllToStartAndFinish();
}
};
final IndexProxy outer = newContractCheckingIndexProxy(inner);
// WHEN
runInSeparateThread(() -> outer.start());
try {
latch.waitForAllToStart();
outer.drop();
} finally {
latch.finish();
}
}
Aggregations