@Test
  public void testRIT() throws Exception {
    RegionStateNode rsn = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager()
      .getRegionStates().getTableRegionStateNodes(TD.getTableName()).stream()
      .filter(rn -> rn.getRegionInfo().getReplicaId() > 1).findAny().get();
    // fake a TRSP to block the CloseExcessRegionReplicasProcedure
    TransitRegionStateProcedure trsp = new TransitRegionStateProcedure();
    rsn.setProcedure(trsp);
    TableDescriptor newTd = TableDescriptorBuilder.newBuilder(TD).setRegionReplication(2).build();
    CompletableFuture<Void> future = UTIL.getAsyncConnection().getAdmin().modifyTable(newTd);
    ProcedureExecutor<MasterProcedureEnv> procExec =
      UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
    UTIL.waitFor(5000, () -> procExec.getProcedures().stream()
      .anyMatch(p -> p instanceof CloseExcessRegionReplicasProcedure && !p.isFinished()));
    CloseExcessRegionReplicasProcedure proc =
      procExec.getProcedures().stream().filter(p -> p instanceof CloseExcessRegionReplicasProcedure)
        .map(p -> (CloseExcessRegionReplicasProcedure) p).findFirst().get();
    // make sure that the procedure can not finish
    for (int i = 0; i < 5; i++) {
      Thread.sleep(3000);
      assertFalse(proc.isFinished());
    }
    assertTrue(rsn.isInState(RegionState.State.OPEN));
    // unset the procedure, so we could make progress on CloseExcessRegionReplicasProcedure
    rsn.unsetProcedure(trsp);
    UTIL.waitFor(60000, () -> proc.isFinished());

    future.get();

    // the region should be in CLOSED state, and should have been removed from AM
    assertTrue(rsn.isInState(RegionState.State.CLOSED));
    // only 2 replicas now
    assertEquals(2, UTIL.getMiniHBaseCluster().getRegions(TD.getTableName()).size());
  }
A test to make sure that we will wait for RIT to finish while closing excess region replicas. See
HBASE-28582 and related issues for more details.
hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestReduceExcessRegionReplicasBlockedByRIT.java