View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.backup;
20  
21  import static org.junit.Assert.assertTrue;
22  
23  import java.util.List;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.hadoop.hbase.TableName;
28  import org.apache.hadoop.hbase.client.HBaseAdmin;
29  import org.apache.hadoop.hbase.testclassification.LargeTests;
30  import org.junit.Test;
31  import org.junit.experimental.categories.Category;
32  
33  @Category(LargeTests.class)
34  public class TestRestoreBoundaryTests extends TestBackupBase {
35  
36    private static final Log LOG = LogFactory.getLog(TestRestoreBoundaryTests.class);
37  
38    /**
39     * Verify that a single empty table is restored to a new table
40     * @throws Exception
41     */
42    @Test
43    public void testFullRestoreSingleEmpty() throws Exception {
44      LOG.info("test full restore on a single table empty table");
45      String backupId = fullTableBackup(toList(table1.getNameAsString()));
46      LOG.info("backup complete");
47      TableName[] tableset = new TableName[] { table1 };
48      TableName[] tablemap = new TableName[] { table1_restore };
49      getBackupAdmin().restore(createRestoreRequest(BACKUP_ROOT_DIR, backupId, false, tableset, tablemap,
50        false));
51      HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
52      assertTrue(hba.tableExists(table1_restore));
53      TEST_UTIL.deleteTable(table1_restore);
54    }
55  
56    /**
57     * Verify that multiple tables are restored to new tables.
58     * @throws Exception
59     */
60    @Test
61    public void testFullRestoreMultipleEmpty() throws Exception {
62      LOG.info("create full backup image on multiple tables");
63  
64      List<TableName> tables = toList(table2.getNameAsString(), table3.getNameAsString());
65      String backupId = fullTableBackup(tables);
66      TableName[] restore_tableset = new TableName[] { table2, table3};
67      TableName[] tablemap = new TableName[] { table2_restore, table3_restore };
68      getBackupAdmin().restore(createRestoreRequest(BACKUP_ROOT_DIR, backupId, false, restore_tableset,
69        tablemap,
70        false));
71      HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
72      assertTrue(hba.tableExists(table2_restore));
73      assertTrue(hba.tableExists(table3_restore));
74      TEST_UTIL.deleteTable(table2_restore);
75      TEST_UTIL.deleteTable(table3_restore);
76    }
77  }