diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java index 3eb304d..09b5704 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java @@ -23,7 +23,13 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.util.HashSet; +import java.util.List; import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseClassTestRule; @@ -294,6 +300,29 @@ public class TestRestoreSnapshotFromClient { } } + @Test + public void testSnapshotAfterSplittingRegions() throws IOException, InterruptedException { + try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { + snapshot1Rows = countRows(table); + } + + List regionInfos = admin.getRegions(tableName).stream() + .filter(regionInfo -> RegionReplicaUtil.isDefaultReplica(regionInfo.getReplicaId())) + .collect(Collectors.toList()); + + // Split a region + splitRegion(regionInfos.get(0)); + + // Take a online snapshot + admin.snapshot(snapshotName1, tableName); + + // Clone the snapshot to another table + TableName clonedTableName = TableName.valueOf(name.getMethodName() + "-" + System.currentTimeMillis()); + admin.cloneSnapshot(snapshotName1, clonedTableName); + + verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows); + } + // ========================================================================== // Helpers // ========================================================================== @@ -321,4 +350,15 @@ public class TestRestoreSnapshotFromClient { protected int countRows(final Table table, final byte[]... families) throws IOException { return TEST_UTIL.countRows(table, families); } + + protected void splitRegion(final RegionInfo regionInfo) throws IOException, + InterruptedException { + byte[][] splitPoints = Bytes.split(regionInfo.getStartKey(), regionInfo.getEndKey(), 1); + try { + admin.splitRegionAsync(regionInfo.getEncodedNameAsBytes(), splitPoints[1]).get(10, + TimeUnit.SECONDS); + } catch (ExecutionException | TimeoutException e) { + throw new IOException(e); + } + } }