InMemoryKeyValueStore implements KeyValueStore<byte[], byte[]> { @Override public KeyValueSnapshot<byte[], byte[]> snapshot(byte[] from, byte[] to) { Set<Map.Entry<byte[], byte[]>> entries = this.underlying.subMap(from, to).entrySet(); return new KeyValueSnapshot<byte[], byte[]>() { @Override public KeyValueIterator<byte[], byte[]> iterator() { return new InMemoryIterator(entries.iterator(), metrics); } @Override public void close() { } }; } InMemoryKeyValueStore(KeyValueStoreMetrics metrics); @Override byte[] get(byte[] key); @Override void put(byte[] key, byte[] value); @Override void putAll(List<Entry<byte[], byte[]>> entries); @Override void delete(byte[] key); @Override KeyValueIterator<byte[], byte[]> range(byte[] from, byte[] to); @Override KeyValueSnapshot<byte[], byte[]> snapshot(byte[] from, byte[] to); @Override KeyValueIterator<byte[], byte[]> all(); @Override Optional<Path> checkpoint(CheckpointId id); @Override void flush(); @Override void close();  }
@Test public void testSnapshot() { for (int i = 0; i < 10; i++) { this.inMemoryKeyValueStore.put(key(OTHER_KEY_PREFIX, i), value(OTHER_VALUE_PREFIX, i)); this.inMemoryKeyValueStore.put(key(i), value(i)); } KeyValueSnapshot<byte[], byte[]> snapshot = this.inMemoryKeyValueStore.snapshot(key(0), key(5)); KeyValueIterator<byte[], byte[]> iterator = snapshot.iterator(); for (int i = 0; i < 5; i++) { assertEntryEquals(key(i), value(i), iterator.next()); } assertFalse(iterator.hasNext()); verify(this.bytesReadCounter, times(5)).inc(DEFAULT_KEY_LENGTH); verify(this.bytesReadCounter, times(5)).inc(DEFAULT_VALUE_LENGTH); }