private void verifyState(boolean isLogSegmented) throws StoreException {
    verifyRealIndexSanity();
    assertEquals("Incorrect log segment count", isLogSegmented ? 3 : 1, index.getLogSegmentCount());
    NavigableMap<Offset, IndexSegment> realIndex = index.getIndexSegments();
    assertEquals("Number of index segments does not match expected", referenceIndex.size(), realIndex.size());
    Map.Entry<Offset, IndexSegment> realIndexEntry = realIndex.firstEntry();
    for (Map.Entry<Offset, TreeMap<MockId, TreeSet<IndexValue>>> referenceIndexEntry : referenceIndex.entrySet()) {
      assertEquals("Offset of index segment does not match expected", referenceIndexEntry.getKey(),
          realIndexEntry.getKey());
      TreeMap<MockId, TreeSet<IndexValue>> referenceIndexSegment = referenceIndexEntry.getValue();
      IndexSegment realIndexSegment = realIndexEntry.getValue();
      for (Map.Entry<MockId, TreeSet<IndexValue>> referenceIndexSegmentEntry : referenceIndexSegment.entrySet()) {
        MockId id = referenceIndexSegmentEntry.getKey();
        NavigableSet<IndexValue> referenceValues = referenceIndexSegmentEntry.getValue();
        NavigableSet<IndexValue> values = realIndexSegment.find(id);
        assertNotNull("No values returned from real index segment for " + id, values);
        assertTrue("No values returned from real index segment for " + id, values.size() > 0);
        IndexValue value = values.first();
        for (IndexValue referenceValue : referenceValues) {
          assertEquals("Offset does not match", referenceValue.getOffset(), value.getOffset());
          assertEquals("ExpiresAtMs does not match", referenceValue.getExpiresAtMs(), value.getExpiresAtMs());
          assertEquals("Size does not match", referenceValue.getSize(), value.getSize());
          assertEquals("Account ID does not match", referenceValue.getAccountId(), value.getAccountId());
          assertEquals("Container ID does not match", referenceValue.getContainerId(), value.getContainerId());
          assertEquals(
              "Original message offset does not match " + id.toString() + " " + referenceValue + " " + value.toString(),
              referenceValue.getOriginalMessageOffset(), value.getOriginalMessageOffset());
          assertEquals("Flags do not match " + id.toString() + " " + referenceValue.toString() + " " + value.toString(),
              referenceValue.getFlags(), value.getFlags());
          if (index.hardDeleter.enabled.get() && !deletedKeys.contains(referenceIndexSegmentEntry.getKey())) {
            assertEquals("Operation time does not match", referenceValue.getOperationTimeInMs(),
                value.getOperationTimeInMs());
            assertEquals("Value from IndexSegment does not match expected", referenceValue.getBytes(),
                value.getBytes());
          }
          value = values.higher(value);
        }
        assertNull("There are more values in the real index", value);
      }
      realIndexEntry = realIndex.higherEntry(realIndexEntry.getKey());
    }
    assertNull("There should no more index segments left", realIndexEntry);
    // all the elements in the last segment should be in the journal
    assertNotNull("There is no offset in the log that corresponds to the last index segment start offset",
        logOrder.get(referenceIndex.lastKey()));
    Map.Entry<Offset, Pair<MockId, LogEntry>> logEntry = logOrder.floorEntry(referenceIndex.lastKey());
    List<JournalEntry> entries = index.journal.getEntriesSince(referenceIndex.lastKey(), true);
    for (JournalEntry entry : entries) {
      assertNotNull("There are no more entries in the reference log but there are entries in the journal", logEntry);
      assertEquals("Offset in journal not as expected", logEntry.getKey(), entry.getOffset());
      assertEquals("Key in journal not as expected", logEntry.getValue().getFirst(), entry.getKey());
      logEntry = logOrder.higherEntry(logEntry.getKey());
    }
    assertNull("There should be no more entries in the reference log", logEntry);
  }
Verifies that the state in {@link PersistentIndex} is the same as the one in {@link #referenceIndex}.
@param isLogSegmented {@code true} if segmented. {@code false} otherwise.
@throws StoreException
ambry-store/src/test/java/com/github/ambry/store/CuratedLogIndexState.java