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.NamespaceDescriptor;
022import org.apache.hadoop.hbase.TableName;
023import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
024import org.junit.Test;
025
026public class CloneSnapshotFromClientNormalTestBase extends CloneSnapshotFromClientTestBase {
027
028  @Test
029  public void testCloneSnapshot() throws IOException, InterruptedException {
030    TableName clonedTableName =
031      TableName.valueOf(getValidMethodName() + "-" + System.currentTimeMillis());
032    testCloneSnapshot(clonedTableName, snapshotName0, snapshot0Rows);
033    testCloneSnapshot(clonedTableName, snapshotName1, snapshot1Rows);
034    testCloneSnapshot(clonedTableName, emptySnapshot, 0);
035  }
036
037  private void testCloneSnapshot(TableName tableName, String snapshotName, int snapshotRows)
038      throws IOException, InterruptedException {
039    // create a new table from snapshot
040    admin.cloneSnapshot(snapshotName, tableName);
041    verifyRowCount(TEST_UTIL, tableName, snapshotRows);
042
043    verifyReplicasCameOnline(tableName);
044    TEST_UTIL.deleteTable(tableName);
045  }
046
047  private void verifyReplicasCameOnline(TableName tableName) throws IOException {
048    SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
049  }
050
051  @Test
052  public void testCloneSnapshotCrossNamespace() throws IOException, InterruptedException {
053    String nsName = getValidMethodName() + "_ns_" + System.currentTimeMillis();
054    admin.createNamespace(NamespaceDescriptor.create(nsName).build());
055    final TableName clonedTableName =
056      TableName.valueOf(nsName, getValidMethodName() + "-" + System.currentTimeMillis());
057    testCloneSnapshot(clonedTableName, snapshotName0, snapshot0Rows);
058    testCloneSnapshot(clonedTableName, snapshotName1, snapshot1Rows);
059    testCloneSnapshot(clonedTableName, emptySnapshot, 0);
060  }
061}