InMemoryKeyValueStore implements KeyValueStore<byte[], byte[]> { @Override public void put(byte[] key, byte[] value) { this.metrics.puts().inc(); Preconditions.checkArgument(key != null, "Null argument 'key' not allowed"); if (value == null) { this.metrics.deletes().inc(); this.underlying.remove(key); } else { this.metrics.bytesWritten().inc(key.length + value.length); this.underlying.put(key, value); } } 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 testPut() { 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.putsCounter, times(2)).inc(); verify(this.bytesWrittenCounter).inc(DEFAULT_KEY_LENGTH + DEFAULT_VALUE_LENGTH); verify(this.bytesWrittenCounter).inc(key(OTHER_KEY_PREFIX, 1).length + value(OTHER_VALUE_PREFIX, 1).length); }