@Test
  public void testCompactionSwitchStates() throws Exception {
    // Create a table with regions
    byte[] family = Bytes.toBytes("family");
    byte[][] families =
      { family, Bytes.add(family, Bytes.toBytes("2")), Bytes.add(family, Bytes.toBytes("3")) };
    createTableWithDefaultConf(tableName, null, families);
    loadData(tableName, families, 3000, 8);
    List<Region> regions = new ArrayList<>();
    TEST_UTIL.getHBaseCluster().getLiveRegionServerThreads()
      .forEach(rsThread -> regions.addAll(rsThread.getRegionServer().getRegions(tableName)));
    CompletableFuture<Map<ServerName, Boolean>> listCompletableFuture =
      admin.compactionSwitch(true, new ArrayList<>());
    Map<ServerName, Boolean> pairs = listCompletableFuture.get();
    for (Map.Entry<ServerName, Boolean> p : pairs.entrySet()) {
      assertEquals("Default compaction state, expected=enabled actual=disabled", true,
        p.getValue());
    }
    CompletableFuture<Map<ServerName, Boolean>> listCompletableFuture1 =
      admin.compactionSwitch(false, new ArrayList<>());
    Map<ServerName, Boolean> pairs1 = listCompletableFuture1.get();
    for (Map.Entry<ServerName, Boolean> p : pairs1.entrySet()) {
      assertEquals("Last compaction state, expected=enabled actual=disabled", true, p.getValue());
    }
    CompletableFuture<Map<ServerName, Boolean>> listCompletableFuture2 =
      admin.compactionSwitch(true, new ArrayList<>());
    Map<ServerName, Boolean> pairs2 = listCompletableFuture2.get();
    for (Map.Entry<ServerName, Boolean> p : pairs2.entrySet()) {
      assertEquals("Last compaction state, expected=disabled actual=enabled", false, p.getValue());
    }
    ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
    List<String> serverNameList = new ArrayList<String>();
    serverNameList.add(serverName.getServerName());
    CompletableFuture<Map<ServerName, Boolean>> listCompletableFuture3 =
      admin.compactionSwitch(false, serverNameList);
    Map<ServerName, Boolean> pairs3 = listCompletableFuture3.get();
    assertEquals(pairs3.entrySet().size(), 1);
    for (Map.Entry<ServerName, Boolean> p : pairs3.entrySet()) {
      assertEquals("Last compaction state, expected=enabled actual=disabled", true, p.getValue());
    }
    CompletableFuture<Map<ServerName, Boolean>> listCompletableFuture4 =
      admin.compactionSwitch(true, serverNameList);
    Map<ServerName, Boolean> pairs4 = listCompletableFuture4.get();
    assertEquals(pairs4.entrySet().size(), 1);
    for (Map.Entry<ServerName, Boolean> p : pairs4.entrySet()) {
      assertEquals("Last compaction state, expected=disabled actual=enabled", false, p.getValue());
    }
  }
Class to test asynchronous region admin operations.
@see TestAsyncRegionAdminApi2 This test and it used to be joined it was taking longer than our
     ten minute timeout so they were split.
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java