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