@Test
  public void testCompactionWithCorruptResult() throws Exception {
    int nfiles = 10;
    for (int i = 0; i < nfiles; i++) {
      createStoreFile(r);
    }
    HStore store = r.getStore(COLUMN_FAMILY);

    Collection<HStoreFile> storeFiles = store.getStorefiles();
    DefaultCompactor tool = (DefaultCompactor) store.storeEngine.getCompactor();
    CompactionRequestImpl request = new CompactionRequestImpl(storeFiles);
    tool.compact(request, NoLimitThroughputController.INSTANCE, null);

    // Now lets corrupt the compacted file.
    FileSystem fs = store.getFileSystem();
    // default compaction policy created one and only one new compacted file
    Path tmpPath = store.getRegionFileSystem().createTempName();
    try (FSDataOutputStream stream = fs.create(tmpPath, null, true, 512, (short) 3, 1024L, null)) {
      stream.writeChars("CORRUPT FILE!!!!");
    }

    // The complete compaction should fail and the corrupt file should remain
    // in the 'tmp' directory;
    assertThrows(IOException.class, () -> store.doCompaction(null, null, null,
      EnvironmentEdgeManager.currentTime(), Collections.singletonList(tmpPath)));
    assertTrue(fs.exists(tmpPath));
  }
Verify that you can stop a long-running compaction (used during RS shutdown)
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java