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