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