private void restartHBaseCluster(boolean cleanUpWALs, boolean cleanUpZnodes) throws Exception {
    // flush cache so that everything is on disk
    TEST_UTIL.getMiniHBaseCluster().flushcache(TableName.META_TABLE_NAME);
    TEST_UTIL.getMiniHBaseCluster().flushcache();

    List<ServerName> oldServers =
      TEST_UTIL.getHBaseCluster().getMaster().getServerManager().getOnlineServersList();

    // make sure there is no procedures pending
    TEST_UTIL.waitFor(TIMEOUT_MS, () -> TEST_UTIL.getHBaseCluster().getMaster().getProcedures()
      .stream().filter(p -> p.isFinished()).findAny().isPresent());

    // shutdown and delete data if needed
    Path walRootDirPath = TEST_UTIL.getMiniHBaseCluster().getMaster().getWALRootDir();
    Path rootDirPath = CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration());
    TEST_UTIL.shutdownMiniHBaseCluster();

    if (cleanUpWALs) {
      TEST_UTIL.getDFSCluster().getFileSystem().delete(walRootDirPath, true);
    }

    if (cleanUpZnodes) {
      // delete all zk data
      // we cannot keep ZK data because it will hold the meta region states as open and
      // didn't submit a InitMetaProcedure
      ZKUtil.deleteChildrenRecursively(TEST_UTIL.getZooKeeperWatcher(),
        TEST_UTIL.getZooKeeperWatcher().getZNodePaths().baseZNode);
      TEST_UTIL.shutdownMiniZKCluster();
      TEST_UTIL.startMiniZKCluster();
    }

    TEST_UTIL.restartHBaseCluster(NUM_RS);
    TEST_UTIL.waitFor(TIMEOUT_MS, new Waiter.Predicate<Exception>() {
      @Override
      public boolean evaluate() throws Exception {
        return TEST_UTIL.getMiniHBaseCluster().getNumLiveRegionServers() == NUM_RS;
      }
    });

    // make sure we have a new set of region servers with different hostnames and ports
    List<ServerName> newServers =
      TEST_UTIL.getHBaseCluster().getMaster().getServerManager().getOnlineServersList();
    assertFalse(newServers.stream().filter((newServer) -> oldServers.contains(newServer)).findAny()
      .isPresent());
  }
Test reuse storefiles within data directory when cluster failover with a set of new region
servers with different hostnames with or without WALs and Zookeeper ZNodes, the master and
cluster should fail respectively if there is any situation considered as not supported.
hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRecreateCluster.java