private void doUndeleteTgtDupTest() throws Exception {
    List<MockId> ids = createLogSegmentWithDuplicateOfUndelete();
    MockId pu = ids.get(0);
    MockId pd = ids.get(1);
    MockId pt = ids.get(2);

    List<LogSegmentName> segmentsUnderCompaction = getLogSegments(1, 1);
    DiskIOScheduler diskIOScheduler;
    if (throwExceptionInsteadOfClose) {
      // pu + pd + pt should span two segment, give it another one for margin.
      diskIOScheduler = new InterruptionInducingDiskIOScheduler(3, Integer.MAX_VALUE);
    } else {
      // For pu, it's 1 PUT + 1 TTL_UPDATE + 1 UNDELETE
      // For pd, it's 1 DELETE
      // For pt, it's 1 PUT + 1 TTL_UPDATE
      long totalBytes = 2 * PUT_RECORD_SIZE + 2 * TTL_UPDATE_RECORD_SIZE + UNDELETE_RECORD_SIZE + DELETE_RECORD_SIZE;
      totalBytes += 2 * PUT_RECORD_SIZE; // Give another put for margin.
      diskIOScheduler = new InterruptionInducingDiskIOScheduler(Integer.MAX_VALUE, totalBytes);
    }
    Log log = new InterruptionInducingLog(Integer.MAX_VALUE, 1);
    compactWithRecoveryAndVerify(state.log, diskIOScheduler, state.index, segmentsUnderCompaction,
        state.time.milliseconds(), true, true);

    List<IndexValue> values = state.index.findAllIndexValuesForKey(pu, null);
    assertNotNull(values);
    assertEquals(3, values.size());
    assertTrue(values.get(0).isUndelete());
    assertEquals(1, values.get(0).getLifeVersion());
    assertTrue(values.get(1).isTtlUpdate());
    assertTrue(values.get(2).isPut());
    values = state.index.findAllIndexValuesForKey(pd, null);
    assertNotNull(values);
    assertEquals(1, values.size());
    assertTrue(values.get(0).isDelete());
    values = state.index.findAllIndexValuesForKey(pt, null);
    assertNotNull(values);
    assertEquals(2, values.size());
    assertTrue(values.get(0).isTtlUpdate());
    assertTrue(values.get(1).isPut());
  }
Tests the case where close/crash creates a situation where duplicates, includeing undeletes, will be detected during
the search for copy candidates in the tgtIndex
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/BlobStoreCompactorTest.java