@Test
  public void compatibilityTest() throws StoreException {
    assumeTrue(PersistentIndex.CURRENT_VERSION == PersistentIndex.VERSION_2
        || PersistentIndex.CURRENT_VERSION == PersistentIndex.VERSION_3);
    // change the version to newer version and reload the index.
    PersistentIndex.CURRENT_VERSION = (short) (persistentIndexVersion + 1);
    // reloading the index at new version to test backward compatibility
    state.reloadIndexAndVerifyState(true, false);

    // get some values out to make sure we can read from the old version
    IndexValue value = state.index.findKey(state.liveKeys.iterator().next());
    assertNotNull("New version should be able to read old version live key", value);
    assertEquals("Version doesn't match", persistentIndexVersion, value.getFormatVersion());
    assertFalse("Not deleted", value.isDelete());

    value = state.index.findKey(state.expiredKeys.iterator().next());
    assertNotNull("New version should be able to old version expired key", value);
    assertEquals("Version doesn't match", persistentIndexVersion, value.getFormatVersion());
    assertFalse("Not deleted", value.isDelete());
    assertFalse("Not ttlUpdated", value.isTtlUpdate());

    value = state.index.findKey(state.deletedKeys.iterator().next());
    assertNotNull("New version should be able to old version deleted key", value);
    assertEquals("Version doesn't match", persistentIndexVersion, value.getFormatVersion());
    assertTrue("Not deleted", value.isDelete());

    // If we are here, then at new version we can read all the index entries in old version.
    // Now add some index entries at new version.
    int indexSegmentCount = state.index.getIndexSegments().size();
    IndexEntry entry =
        state.addPutEntries(1, PUT_RECORD_SIZE, state.time.milliseconds() + TimeUnit.DAYS.toMillis(2)).get(0);
    MockId key = (MockId) entry.getKey();
    state.makePermanent(key, false);
    state.addDeleteEntry(key);
    assertEquals("New version entry should roll over to new index segment", indexSegmentCount + 1,
        state.index.getIndexSegments().size());

    value = state.index.findKey(key);
    assertNotNull("New version should be able to new version expired key", value);
    assertEquals("Version doesn't match", PersistentIndex.CURRENT_VERSION, value.getFormatVersion());
    assertTrue("Not deleted", value.isDelete());

    // change the version back to old version, so we can test forward compatibility
    PersistentIndex.CURRENT_VERSION = persistentIndexVersion;
    state.reloadIndexAndVerifyState(true, false);

    // get records written in new version make sure we can read it out.
    value = state.index.findKey(key);
    assertNotNull("Old version should be able to new version expired key", value);
    assertEquals("Version doesn't match", (short) (persistentIndexVersion + 1), value.getFormatVersion());
    assertTrue("Not deleted", value.isDelete());
  }
Test forward and backward compatibility when the version is 2 and then we bump the version to 3 and add some index entries.
make sure those entries can still be read at version 2.
ambry-store/src/test/java/com/github/ambry/store/IndexTest.java