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