@Test
  public void testMergeDetectsModifyTableProcedure() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

    List<RegionInfo> regions = createTable(tableName);

    RegionServerHostingReplicaSlowOpenCoprocessor.slowDownReplicaOpen = true;
    TableDescriptor td = TableDescriptorBuilder.newBuilder(admin.getDescriptor(tableName))
      .setRegionReplication(2).build();
    long modifyProcId =
      procExec.submitProcedure(new ModifyTableProcedure(procExec.getEnvironment(), td));

    // Merge regions of the table, the MergeTableRegionsProcedure will fail because there is a
    // ModifyTableProcedure in progress
    MergeTableRegionsProcedure mergeProcedure = new MergeTableRegionsProcedure(
      procExec.getEnvironment(), regions.toArray(new RegionInfo[0]), false);
    long mergeProcId = procExec.submitProcedure(mergeProcedure);
    ProcedureTestingUtility.waitProcedure(procExec, mergeProcId);
    ProcedureTestingUtility.assertProcFailed(procExec, mergeProcId);

    RegionServerHostingReplicaSlowOpenCoprocessor.slowDownReplicaOpen = false;
    ProcedureTestingUtility.waitProcedure(procExec, modifyProcId);
    ProcedureTestingUtility.assertProcNotFailed(procExec, modifyProcId);
  }
This tests two concurrent region merges
hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestMergeTableRegionsProcedure.java