@Test
  public void testDisableAndMove() throws Exception {
    Admin admin = TEST_UTIL.getAdmin();

    // Create a table with more than one region
    Table t = TEST_UTIL.createMultiRegionTable(tableName, Bytes.toBytes(F1), 10);
    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);

    // Write an update to each region
    for (RegionInfo regionInfo : admin.getRegions(tableName)) {
      byte[] startKey = regionInfo.getStartKey();
      // The startKey of the first region is "empty", which would throw an error if we try to
      // Put that.
      byte[] rowKey = org.apache.hbase.thirdparty.com.google.common.primitives.Bytes
        .concat(startKey, Bytes.toBytes("1"));
      Put p = new Put(rowKey);
      p.addColumn(Bytes.toBytes(F1), Bytes.toBytes("q1"), Bytes.toBytes("value"));
      t.put(p);
    }

    // Get a Region which is on the first RS
    HRegionServer rs1 = TEST_UTIL.getRSForFirstRegionInTable(tableName);
    HRegionServer rs2 = TEST_UTIL.getOtherRegionServer(rs1);
    List<RegionInfo> regionsOnRS1ForTable = admin.getRegions(rs1.getServerName()).stream()
      .filter((regionInfo) -> regionInfo.getTable().equals(tableName)).collect(Collectors.toList());
    assertTrue("Expected to find at least one region for " + tableName + " on "
      + rs1.getServerName() + ", but found none", !regionsOnRS1ForTable.isEmpty());
    final RegionInfo regionToMove = regionsOnRS1ForTable.get(0);

    // Offline the region and then try to move it. Should fail.
    admin.unassign(regionToMove.getRegionName(), true);
    try {
      admin.move(regionToMove.getEncodedNameAsBytes(), rs2.getServerName());
      fail();
    } catch (DoNotRetryRegionException e) {
      // We got expected exception
    }
    // Reassign for next stage of test.
    admin.assign(regionToMove.getRegionName());

    // Disable the table
    admin.disableTable(tableName);

    try {
      // Move the region to the other RS -- should fail
      admin.move(regionToMove.getEncodedNameAsBytes(), rs2.getServerName());
      fail();
    } catch (DoNotRetryIOException e) {
      // We got expected exception
    }
  }
Test move fails when table disabled
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java