@Test
  public void testDataCorrectnessReplayingRecoveredEdits() throws Exception {
    final int NUM_RS = 3;
    Admin hbaseAdmin = null;
    TEST_UTIL.startMiniCluster(NUM_RS);

    try {
      final TableName tableName = TableName.valueOf(name.getMethodName());
      final byte[] FAMILY = Bytes.toBytes("family");
      SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
      HMaster master = cluster.getMaster();

      // Create table
      TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName)
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
      hbaseAdmin = master.getConnection().getAdmin();
      hbaseAdmin.createTable(tableDescriptor);

      assertTrue(hbaseAdmin.isTableAvailable(tableName));

      // Put data: r1->v1
      LOG.info("Loading r1 to v1 into " + tableName);
      Table table = TEST_UTIL.getConnection().getTable(tableName);
      putDataAndVerify(table, "r1", FAMILY, "v1", 1);

      TEST_UTIL.waitUntilAllRegionsAssigned(table.getName());
      // Move region to target server

      RegionInfo regionInfo;
      try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
        regionInfo = locator.getRegionLocation(Bytes.toBytes("r1")).getRegion();
      }

      int originServerNum = cluster.getServerWith(regionInfo.getRegionName());
      HRegionServer originServer = cluster.getRegionServer(originServerNum);
      int targetServerNum = (originServerNum + 1) % NUM_RS;
      HRegionServer targetServer = cluster.getRegionServer(targetServerNum);
      assertFalse(originServer.equals(targetServer));

      TEST_UTIL.waitUntilAllRegionsAssigned(table.getName());
      LOG.info("Moving " + regionInfo.getEncodedName() + " to " + targetServer.getServerName());
      hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), targetServer.getServerName());
      do {
        Thread.sleep(1);
      } while (cluster.getServerWith(regionInfo.getRegionName()) == originServerNum);

      // Put data: r2->v2
      LOG.info("Loading r2 to v2 into " + tableName);
      putDataAndVerify(table, "r2", FAMILY, "v2", 2);

      TEST_UTIL.waitUntilAllRegionsAssigned(table.getName());
      // Move region to origin server
      LOG.info("Moving " + regionInfo.getEncodedName() + " to " + originServer.getServerName());
      hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), originServer.getServerName());
      do {
        Thread.sleep(1);
      } while (cluster.getServerWith(regionInfo.getRegionName()) == targetServerNum);

      // Put data: r3->v3
      LOG.info("Loading r3 to v3 into " + tableName);
      putDataAndVerify(table, "r3", FAMILY, "v3", 3);

      // Kill target server
      LOG.info("Killing target server " + targetServer.getServerName());
      targetServer.kill();
      cluster.getRegionServerThreads().get(targetServerNum).join();
      // Wait until finish processing of shutdown
      while (master.getServerManager().areDeadServersInProgress()) {
        Thread.sleep(5);
      }
      // Kill origin server
      LOG.info("Killing origin server " + targetServer.getServerName());
      originServer.kill();
      cluster.getRegionServerThreads().get(originServerNum).join();

      // Put data: r4->v4
      LOG.info("Loading r4 to v4 into " + tableName);
      putDataAndVerify(table, "r4", FAMILY, "v4", 4);

    } finally {
      if (hbaseAdmin != null) hbaseAdmin.close();
      TEST_UTIL.shutdownMiniCluster();
    }
  }
Tests that need to spin up a cluster testing an {@link HRegion}. Use {@link TestHRegion} if you
don't need a cluster, if you can test w/ a standalone {@link HRegion}.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionOnCluster.java