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 static org.junit.Assert.assertFalse; 021import static org.junit.Assert.fail; 022 023import java.io.IOException; 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException; 026import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; 027import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; 028import org.junit.Test; 029 030public class RestoreSnapshotFromClientSimpleTestBase extends RestoreSnapshotFromClientTestBase { 031 032 @Test 033 public void testRestoreSnapshot() throws IOException { 034 verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); 035 admin.disableTable(tableName); 036 admin.snapshot(snapshotName1, tableName); 037 // Restore from snapshot-0 038 admin.restoreSnapshot(snapshotName0); 039 admin.enableTable(tableName); 040 verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); 041 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); 042 043 // Restore from emptySnapshot 044 admin.disableTable(tableName); 045 admin.restoreSnapshot(emptySnapshot); 046 admin.enableTable(tableName); 047 verifyRowCount(TEST_UTIL, tableName, 0); 048 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); 049 050 // Restore from snapshot-1 051 admin.disableTable(tableName); 052 admin.restoreSnapshot(snapshotName1); 053 admin.enableTable(tableName); 054 verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); 055 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); 056 057 // Restore from snapshot-1 058 TEST_UTIL.deleteTable(tableName); 059 admin.restoreSnapshot(snapshotName1); 060 verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); 061 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); 062 } 063 064 @Test 065 public void testCorruptedSnapshot() throws IOException, InterruptedException { 066 SnapshotTestingUtils.corruptSnapshot(TEST_UTIL, snapshotName0); 067 TableName cloneName = 068 TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime()); 069 try { 070 admin.cloneSnapshot(snapshotName0, cloneName); 071 fail("Expected CorruptedSnapshotException, got succeeded cloneSnapshot()"); 072 } catch (CorruptedSnapshotException e) { 073 // Got the expected corruption exception. 074 // check for no references of the cloned table. 075 assertFalse(admin.tableExists(cloneName)); 076 } catch (Exception e) { 077 fail("Expected CorruptedSnapshotException got: " + e); 078 } 079 } 080}