@Test
  public void testMergeWithReplicas() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    try {
      // Create table and load data.
      Table table = createTableAndLoadData(MASTER, tableName, 5, 2);
      List<Pair<RegionInfo, ServerName>> initialRegionToServers =
        MetaTableAccessor.getTableRegionsAndLocations(TEST_UTIL.getConnection(), tableName);
      // Merge 1st and 2nd region
      PairOfSameType<RegionInfo> mergedRegions =
        mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 2, 5 * 2 - 2);
      List<Pair<RegionInfo, ServerName>> currentRegionToServers =
        MetaTableAccessor.getTableRegionsAndLocations(TEST_UTIL.getConnection(), tableName);
      List<RegionInfo> initialRegions = new ArrayList<>();
      for (Pair<RegionInfo, ServerName> p : initialRegionToServers) {
        initialRegions.add(p.getFirst());
      }
      List<RegionInfo> currentRegions = new ArrayList<>();
      for (Pair<RegionInfo, ServerName> p : currentRegionToServers) {
        currentRegions.add(p.getFirst());
      }
      // this is the first region
      assertTrue(initialRegions.contains(mergedRegions.getFirst()));
      // this is the replica of the first region
      assertTrue(initialRegions
        .contains(RegionReplicaUtil.getRegionInfoForReplica(mergedRegions.getFirst(), 1)));
      // this is the second region
      assertTrue(initialRegions.contains(mergedRegions.getSecond()));
      // this is the replica of the second region
      assertTrue(initialRegions
        .contains(RegionReplicaUtil.getRegionInfoForReplica(mergedRegions.getSecond(), 1)));
      // this is the new region
      assertTrue(!initialRegions.contains(currentRegions.get(0)));
      // replica of the new region
      assertTrue(!initialRegions
        .contains(RegionReplicaUtil.getRegionInfoForReplica(currentRegions.get(0), 1)));
      // replica of the new region
      assertTrue(currentRegions
        .contains(RegionReplicaUtil.getRegionInfoForReplica(currentRegions.get(0), 1)));
      // replica of the merged region
      assertTrue(!currentRegions
        .contains(RegionReplicaUtil.getRegionInfoForReplica(mergedRegions.getFirst(), 1)));
      // replica of the merged region
      assertTrue(!currentRegions
        .contains(RegionReplicaUtil.getRegionInfoForReplica(mergedRegions.getSecond(), 1)));
      table.close();
    } finally {
      TEST_UTIL.deleteTable(tableName);
    }
  }
This test tests 1, merging region not online; 2, merging same two regions; 3, merging unknown
regions. They are in one test case so that we don't have to create many tables, and these tests
are simple.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java