Search in sources :

Example 1 with NodeKey

use of org.neo4j.kernel.impl.store.counts.keys.NodeKey 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 NodeKey

use of org.neo4j.kernel.impl.store.counts.keys.NodeKey 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 NodeKey

use of org.neo4j.kernel.impl.store.counts.keys.NodeKey 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 NodeKey

use of org.neo4j.kernel.impl.store.counts.keys.NodeKey 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 NodeKey

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

the class InMemoryCountsStoreSnapshotDeserializerTest method correctlyDeserializeEntityNode.

@Test
public void correctlyDeserializeEntityNode() throws IOException {
    //GIVEN
    serializedBytes = ByteBuffer.allocate(1000);
    InMemoryClosableChannel logChannel = new InMemoryClosableChannel(serializedBytes.array(), false);
    writeSimpleHeader(logChannel);
    logChannel.put(ENTITY_NODE.code);
    logChannel.putInt(1);
    logChannel.putLong(1);
    //WHEN
    NodeKey expectedNode = CountsKeyFactory.nodeKey(1);
    CountsSnapshot countsSnapshot = deserialize(logChannel);
    //THEN
    assertNotNull(countsSnapshot.getMap().get(expectedNode));
    assertArrayEquals(new long[] { 1 }, countsSnapshot.getMap().get(expectedNode));
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) NodeKey(org.neo4j.kernel.impl.store.counts.keys.NodeKey) Test(org.junit.Test)

Aggregations

NodeKey (org.neo4j.kernel.impl.store.counts.keys.NodeKey)7 Test (org.junit.Test)6 CountsKey (org.neo4j.kernel.impl.store.counts.keys.CountsKey)6 HashMap (java.util.HashMap)5 Map (java.util.Map)1 IndexSampleKey (org.neo4j.kernel.impl.store.counts.keys.IndexSampleKey)1 IndexStatisticsKey (org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey)1 RelationshipKey (org.neo4j.kernel.impl.store.counts.keys.RelationshipKey)1 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)1