InMemoryKeyValueStore implements KeyValueStore<byte[], byte[]> { @Override public KeyValueIterator<byte[], byte[]> all() { this.metrics.alls().inc(); return new InMemoryIterator(this.underlying.entrySet().iterator(), this.metrics); } 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 testAll() { Counter allsCounter = mock(Counter.class); when(this.keyValueStoreMetrics.alls()).thenReturn(allsCounter); 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)); } KeyValueIterator<byte[], byte[]> all = this.inMemoryKeyValueStore.all(); for (int i = 0; i < 10; i++) { assertEntryEquals(key(i), value(i), all.next()); } for (int i = 0; i < 10; i++) { assertEntryEquals(key(OTHER_KEY_PREFIX, i), value(OTHER_VALUE_PREFIX, i), all.next()); } assertFalse(all.hasNext()); verify(allsCounter).inc(); verify(this.bytesReadCounter, times(10)).inc(DEFAULT_KEY_LENGTH); int otherKeyLength = key(OTHER_KEY_PREFIX, 0).length; verify(this.bytesReadCounter, times(10)).inc(otherKeyLength); verify(this.bytesReadCounter, times(10)).inc(DEFAULT_VALUE_LENGTH); int otherValueLength = value(OTHER_VALUE_PREFIX, 0).length; verify(this.bytesReadCounter, times(10)).inc(otherValueLength); }