Search in sources :

Example 1 with ReadableBuffer

use of org.neo4j.kernel.impl.store.kvstore.ReadableBuffer 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);
    }
}
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) Barrier(org.neo4j.test.Barrier) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) IOException(java.io.IOException) ReadableBuffer(org.neo4j.kernel.impl.store.kvstore.ReadableBuffer) CountsOracle(org.neo4j.kernel.impl.store.CountsOracle) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) 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