private static TestCase buildExpectedRecordsForInsertLatest(final TestCase originalTestCase) {
        final List<TestRecord> originalRecords = originalTestCase.records;
        final List<TestRecord> newRecords = new ArrayList<>();

        for (int i = originalRecords.size() - 1; i >= 0; i--) {
            final TestRecord originalRecord = originalRecords.get(i);
            if (originalRecord.timestamp < INSERT_VALID_FROM_TIMESTAMP) {
                newRecords.add(0, originalRecord);
            } else {
                break;
            }
        }
        newRecords.add(0, new TestRecord(INSERT_VALUE, INSERT_VALID_FROM_TIMESTAMP));
        return new TestCase("expected", INSERT_VALID_TO_TIMESTAMP, newRecords);
    }
These scenarios may only be hit in the event of an earlier exception, such as failure to
write to a particular segment store of {@link RocksDBVersionedStore} resulting in an
inconsistency among segments. These tests verify that the store is able to recover
gracefully even if this happens.
streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBVersionedStoreSegmentValueFormatterTest.java