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.Test;
025
026public class RestoreSnapshotFromClientCloneTestBase extends RestoreSnapshotFromClientTestBase {
027
028  @Test
029  public void testCloneSnapshotOfCloned() throws IOException, InterruptedException {
030    TableName clonedTableName =
031      TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime());
032    admin.cloneSnapshot(snapshotName0, clonedTableName);
033    verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
034    SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
035    admin.disableTable(clonedTableName);
036    admin.snapshot(snapshotName2, clonedTableName);
037    TEST_UTIL.deleteTable(clonedTableName);
038    waitCleanerRun();
039
040    admin.cloneSnapshot(snapshotName2, clonedTableName);
041    verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
042    SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
043    TEST_UTIL.deleteTable(clonedTableName);
044  }
045
046  @Test
047  public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException {
048    TEST_UTIL.deleteTable(tableName);
049    waitCleanerRun();
050
051    admin.cloneSnapshot(snapshotName0, tableName);
052    verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
053    SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
054    waitCleanerRun();
055
056    admin.disableTable(tableName);
057    admin.restoreSnapshot(snapshotName0);
058    admin.enableTable(tableName);
059    verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
060    SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
061  }
062
063  private void waitCleanerRun() throws InterruptedException {
064    TEST_UTIL.getMiniHBaseCluster().getMaster().getHFileCleaner().choreForTesting();
065  }
066}