private void tryMergeAndEnsureItIsSuccess(final TableName tableName) throws Exception {
    // assert we have at least 2 regions in the table
    List<RegionInfo> regions = admin.getRegions(tableName);
    int originalCount = regions.size();
    assertTrue(originalCount >= 2);

    byte[] nameOfRegionA = regions.get(0).getEncodedNameAsBytes();
    byte[] nameOfRegionB = regions.get(1).getEncodedNameAsBytes();

    // merge the table regions and wait until region count decreases
    admin.mergeRegionsAsync(new byte[][] { nameOfRegionA, nameOfRegionB }, true);
    TEST_UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {

      @Override
      public boolean evaluate() throws Exception {
        return admin.getRegions(tableName).size() < originalCount;
      }

      @Override
      public String explainFailure() throws Exception {
        return "Merge has not finished yet";
      }
    });
  }
Method to enable merge for the passed table and validate this modification.
@param tableName name of the table
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSplitOrMergeAtTableLevel.java