use of org.neo4j.function.ThrowingFunction in project neo4j by neo4j.
the class CountsTrackerTest method shouldBeAbleToReadUpToDateValueWhileAnotherThreadIsPerformingRotation.
@Test
public void shouldBeAbleToReadUpToDateValueWhileAnotherThreadIsPerformingRotation() throws Exception {
// given
CountsOracle oracle = someData();
final int firstTransaction = 2, secondTransaction = 3;
try (Lifespan life = new Lifespan()) {
CountsTracker tracker = life.add(newTracker());
oracle.update(tracker, firstTransaction);
tracker.rotate(firstTransaction);
}
// when
final CountsOracle delta = new CountsOracle();
{
CountsOracle.Node n1 = delta.node(1);
// Label 4 has not been used before...
CountsOracle.Node n2 = delta.node(1, 4);
delta.relationship(n1, 1, n2);
// relationshipType 2 has not been used before...
delta.relationship(n2, 2, n1);
}
delta.update(oracle);
try (Lifespan life = new Lifespan()) {
final Barrier.Control barrier = new Barrier.Control();
CountsTracker tracker = life.add(new CountsTracker(resourceManager.logProvider(), resourceManager.fileSystem(), resourceManager.pageCache(), Config.empty(), resourceManager.testPath()) {
@Override
protected boolean include(CountsKey countsKey, ReadableBuffer value) {
barrier.reached();
return super.include(countsKey, value);
}
});
Future<Void> task = threading.execute((ThrowingFunction<CountsTracker, Void, RuntimeException>) t -> {
try {
delta.update(t, secondTransaction);
t.rotate(secondTransaction);
} catch (IOException e) {
throw new AssertionError(e);
}
return null;
}, tracker);
// then
barrier.await();
oracle.verify(tracker);
barrier.release();
task.get();
oracle.verify(tracker);
}
}
Aggregations