Search in sources :

Example 1 with STARTED

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());
}
Also used : CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) Registers(org.neo4j.register.Registers) Assert.assertSame(org.junit.Assert.assertSame) Future(java.util.concurrent.Future) FakeClock(org.neo4j.time.FakeClock) CountsVisitor(org.neo4j.kernel.impl.api.CountsVisitor) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) CountsKeyFactory(org.neo4j.kernel.impl.store.counts.keys.CountsKeyFactory) DebugUtil.classNameContains(org.neo4j.kernel.impl.util.DebugUtil.classNameContains) Assert.fail(org.junit.Assert.fail) ReadableBuffer(org.neo4j.kernel.impl.store.kvstore.ReadableBuffer) STARTED(org.neo4j.test.rule.Resources.InitialLifecycle.STARTED) Config(org.neo4j.kernel.configuration.Config) CountsOracle(org.neo4j.kernel.impl.store.CountsOracle) Barrier(org.neo4j.test.Barrier) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Predicate(java.util.function.Predicate) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Register(org.neo4j.register.Register) IOFunction(org.neo4j.function.IOFunction) ThrowingFunction(org.neo4j.function.ThrowingFunction) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) DataInitializer(org.neo4j.kernel.impl.store.kvstore.DataInitializer) FILE_IN_EXISTING_DIRECTORY(org.neo4j.test.rule.Resources.TestPath.FILE_IN_EXISTING_DIRECTORY) DebugUtil.stackTraceContains(org.neo4j.kernel.impl.util.DebugUtil.stackTraceContains) RotationTimeoutException(org.neo4j.kernel.impl.store.kvstore.RotationTimeoutException) Rule(org.junit.Rule) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) Resources(org.neo4j.test.rule.Resources) ThreadingRule(org.neo4j.test.rule.concurrent.ThreadingRule) Clock(java.time.Clock) DebugUtil.methodIs(org.neo4j.kernel.impl.util.DebugUtil.methodIs) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Clocks(org.neo4j.time.Clocks) Assert.assertEquals(org.junit.Assert.assertEquals) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Predicates.all(org.neo4j.function.Predicates.all) Mockito.mock(org.mockito.Mockito.mock) FakeClock(org.neo4j.time.FakeClock) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) Register(org.neo4j.register.Register) RotationTimeoutException(org.neo4j.kernel.impl.store.kvstore.RotationTimeoutException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Clock (java.time.Clock)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 Predicate (java.util.function.Predicate)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)1 Assert.assertSame (org.junit.Assert.assertSame)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 IOFunction (org.neo4j.function.IOFunction)1 Predicates.all (org.neo4j.function.Predicates.all)1