@Test
  public void testRegionObserverCompactionTimeStacking() throws Exception {
    // setup a mini cluster so we can do a real compaction on a region
    Configuration conf = UTIL.getConfiguration();
    conf.setClass(HConstants.REGION_IMPL, CompactionCompletionNotifyingRegion.class, HRegion.class);
    conf.setInt("hbase.hstore.compaction.min", 2);
    UTIL.startMiniCluster();
    byte[] ROW = Bytes.toBytes("testRow");
    byte[] A = Bytes.toBytes("A");
    TableDescriptor tableDescriptor =
      TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of(A))
        .setCoprocessor(CoprocessorDescriptorBuilder
          .newBuilder(EmptyRegionObsever.class.getName()).setJarPath(null)
          .setPriority(Coprocessor.PRIORITY_USER).setProperties(Collections.emptyMap()).build())
        .setCoprocessor(CoprocessorDescriptorBuilder
          .newBuilder(NoDataFromCompaction.class.getName()).setJarPath(null)
          .setPriority(Coprocessor.PRIORITY_HIGHEST).setProperties(Collections.emptyMap()).build())
        .build();

    Admin admin = UTIL.getAdmin();
    admin.createTable(tableDescriptor);

    Table table = UTIL.getConnection().getTable(tableDescriptor.getTableName());

    // put a row and flush it to disk
    Put put = new Put(ROW);
    put.addColumn(A, A, A);
    table.put(put);

    HRegionServer rs = UTIL.getRSForFirstRegionInTable(tableDescriptor.getTableName());
    List<HRegion> regions = rs.getRegions(tableDescriptor.getTableName());
    assertEquals("More than 1 region serving test table with 1 row", 1, regions.size());
    Region region = regions.get(0);
    admin.flushRegion(region.getRegionInfo().getRegionName());
    CountDownLatch latch =
      ((CompactionCompletionNotifyingRegion) region).getCompactionStateChangeLatch();

    // put another row and flush that too
    put = new Put(Bytes.toBytes("anotherrow"));
    put.addColumn(A, A, A);
    table.put(put);
    admin.flushRegion(region.getRegionInfo().getRegionName());

    // run a compaction, which normally would should get rid of the data
    // wait for the compaction checker to complete
    latch.await();
    // check both rows to ensure that they aren't there
    Get get = new Get(ROW);
    Result r = table.get(get);
    assertNull(
      "Got an unexpected number of rows - "
        + "no data should be returned with the NoDataFromScan coprocessor. Found: " + r,
      r.listCells());

    get = new Get(Bytes.toBytes("anotherrow"));
    r = table.get(get);
    assertNull(
      "Got an unexpected number of rows - "
        + "no data should be returned with the NoDataFromScan coprocessor Found: " + r,
      r.listCells());

    table.close();
    UTIL.shutdownMiniCluster();
  }
Unfortunately, the easiest way to test this is to spin up a mini-cluster since we want to do
the usual compaction mechanism on the region, rather than going through the backdoor to the
region
hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java