@Test
  public void testRangeWithUpdate() {
    Counter rangesCounter = mock(Counter.class);
    when(this.keyValueStoreMetrics.ranges()).thenReturn(rangesCounter);

    // exclude the index 1 entry so it can be added later
    for (int i = 0; i < 10; i++) {
      if (i != 1) {
        this.inMemoryKeyValueStore.put(key(i), value(i));
      }
    }
    KeyValueIterator<byte[], byte[]> range = this.inMemoryKeyValueStore.range(key(0), key(5));
    assertEquals(4, Iterators.size(range));

    this.inMemoryKeyValueStore.delete(key(2)); // delete an entry from the range
    this.inMemoryKeyValueStore.put(key(3), value(OTHER_VALUE_PREFIX, 3)); // update an entry
    this.inMemoryKeyValueStore.put(key(1), value(DEFAULT_VALUE_PREFIX, 1)); // add a new entry
    range = this.inMemoryKeyValueStore.range(key(0), key(5));
    for (int i = 0; i < 5; i++) {
      if (i != 2) { // index 2 was deleted
        if (i == 3) { // index 3 has an updated value
          assertEntryEquals(key(i), value(OTHER_VALUE_PREFIX, 3), range.next());
        } else {
          // all other entries (including index 1 have the "normal" entries)
          assertEntryEquals(key(i), value(DEFAULT_VALUE_PREFIX, i), range.next());
        }
      }
    }
    assertFalse(range.hasNext());

    verify(rangesCounter, times(2)).inc();
    // key increments: 4 for iterator size for first range, 4 for second range; key(i) produces byte[] of same length
    verify(this.bytesReadCounter, times(8)).inc(DEFAULT_KEY_LENGTH);
    /*
     * value increments: 4 for iterator size for first range, 3 for second range (updated entry is different); value(i)
     * produces byte[] of same length
     */
    verify(this.bytesReadCounter, times(7)).inc(DEFAULT_VALUE_LENGTH);
    // 1 call for updated entry
    verify(this.bytesReadCounter).inc(value(OTHER_VALUE_PREFIX, 0).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