@Test
  public void testSnapshotImmutable() {
    for (int i = 0; i < 10; i++) {
      this.inMemoryKeyValueStore.put(key(i), value(i));
    }
    KeyValueSnapshot<byte[], byte[]> snapshot = this.inMemoryKeyValueStore.snapshot(key(0), key(5));
    // make sure the entries in the snapshot don't change when something is added
    this.inMemoryKeyValueStore.put(key(1), value(OTHER_VALUE_PREFIX, 1));
    KeyValueIterator<byte[], byte[]> iterator = snapshot.iterator();

    for (int i = 0; i < 5; i++) {
      if (i == 1) {
        /*
         * There is a bug in which the snapshot is impacted by writes after calling snapshot.
         * When the bug is fixed, the value for key(1) should be the original value from when snapshot was called.
         */
        assertEntryEquals(key(i), value(OTHER_VALUE_PREFIX, 1), iterator.next());
      } else {
        assertEntryEquals(key(i), value(i), iterator.next());
      }
    }
    assertFalse(iterator.hasNext());
    // key size increments; key(i) produces byte[] of same length
    verify(this.bytesReadCounter, times(5)).inc(DEFAULT_KEY_LENGTH);
    // value size increments; value(i) produces byte[] of same length
    verify(this.bytesReadCounter, times(4)).inc(DEFAULT_VALUE_LENGTH);
    // when snapshot immutability bug is fixed, this should be merged into the bytesRead check above
    verify(this.bytesReadCounter).inc(value(OTHER_VALUE_PREFIX, 1).length);
  }
The length of the result of {@link #value(int)} will always be the same, so this can be used as the length for any
key produced by {@link #value(int)}.
samza-kv-inmemory/src/test/java/org/apache/samza/storage/kv/inmemory/TestInMemoryKeyValueStore.java