@Test
  public void testRetentionAfterFailedCleanup() throws Exception {
    conf.setBoolVar(HIVE_COMPACTOR_DELAYED_CLEANUP_ENABLED, false);

    Table t = newTable("default", "retry_test", false);

    addBaseFile(t, null, 20L, 20);
    addDeltaFile(t, null, 21L, 22L, 2);
    addDeltaFile(t, null, 23L, 24L, 2);
    burnThroughTransactions("default", "retry_test", 25);

    CompactionRequest rqst = new CompactionRequest("default", "retry_test", CompactionType.MAJOR);
    long compactTxn = compactInTxn(rqst);
    addBaseFile(t, null, 25L, 25, compactTxn);

    //Prevent cleaner from marking the compaction as cleaned
    TxnStore mockedHandler = spy(txnHandler);
    MetadataCache metadataCache = new MetadataCache(true);
    FSRemover fsRemover = new FSRemover(conf, ReplChangeManager.getInstance(conf), metadataCache);
    List<TaskHandler> taskHandlers = TaskHandlerFactory.getInstance()
            .getHandlers(conf, mockedHandler, metadataCache, false, fsRemover);
    doThrow(new RuntimeException()).when(mockedHandler).markCleaned(nullable(CompactionInfo.class));

    //Do a run to fail the clean and set the retention time
    Cleaner cleaner = new Cleaner();
    cleaner.setConf(conf);
    cleaner.init(new AtomicBoolean(true));
    cleaner.setCleanupHandlers(taskHandlers);
    ReflectionUtil.setInAllFields(cleaner, "txnHandler", mockedHandler);

    cleaner.run();

    AtomicReference<List<CompactionInfo>> reference = new AtomicReference<>();
    doAnswer(invocation -> {
      Object o = invocation.callRealMethod();
      reference.set((List<CompactionInfo>) o);
      return o;
    }).when(mockedHandler).findReadyToClean(anyLong(), anyLong());

    //Do a final run and check if the compaction is not picked up again
    cleaner = new Cleaner();
    cleaner.setConf(conf);
    cleaner.init(new AtomicBoolean(true));
    cleaner.setCleanupHandlers(taskHandlers);
    ReflectionUtil.setInAllFields(cleaner, "txnHandler", mockedHandler);

    cleaner.run();

    Assert.assertEquals(0, reference.get().size());
  }
Tests for the compactor Cleaner thread
ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestCleaner.java