Search in sources :

Example 1 with CountsOracle

use of org.neo4j.kernel.impl.store.CountsOracle in project neo4j by neo4j.

the class CountsTrackerTest method shouldStoreCounts.

@Test
public void shouldStoreCounts() throws Exception {
    // given
    CountsOracle oracle = someData();
    // when
    try (Lifespan life = new Lifespan()) {
        CountsTracker tracker = life.add(newTracker());
        oracle.update(tracker, 2);
        tracker.rotate(2);
    }
    // then
    try (Lifespan life = new Lifespan()) {
        oracle.verify(life.add(newTracker()));
    }
}
Also used : CountsOracle(org.neo4j.kernel.impl.store.CountsOracle) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Example 2 with CountsOracle

use of org.neo4j.kernel.impl.store.CountsOracle in project neo4j by neo4j.

the class CountsTrackerTest method shouldBeAbleToWriteDataToCountsTracker.

@Test
@Resources.Life(STARTED)
public void shouldBeAbleToWriteDataToCountsTracker() throws Exception {
    // given
    CountsTracker tracker = resourceManager.managed(newTracker());
    long indexId = 0;
    CountsOracle oracle = new CountsOracle();
    {
        CountsOracle.Node a = oracle.node(1);
        CountsOracle.Node b = oracle.node(1);
        oracle.relationship(a, 1, b);
        oracle.indexSampling(indexId, 2, 2);
        oracle.indexUpdatesAndSize(indexId, 10, 2);
    }
    // when
    oracle.update(tracker, 2);
    // then
    oracle.verify(tracker);
    // when
    tracker.rotate(2);
    // then
    oracle.verify(tracker);
    // when
    try (CountsAccessor.IndexStatsUpdater updater = tracker.updateIndexCounts()) {
        updater.incrementIndexUpdates(indexId, 2);
    }
    // then
    oracle.indexUpdatesAndSize(indexId, 12, 2);
    oracle.verify(tracker);
    // when
    tracker.rotate(2);
    // then
    oracle.verify(tracker);
}
Also used : CountsOracle(org.neo4j.kernel.impl.store.CountsOracle) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) Test(org.junit.Test)

Example 3 with CountsOracle

use of org.neo4j.kernel.impl.store.CountsOracle in project neo4j by neo4j.

the class CountsTrackerTest method someData.

private CountsOracle someData() {
    CountsOracle oracle = new CountsOracle();
    CountsOracle.Node n0 = oracle.node(0, 1);
    CountsOracle.Node n1 = oracle.node(0, 3);
    CountsOracle.Node n2 = oracle.node(2, 3);
    CountsOracle.Node n3 = oracle.node(2);
    oracle.relationship(n0, 1, n2);
    oracle.relationship(n1, 1, n3);
    oracle.relationship(n1, 1, n2);
    oracle.relationship(n0, 1, n3);
    long indexId = 2;
    oracle.indexUpdatesAndSize(indexId, 0L, 50L);
    oracle.indexSampling(indexId, 25L, 50L);
    return oracle;
}
Also used : CountsOracle(org.neo4j.kernel.impl.store.CountsOracle)

Example 4 with CountsOracle

use of org.neo4j.kernel.impl.store.CountsOracle 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)

Example 5 with CountsOracle

use of org.neo4j.kernel.impl.store.CountsOracle in project neo4j by neo4j.

the class CountsTrackerTest method shouldUpdateCountsOnExistingStore.

@Test
public void shouldUpdateCountsOnExistingStore() throws Exception {
    // given
    CountsOracle oracle = someData();
    int firstTx = 2, secondTx = 3;
    try (Lifespan life = new Lifespan()) {
        CountsTracker tracker = life.add(newTracker());
        oracle.update(tracker, firstTx);
        tracker.rotate(firstTx);
        oracle.verify(tracker);
        // when
        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(tracker, secondTx);
        delta.update(oracle);
        // then
        oracle.verify(tracker);
        // when
        tracker.rotate(secondTx);
    }
    // then
    try (Lifespan life = new Lifespan()) {
        oracle.verify(life.add(newTracker()));
    }
}
Also used : CountsOracle(org.neo4j.kernel.impl.store.CountsOracle) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Aggregations

CountsOracle (org.neo4j.kernel.impl.store.CountsOracle)5 Test (org.junit.Test)4 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)3 CountsAccessor (org.neo4j.kernel.impl.api.CountsAccessor)2 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 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1