@Test
  public void undeletePutCompactedTest() throws Exception {
    assumeTrue(withUndelete);
    refreshState(false, false, false);
    state.properties.put("store.index.max.number.of.inmem.elements", Integer.toString(5));
    state.initIndex(null);

    // Insert P, D in the first log segment
    IndexEntry p1 = state.addPutEntries(1, PUT_RECORD_SIZE, Utils.Infinite_Time).get(0);
    state.addDeleteEntry((MockId) p1.getKey());

    writeDataToMeetRequiredSegmentCount(1, null);
    // Now we are at second segment
    // Randomly insert a new put
    state.addPutEntries(1, PUT_RECORD_SIZE, Utils.Infinite_Time);
    state.addUndeleteEntry((MockId) p1.getKey());
    state.addDeleteEntry((MockId) p1.getKey());

    writeDataToMeetRequiredSegmentCount(3, null);

    List<LogSegmentName> segmentsUnderCompaction = getLogSegments(0, 1);
    long deleteReferenceTimeMs = state.time.milliseconds() + 1000;
    compactAndVerify(segmentsUnderCompaction, deleteReferenceTimeMs, true);

    state.reloadIndex(true, false);
    List<IndexValue> values = state.index.findAllIndexValuesForKey(p1.getKey(), null);
    assertNotNull(values);
    assertEquals(2, values.size());
    assertTrue(values.get(0).isDelete());
    assertEquals((short) 1, values.get(0).getLifeVersion());
    assertTrue(values.get(1).isUndelete());
    assertEquals((short) 1, values.get(1).getLifeVersion());
  }
Test when log has P, D, U, D, but P and first D is in a separate segment under compaction.
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/BlobStoreCompactorTest.java