@Test
  public void testExcludeAndDesignated() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    // create designated file
    File designatedFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "designated_file");
    HRegionServer designatedServer = cluster.getRegionServer(0);
    try (FileWriter fos = new FileWriter(designatedFile)) {
      String designatedHostname = designatedServer.getServerName().getHostname();
      int designatedServerPort = designatedServer.getServerName().getPort();
      String excludeServerName = designatedHostname + ":" + designatedServerPort;
      fos.write(excludeServerName);
    }
    int regionsInDesignatedServer = designatedServer.getNumberOfOnlineRegions();
    // create exclude file
    File excludeFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "exclude_file");
    HRegionServer excludeServer = cluster.getRegionServer(1);
    try (FileWriter fos = new FileWriter(excludeFile)) {
      String excludeHostname = excludeServer.getServerName().getHostname();
      int excludeServerPort = excludeServer.getServerName().getPort();
      String excludeServerName = excludeHostname + ":" + excludeServerPort;
      fos.write(excludeServerName);
    }
    int regionsInExcludeServer = excludeServer.getNumberOfOnlineRegions();

    HRegionServer targetRegionServer = cluster.getRegionServer(2);
    String rsName = targetRegionServer.getServerName().getHostname();
    int port = targetRegionServer.getServerName().getPort();
    String rs = rsName + ":" + port;
    int regionsInTargetRegionServer = targetRegionServer.getNumberOfOnlineRegions();

    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs, TEST_UTIL.getConfiguration())
      .designatedFile(designatedFile.getCanonicalPath())
      .excludeFile(excludeFile.getCanonicalPath());
    try (RegionMover rm = rmBuilder.build()) {
      LOG.debug("Unloading {}", rs);
      rm.unload();
      assertEquals(0, targetRegionServer.getNumberOfOnlineRegions());
      assertEquals(regionsInDesignatedServer + regionsInTargetRegionServer,
        designatedServer.getNumberOfOnlineRegions());
      LOG.debug("DesignatedServer Before:{} After:{}", regionsInDesignatedServer,
        designatedServer.getNumberOfOnlineRegions());
      assertEquals(regionsInExcludeServer, excludeServer.getNumberOfOnlineRegions());
      LOG.debug("ExcludeServer Before:{} After:{}", regionsInExcludeServer,
        excludeServer.getNumberOfOnlineRegions());
    }
  }
To test that we successfully exclude a server from the unloading process We test for the number
of regions on Excluded server and also test that regions are unloaded successfully
hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionMover1.java