@Test
  public void testTruncateReplicaRegionNotAllowed() throws Exception {
    // Arrange - Create table, insert data, identify region to truncate.
    final byte[][] splitKeys =
      new byte[][] { Bytes.toBytes("30"), Bytes.toBytes("60"), Bytes.toBytes("90") };
    String family1 = "f1";
    String family2 = "f2";

    final byte[][] bFamilies = new byte[][] { Bytes.toBytes(family1), Bytes.toBytes(family2) };
    createTableWithDefaultConf(tableName, 2, splitKeys, bFamilies);

    AsyncTable<AdvancedScanResultConsumer> metaTable = ASYNC_CONN.getTable(META_TABLE_NAME);
    List<HRegionLocation> regionLocations =
      ClientMetaTableAccessor.getTableHRegionLocations(metaTable, tableName).get();
    RegionInfo primaryRegion = regionLocations.get(0).getRegion();

    RegionInfo firstReplica = RegionReplicaUtil.getRegionInfoForReplica(primaryRegion, 1);

    // Act - Truncate the first region
    try {
      admin.truncateRegion(firstReplica.getRegionName()).get();
    } catch (Exception e) {
      // Assert
      assertEquals("Expected message is different",
        "Can't truncate replicas directly.Replicas are auto-truncated "
          + "when their primary is truncated.",
        e.getCause().getMessage());
    }
  }
Class to test asynchronous region admin operations.
@see TestAsyncRegionAdminApi This test and it used to be joined it was taking longer than our ten
     minute timeout so they were split.
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi2.java