Search in sources :

Example 1 with CountsKey

use of org.neo4j.kernel.impl.store.counts.keys.CountsKey in project neo4j by neo4j.

the class InMemoryCountsStoreTest method restoreFromSnapshot.

@Test
public void restoreFromSnapshot() {
    //GIVEN
    InMemoryCountsStore countStore = new InMemoryCountsStore();
    Map<CountsKey, long[]> update = new HashMap<>();
    NodeKey keyA = CountsKeyFactory.nodeKey(1);
    NodeKey keyB = CountsKeyFactory.nodeKey(2);
    NodeKey keyC = CountsKeyFactory.nodeKey(3);
    update.put(keyA, new long[] { 1 });
    countStore.updateAll(1, update);
    update.clear();
    update.put(keyB, new long[] { 1 });
    countStore.updateAll(2, update);
    update.clear();
    update.put(keyC, new long[] { 1 });
    countStore.updateAll(3, update);
    //WHEN
    CountsSnapshot countsSnapshot = countStore.snapshot(3);
    long beforeTxId = countsSnapshot.getTxId();
    Assert.assertEquals(3, beforeTxId);
    countStore = new InMemoryCountsStore(countsSnapshot);
    //THEN
    CountsSnapshot secondCountsSnapshot = countStore.snapshot(3);
    Assert.assertEquals(3, secondCountsSnapshot.getTxId());
    update.put(keyC, new long[] { 1 });
    countStore.updateAll(4, update);
    CountsSnapshot thirdCountsSnapshot = countStore.snapshot(4);
    Assert.assertEquals(4, thirdCountsSnapshot.getTxId());
}
Also used : HashMap(java.util.HashMap) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) NodeKey(org.neo4j.kernel.impl.store.counts.keys.NodeKey) Test(org.junit.Test)

Example 2 with CountsKey

use of org.neo4j.kernel.impl.store.counts.keys.CountsKey in project neo4j by neo4j.

the class InMemoryCountsStoreTest method getExpectedValue.

@Test
public void getExpectedValue() {
    //GIVEN
    InMemoryCountsStore countStore = new InMemoryCountsStore();
    Map<CountsKey, long[]> update = new HashMap<>();
    NodeKey key = CountsKeyFactory.nodeKey(1);
    update.put(key, new long[] { 1 });
    //WHEN
    countStore.updateAll(1, update);
    //THEN
    Assert.assertEquals(countStore.get(key)[0], 1);
}
Also used : HashMap(java.util.HashMap) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) NodeKey(org.neo4j.kernel.impl.store.counts.keys.NodeKey) Test(org.junit.Test)

Example 3 with CountsKey

use of org.neo4j.kernel.impl.store.counts.keys.CountsKey in project neo4j by neo4j.

the class InMemoryCountsStoreTest method getNullKeyResultsInNPE.

@Test(expected = NullPointerException.class)
public void getNullKeyResultsInNPE() {
    //GIVEN
    InMemoryCountsStore countStore = new InMemoryCountsStore();
    Map<CountsKey, long[]> update = new HashMap<>();
    NodeKey key = CountsKeyFactory.nodeKey(1);
    update.put(key, new long[] { 1 });
    //WHEN
    countStore.updateAll(1, update);
    //THEN throws
    countStore.get(null);
}
Also used : HashMap(java.util.HashMap) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) NodeKey(org.neo4j.kernel.impl.store.counts.keys.NodeKey) Test(org.junit.Test)

Example 4 with CountsKey

use of org.neo4j.kernel.impl.store.counts.keys.CountsKey in project neo4j by neo4j.

the class InMemoryCountsStoreTest method neverSetKeyReturnsNull.

@Test
public void neverSetKeyReturnsNull() {
    //GIVEN
    InMemoryCountsStore countStore = new InMemoryCountsStore();
    Map<CountsKey, long[]> update = new HashMap<>();
    NodeKey key = CountsKeyFactory.nodeKey(1);
    update.put(key, new long[] { 1 });
    //WHEN
    countStore.updateAll(1, update);
    //THEN
    Assert.assertNull(countStore.get(CountsKeyFactory.relationshipKey(1, 1, 1)));
}
Also used : HashMap(java.util.HashMap) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) NodeKey(org.neo4j.kernel.impl.store.counts.keys.NodeKey) Test(org.junit.Test)

Example 5 with CountsKey

use of org.neo4j.kernel.impl.store.counts.keys.CountsKey in project neo4j by neo4j.

the class CountsRotationTest method allRecords.

private Collection<Pair<? extends CountsKey, Long>> allRecords(CountsVisitor.Visitable store) {
    final Collection<Pair<? extends CountsKey, Long>> records = new ArrayList<>();
    store.accept(new CountsVisitor() {

        @Override
        public void visitNodeCount(int labelId, long count) {
            records.add(Pair.of(CountsKeyFactory.nodeKey(labelId), count));
        }

        @Override
        public void visitRelationshipCount(int startLabelId, int typeId, int endLabelId, long count) {
            records.add(Pair.of(CountsKeyFactory.relationshipKey(startLabelId, typeId, endLabelId), count));
        }

        @Override
        public void visitIndexStatistics(long indexId, long updates, long size) {
            records.add(Pair.of(CountsKeyFactory.indexStatisticsKey(indexId), size));
        }

        @Override
        public void visitIndexSample(long indexId, long unique, long size) {
            records.add(Pair.of(CountsKeyFactory.indexSampleKey(indexId), size));
        }
    });
    return records;
}
Also used : CountsVisitor(org.neo4j.kernel.impl.api.CountsVisitor) ArrayList(java.util.ArrayList) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) Pair(org.neo4j.helpers.collection.Pair)

Aggregations

CountsKey (org.neo4j.kernel.impl.store.counts.keys.CountsKey)13 Test (org.junit.Test)9 HashMap (java.util.HashMap)7 NodeKey (org.neo4j.kernel.impl.store.counts.keys.NodeKey)6 Map (java.util.Map)4 File (java.io.File)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountsVisitor (org.neo4j.kernel.impl.api.CountsVisitor)2 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)2 IOException (java.io.IOException)1 Clock (java.time.Clock)1 ArrayList (java.util.ArrayList)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