InMemoryKeyValueStore implements KeyValueStore<byte[], byte[]> { @Override public KeyValueIterator<byte[], byte[]> range(byte[] from, byte[] to) { this.metrics.ranges().inc(); Preconditions.checkArgument(from != null, "Null argument 'from' not allowed"); Preconditions.checkArgument(to != null, "Null argument 'to' not allowed"); return new InMemoryIterator(this.underlying.subMap(from, to).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 testRange() { Counter rangesCounter = mock(Counter.class); when(this.keyValueStoreMetrics.ranges()).thenReturn(rangesCounter); 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[]> range = this.inMemoryKeyValueStore.range(key(0), key(5)); for (int i = 0; i < 5; i++) { assertEntryEquals(key(i), value(i), range.next()); } assertFalse(range.hasNext()); verify(rangesCounter).inc(); verify(this.bytesReadCounter, times(5)).inc(DEFAULT_KEY_LENGTH); verify(this.bytesReadCounter, times(5)).inc(DEFAULT_VALUE_LENGTH); }