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.backup;
019
020import static org.junit.Assert.assertTrue;
021
022import java.util.List;
023import org.apache.hadoop.hbase.HBaseClassTestRule;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.hadoop.hbase.backup.util.BackupUtils;
026import org.apache.hadoop.hbase.client.Admin;
027import org.apache.hadoop.hbase.testclassification.LargeTests;
028import org.junit.ClassRule;
029import org.junit.Test;
030import org.junit.experimental.categories.Category;
031import org.slf4j.Logger;
032import org.slf4j.LoggerFactory;
033
034@Category(LargeTests.class)
035public class TestRestoreBoundaryTests extends TestBackupBase {
036
037  @ClassRule
038  public static final HBaseClassTestRule CLASS_RULE =
039    HBaseClassTestRule.forClass(TestRestoreBoundaryTests.class);
040
041  private static final Logger LOG = LoggerFactory.getLogger(TestRestoreBoundaryTests.class);
042
043  /**
044   * Verify that a single empty table is restored to a new table.
045   * @throws Exception if doing the backup or an operation on the tables fails
046   */
047  @Test
048  public void testFullRestoreSingleEmpty() throws Exception {
049    LOG.info("test full restore on a single table empty table");
050    String backupId = fullTableBackup(toList(table1.getNameAsString()));
051    LOG.info("backup complete");
052    TableName[] tableset = new TableName[] { table1 };
053    TableName[] tablemap = new TableName[] { table1_restore };
054    getBackupAdmin().restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, backupId, false,
055      tableset, tablemap, false));
056    Admin hba = TEST_UTIL.getAdmin();
057    assertTrue(hba.tableExists(table1_restore));
058    TEST_UTIL.deleteTable(table1_restore);
059  }
060
061  /**
062   * Verify that multiple tables are restored to new tables.
063   * @throws Exception if doing the backup or an operation on the tables fails
064   */
065  @Test
066  public void testFullRestoreMultipleEmpty() throws Exception {
067    LOG.info("create full backup image on multiple tables");
068
069    List<TableName> tables = toList(table2.getNameAsString(), table3.getNameAsString());
070    String backupId = fullTableBackup(tables);
071    TableName[] restore_tableset = new TableName[] { table2, table3 };
072    TableName[] tablemap = new TableName[] { table2_restore, table3_restore };
073    getBackupAdmin().restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, backupId, false,
074      restore_tableset, tablemap, false));
075    Admin hba = TEST_UTIL.getAdmin();
076    assertTrue(hba.tableExists(table2_restore));
077    assertTrue(hba.tableExists(table3_restore));
078    TEST_UTIL.deleteTable(table2_restore);
079    TEST_UTIL.deleteTable(table3_restore);
080    hba.close();
081  }
082}