InMemoryKeyValueStore implements KeyValueStore<byte[], byte[]> { @Override public byte[] get(byte[] key) { this.metrics.gets().inc(); Preconditions.checkArgument(key != null, "Null argument 'key' not allowed"); byte[] found = this.underlying.get(key); if (found != null) { metrics.bytesRead().inc(found.length); } return found; } 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 testGet() { this.inMemoryKeyValueStore.put(key(0), value(0)); this.inMemoryKeyValueStore.put(key(OTHER_KEY_PREFIX, 1), value(OTHER_VALUE_PREFIX, 1)); assertArrayEquals(value(0), this.inMemoryKeyValueStore.get(key(0))); assertArrayEquals(value(OTHER_VALUE_PREFIX, 1), this.inMemoryKeyValueStore.get(key(OTHER_KEY_PREFIX, 1))); verify(this.getsCounter, times(2)).inc(); verify(this.bytesReadCounter).inc(DEFAULT_VALUE_LENGTH); verify(this.bytesReadCounter).inc(value(OTHER_VALUE_PREFIX, 1).length); }
@Test public void testGetEmpty() { assertNull(this.inMemoryKeyValueStore.get(key(0))); verify(this.getsCounter).inc(); verifyZeroInteractions(this.bytesReadCounter); }