use of org.neo4j.test.rule.Resources.InitialLifecycle.STARTED in project neo4j by neo4j.
the class CountsTrackerTest method shouldNotEndUpInBrokenStateAfterRotationFailure.
@Test
@Resources.Life(STARTED)
public void shouldNotEndUpInBrokenStateAfterRotationFailure() throws Exception {
// GIVEN
FakeClock clock = Clocks.fakeClock();
CountsTracker tracker = resourceManager.managed(newTracker(clock));
int labelId = 1;
try (CountsAccessor.Updater tx = tracker.apply(2).get()) {
// now at 1
tx.incrementNodeCount(labelId, 1);
}
// WHEN
Predicate<Thread> arrived = thread -> stackTraceContains(thread, all(classNameContains("Rotation"), methodIs("rotate")));
Future<Object> rotation = threading.executeAndAwait(t -> t.rotate(4), tracker, arrived, 100, MILLISECONDS);
try (CountsAccessor.Updater tx = tracker.apply(3).get()) {
// now at 2
tx.incrementNodeCount(labelId, 1);
}
clock.forward(Config.empty().get(GraphDatabaseSettings.counts_store_rotation_timeout) * 2, MILLISECONDS);
try {
rotation.get();
fail("Should've failed rotation due to timeout");
} catch (ExecutionException e) {
// good
assertTrue(e.getCause() instanceof RotationTimeoutException);
}
// THEN
Register.DoubleLongRegister register = Registers.newDoubleLongRegister();
tracker.get(CountsKeyFactory.nodeKey(labelId), register);
assertEquals(2, register.readSecond());
// and WHEN later attempting rotation again
try (CountsAccessor.Updater tx = tracker.apply(4).get()) {
// now at 3
tx.incrementNodeCount(labelId, 1);
}
tracker.rotate(4);
// THEN
tracker.get(CountsKeyFactory.nodeKey(labelId), register);
assertEquals(3, register.readSecond());
}
Aggregations