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  package org.apache.hadoop.hbase.backup;
19  
20  import static org.junit.Assert.assertTrue;
21  
22  import java.util.ArrayList;
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.backup.impl.BackupSystemTable;
29  import org.apache.hadoop.hbase.testclassification.LargeTests;
30  import org.apache.hadoop.util.ToolRunner;
31  import org.junit.Test;
32  import org.junit.experimental.categories.Category;
33  
34  import com.google.common.collect.Lists;
35  
36  @Category(LargeTests.class)
37  public class TestFullBackup extends TestBackupBase {
38  
39    private static final Log LOG = LogFactory.getLog(TestFullBackup.class);
40  
41    /**
42     * Verify that full backup is created on a single table with data correctly.
43     * @throws Exception
44     */
45    @Test
46    public void testFullBackupSingle() throws Exception {
47      LOG.info("test full backup on a single table with data");
48      List<TableName> tables = Lists.newArrayList(table1);
49      String backupId = fullTableBackup(tables);
50      assertTrue(checkSucceeded(backupId));
51      LOG.info("backup complete for " + backupId);
52    }
53  
54    /**
55     * Verify that full backup is created on a single table with data correctly.
56     * @throws Exception
57     */
58    @Test
59    public void testFullBackupSingleCommand() throws Exception {
60      LOG.info("test full backup on a single table with data: command-line");
61      try(BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {    
62        int before = table.getBackupHistory().size();
63        String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR,  table1.getNameAsString() }; 
64        // Run backup
65        int ret = ToolRunner.run(conf1, new BackupDriver(), args);
66        assertTrue(ret == 0);
67        ArrayList<BackupInfo> backups = table.getBackupHistory(); 
68        int after = table.getBackupHistory().size();
69        assertTrue(after == before +1);
70        for(BackupInfo data : backups){
71          String backupId = data.getBackupId();
72          assertTrue(checkSucceeded(backupId));
73        }
74      }
75      LOG.info("backup complete");
76    }
77  
78  
79    /**
80     * Verify that full backup is created on multiple tables correctly.
81     * @throws Exception
82     */
83    @Test
84    public void testFullBackupMultiple() throws Exception {
85      LOG.info("create full backup image on multiple tables with data");
86      List<TableName> tables = Lists.newArrayList(table1, table1);
87      String backupId = fullTableBackup(tables);
88      assertTrue(checkSucceeded(backupId));
89    }
90  
91    @Test
92    public void testFullBackupMultipleCommand() throws Exception {
93      LOG.info("test full backup on a multiple tables with data: command-line");
94      try(BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {    
95        int before = table.getBackupHistory().size();
96        String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR,  
97            table1.getNameAsString() +","+ table2.getNameAsString() }; 
98        // Run backup
99        int ret = ToolRunner.run(conf1, new BackupDriver(), args);
100       assertTrue(ret == 0);
101       ArrayList<BackupInfo> backups = table.getBackupHistory(); 
102       int after = table.getBackupHistory().size();
103       assertTrue(after == before +1);
104       for(BackupInfo data : backups){
105         String backupId = data.getBackupId();
106         assertTrue(checkSucceeded(backupId));
107       }
108     }
109     LOG.info("backup complete");
110   }
111   /**
112    * Verify that full backup is created on all tables correctly.
113    * @throws Exception
114    */
115   @Test
116   public void testFullBackupAll() throws Exception {
117     LOG.info("create full backup image on all tables");
118     String backupId = fullTableBackup(null);
119     assertTrue(checkSucceeded(backupId));
120 
121   }
122   
123   @Test
124   public void testFullBackupAllCommand() throws Exception {
125     LOG.info("create full backup image on all tables: command-line");
126     try(BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {    
127       int before = table.getBackupHistory().size();
128       String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR  }; 
129       // Run backup
130       int ret = ToolRunner.run(conf1, new BackupDriver(), args);
131       assertTrue(ret == 0);
132       ArrayList<BackupInfo> backups = table.getBackupHistory(); 
133       int after = table.getBackupHistory().size();
134       assertTrue(after == before +1);
135       for(BackupInfo data : backups){
136         String backupId = data.getBackupId();
137         assertTrue(checkSucceeded(backupId));
138       }
139     }
140   }
141 }