Search in sources :

Example 6 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 7 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)

Example 8 with CountsKey

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

the class InMemoryCountsStoreCountsSnapshotSerializerIntegrationTest method smallWorkloadOnInMemoryLogTest.

@Test
public void smallWorkloadOnInMemoryLogTest() throws IOException {
    //GIVEN
    InMemoryClosableChannel tempChannel = new InMemoryClosableChannel();
    Map<CountsKey, long[]> map = CountsStoreMapGenerator.simpleCountStoreMap(1);
    CountsSnapshot countsSnapshot = new CountsSnapshot(1, map);
    //WHEN
    serialize(tempChannel, countsSnapshot);
    CountsSnapshot recovered = deserialize(tempChannel);
    //THEN
    Assert.assertEquals(countsSnapshot.getTxId(), recovered.getTxId());
    for (Map.Entry<CountsKey, long[]> pair : countsSnapshot.getMap().entrySet()) {
        long[] value = recovered.getMap().get(pair.getKey());
        Assert.assertNotNull(value);
        Assert.assertArrayEquals(value, pair.getValue());
    }
    for (Map.Entry<CountsKey, long[]> pair : recovered.getMap().entrySet()) {
        long[] value = countsSnapshot.getMap().get(pair.getKey());
        Assert.assertNotNull(value);
        Assert.assertArrayEquals(value, pair.getValue());
    }
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) Map(java.util.Map) Test(org.junit.Test)

Example 9 with CountsKey

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

the class InMemoryCountsStoreSnapshotDeserializerTest method correctlyDeserializeTxIdAndMapSize.

@Test
public void correctlyDeserializeTxIdAndMapSize() throws IOException {
    //GIVEN
    InMemoryCountsStore countStore = new InMemoryCountsStore();
    Map<CountsKey, long[]> updates = new HashMap<>();
    updates.put(CountsKeyFactory.nodeKey(1), new long[] { 1 });
    updates.put(CountsKeyFactory.nodeKey(2), new long[] { 1 });
    updates.put(CountsKeyFactory.nodeKey(3), new long[] { 1 });
    countStore.updateAll(1, updates);
    serializedBytes = ByteBuffer.allocate(1000);
    InMemoryClosableChannel logChannel = new InMemoryClosableChannel(serializedBytes.array(), false);
    serialize(logChannel, countStore.snapshot(1));
    //WHEN
    serializedBytes.position(8);
    //We serialized 3, but now the deserialization should only expect 2.
    serializedBytes.putInt(2);
    //THEN
    CountsSnapshot countsSnapshot = deserialize(logChannel);
    assertEquals(2, countsSnapshot.getMap().size());
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) Test(org.junit.Test)

Example 10 with CountsKey

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

the class InMemoryCountsStoreTest method validSnapshot.

@Test
public void validSnapshot() {
    //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
    CountsSnapshot countsSnapshot = countStore.snapshot(1);
    Assert.assertEquals(countsSnapshot.getTxId(), 1);
    Assert.assertEquals(countsSnapshot.getMap().size(), 1);
    Assert.assertEquals(countsSnapshot.getMap().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)

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