@Test
  public void testCompactionFailure() throws Exception {
    // setup a compact/split thread on a mock server
    HRegionServer mockServer = Mockito.mock(HRegionServer.class);
    Mockito.when(mockServer.getConfiguration()).thenReturn(r.getBaseConf());
    CompactSplit thread = new CompactSplit(mockServer);
    Mockito.when(mockServer.getCompactSplitThread()).thenReturn(thread);

    // setup a region/store with some files
    HStore store = r.getStore(COLUMN_FAMILY);
    createStoreFile(r);
    for (int i = 0; i < HStore.DEFAULT_BLOCKING_STOREFILE_COUNT - 1; i++) {
      createStoreFile(r);
    }

    HRegion mockRegion = Mockito.spy(r);
    Mockito.when(mockRegion.checkSplit())
      .thenThrow(new RuntimeException("Thrown intentionally by test!"));

    try (MetricsRegionWrapperImpl metricsWrapper = new MetricsRegionWrapperImpl(r)) {

      long preCompletedCount = metricsWrapper.getNumCompactionsCompleted();
      long preFailedCount = metricsWrapper.getNumCompactionsFailed();

      CountDownLatch latch = new CountDownLatch(1);
      Tracker tracker = new Tracker(latch);
      thread.requestCompaction(mockRegion, store, "test custom comapction", PRIORITY_USER, tracker,
        null);
      // wait for the latch to complete.
      latch.await(120, TimeUnit.SECONDS);

      // compaction should have completed and been marked as failed due to error in split request
      long postCompletedCount = metricsWrapper.getNumCompactionsCompleted();
      long postFailedCount = metricsWrapper.getNumCompactionsFailed();

      assertTrue("Completed count should have increased (pre=" + preCompletedCount + ", post="
        + postCompletedCount + ")", postCompletedCount > preCompletedCount);
      assertTrue("Failed count should have increased (pre=" + preFailedCount + ", post="
        + postFailedCount + ")", postFailedCount > preFailedCount);
    }
  }
Create a custom compaction request and be sure that we can track it through the queue, knowing
when the compaction is completed.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java