@Test
  public void test() throws Exception {
    LOG.info("====== Test started ======");
    int numThreads = 7;
    AtomicBoolean stop = new AtomicBoolean(false);
    ExecutorService executor = Executors.newFixedThreadPool(numThreads,
      new ThreadFactoryBuilder().setNameFormat("TestAsyncGet-pool-%d").setDaemon(true)
        .setUncaughtExceptionHandler(Threads.LOGGING_EXCEPTION_HANDLER).build());
    List<Future<?>> futures = new ArrayList<>();
    IntStream.range(0, numThreads).forEach(i -> futures.add(executor.submit(() -> {
      run(stop);
      return null;
    })));
    LOG.info("====== Scheduled {} read threads ======", numThreads);
    Collections.shuffle(Arrays.asList(SPLIT_KEYS), ThreadLocalRandom.current());
    Admin admin = TEST_UTIL.getAdmin();
    for (byte[] splitPoint : SPLIT_KEYS) {
      int oldRegionCount = admin.getRegions(TABLE_NAME).size();
      LOG.info("====== Splitting at {} ======, region count before splitting is {}",
        Bytes.toStringBinary(splitPoint), oldRegionCount);
      admin.split(TABLE_NAME, splitPoint);
      TEST_UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {
        @Override
        public boolean evaluate() throws Exception {
          return TEST_UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).size() > oldRegionCount;
        }

        @Override
        public String explainFailure() throws Exception {
          return "Split has not finished yet";
        }
      });
      List<HRegion> regions = TEST_UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME);
      LOG.info("====== Split at {} ======, region count after splitting is {}",
        Bytes.toStringBinary(splitPoint), regions.size());
      for (HRegion region : regions) {
        LOG.info("====== Compact {} ======", region.getRegionInfo());
        region.compact(true);
      }
      for (HRegion region : regions) {
        // Waiting for compaction to complete and references are cleaned up
        LOG.info("====== Waiting for compaction on {} ======", region.getRegionInfo());
        RetryCounter retrier = new RetryCounter(30, 1, TimeUnit.SECONDS);
        for (;;) {
          try {
            if (
              admin.getCompactionStateForRegion(region.getRegionInfo().getRegionName())
                  == CompactionState.NONE
            ) {
              break;
            }
          } catch (IOException e) {
            LOG.warn("Failed to query");
          }
          if (!retrier.shouldRetry()) {
            throw new IOException("Can not finish compaction in time after attempt "
              + retrier.getAttemptTimes() + " times");
          }
          retrier.sleepUntilNextRetry();
        }
        LOG.info("====== Compaction on {} finished, close and archive compacted files ======",
          region.getRegionInfo());
        region.getStores().get(0).closeAndArchiveCompactedFiles();
        LOG.info("====== Close and archive compacted files on {} done ======",
          region.getRegionInfo());
      }
      Thread.sleep(5000);
      LOG.info("====== Balancing cluster ======");
      admin.balance(BalanceRequest.newBuilder().setIgnoreRegionsInTransition(true).build());
      LOG.info("====== Balance cluster done ======");
      Thread.sleep(5000);
      ServerName metaServer = TEST_UTIL.getHBaseCluster().getServerHoldingMeta();
      ServerName newMetaServer = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream()
        .map(t -> t.getRegionServer().getServerName()).filter(s -> !s.equals(metaServer)).findAny()
        .get();
      LOG.info("====== Moving meta from {} to {} ======", metaServer, newMetaServer);
      admin.move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), newMetaServer);
      LOG.info("====== Move meta done ======");
      Thread.sleep(5000);
    }
    List<LogEntry> balancerDecisionRecords =
      admin.getLogEntries(null, "BALANCER_DECISION", ServerType.MASTER, 2, null);
    Assert.assertEquals(balancerDecisionRecords.size(), 2);
    LOG.info("====== Read test finished, shutdown thread pool ======");
    stop.set(true);
    executor.shutdown();
    for (int i = 0; i < numThreads; i++) {
      LOG.info("====== Waiting for {} threads to finish, remaining {} ======", numThreads,
        numThreads - i);
      futures.get(i).get();
    }
    LOG.info("====== Test test finished ======");
  }
Will split the table, and move region randomly when testing.
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableGetMultiThreaded.java