001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import java.io.IOException; 021import org.apache.hadoop.hbase.TableName; 022import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; 023import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; 024import org.junit.jupiter.api.TestTemplate; 025 026public class RestoreSnapshotFromClientCloneTestBase extends RestoreSnapshotFromClientTestBase { 027 028 protected RestoreSnapshotFromClientCloneTestBase(int numReplicas) { 029 super(numReplicas); 030 } 031 032 @TestTemplate 033 public void testCloneSnapshotOfCloned() throws IOException, InterruptedException { 034 TableName clonedTableName = 035 TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime()); 036 admin.cloneSnapshot(snapshotName0, clonedTableName); 037 verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows); 038 SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, numReplicas); 039 admin.disableTable(clonedTableName); 040 admin.snapshot(snapshotName2, clonedTableName); 041 TEST_UTIL.deleteTable(clonedTableName); 042 waitCleanerRun(); 043 044 admin.cloneSnapshot(snapshotName2, clonedTableName); 045 verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows); 046 SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, numReplicas); 047 TEST_UTIL.deleteTable(clonedTableName); 048 } 049 050 @TestTemplate 051 public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException { 052 TEST_UTIL.deleteTable(tableName); 053 waitCleanerRun(); 054 055 admin.cloneSnapshot(snapshotName0, tableName); 056 verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); 057 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas); 058 waitCleanerRun(); 059 060 admin.disableTable(tableName); 061 admin.restoreSnapshot(snapshotName0); 062 admin.enableTable(tableName); 063 verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); 064 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas); 065 } 066 067 private void waitCleanerRun() throws InterruptedException { 068 TEST_UTIL.getMiniHBaseCluster().getMaster().getHFileCleaner().choreForTesting(); 069 } 070}