use of org.neo4j.kernel.impl.store.counts.keys.NodeKey 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);
}
use of org.neo4j.kernel.impl.store.counts.keys.NodeKey in project neo4j by neo4j.
the class CountsSnapshotSerializer method serialize.
public static void serialize(FlushableChannel channel, CountsSnapshot countsSnapshot) throws IOException {
channel.putLong(countsSnapshot.getTxId());
channel.putInt(countsSnapshot.getMap().size());
for (Map.Entry<CountsKey, long[]> pair : countsSnapshot.getMap().entrySet()) {
CountsKey key = pair.getKey();
long[] value = pair.getValue();
switch(key.recordType()) {
case ENTITY_NODE:
if (value.length != 1) {
throw new IllegalArgumentException("CountsKey of type " + key.recordType() + " has an unexpected value.");
}
NodeKey nodeKey = (NodeKey) key;
channel.put(ENTITY_NODE.code);
channel.putInt(nodeKey.getLabelId());
channel.putLong(value[0]);
break;
case ENTITY_RELATIONSHIP:
if (value.length != 1) {
throw new IllegalArgumentException("CountsKey of type " + key.recordType() + " has an unexpected value.");
}
RelationshipKey relationshipKey = (RelationshipKey) key;
channel.put(ENTITY_RELATIONSHIP.code);
channel.putInt(relationshipKey.getStartLabelId());
channel.putInt(relationshipKey.getTypeId());
channel.putInt(relationshipKey.getEndLabelId());
channel.putLong(value[0]);
break;
case INDEX_SAMPLE:
if (value.length != 2) {
throw new IllegalArgumentException("CountsKey of type " + key.recordType() + " has an unexpected value.");
}
IndexSampleKey indexSampleKey = (IndexSampleKey) key;
channel.put(INDEX_SAMPLE.code);
channel.putLong(indexSampleKey.indexId());
channel.putLong(value[0]);
channel.putLong(value[1]);
break;
case INDEX_STATISTICS:
if (value.length != 2) {
throw new IllegalArgumentException("CountsKey of type " + key.recordType() + " has an unexpected value.");
}
IndexStatisticsKey indexStatisticsKey = (IndexStatisticsKey) key;
channel.put(INDEX_STATISTICS.code);
channel.putLong(indexStatisticsKey.indexId());
channel.putLong(value[0]);
channel.putLong(value[1]);
break;
case EMPTY:
throw new IllegalArgumentException("CountsKey of type EMPTY cannot be serialized.");
default:
throw new IllegalArgumentException("The read CountsKey has an unknown type.");
}
}
}
Aggregations