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.assertNotEquals;
22  import static org.junit.Assert.assertTrue;
23  
24  import java.io.ByteArrayOutputStream;
25  import java.io.PrintStream;
26  import java.util.List;
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  import org.apache.hadoop.hbase.TableName;
31  import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
32  import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
33  import org.apache.hadoop.hbase.testclassification.LargeTests;
34  import org.apache.hadoop.util.ToolRunner;
35  import org.junit.Test;
36  import org.junit.experimental.categories.Category;
37  
38  import com.google.common.collect.Lists;
39  
40  @Category(LargeTests.class)
41  public class TestBackupDescribe extends TestBackupBase {
42  
43    private static final Log LOG = LogFactory.getLog(TestBackupDescribe.class);
44  
45    /**
46     * Verify that full backup is created on a single table with data correctly. Verify that describe
47     * works as expected
48     * @throws Exception
49     */
50    @Test
51    public void testBackupDescribe() throws Exception {
52  
53      LOG.info("test backup describe on a single table with data");
54      
55      List<TableName> tableList = Lists.newArrayList(table1);
56      String backupId = fullTableBackup(tableList);
57      
58      LOG.info("backup complete");
59      assertTrue(checkSucceeded(backupId));
60  
61  
62      BackupInfo info = getBackupAdmin().getBackupInfo(backupId);
63      assertTrue(info.getState() == BackupState.COMPLETE);
64  
65    }
66  
67    @Test
68    public void testBackupSetCommandWithNonExistentTable() throws Exception {
69      String[] args = new String[]{"set", "add", "some_set", "table" }; 
70      // Run backup
71      int ret = ToolRunner.run(conf1, new BackupDriver(), args);
72      assertNotEquals(ret, 0);
73    }
74  
75    @Test
76    public void testBackupDescribeCommand() throws Exception {
77  
78      LOG.info("test backup describe on a single table with data: command-line");
79      
80      List<TableName> tableList = Lists.newArrayList(table1);
81      String backupId = fullTableBackup(tableList);
82      
83      LOG.info("backup complete");
84      assertTrue(checkSucceeded(backupId));
85  
86      ByteArrayOutputStream baos = new ByteArrayOutputStream();
87      System.setOut(new PrintStream(baos));
88  
89      String[] args = new String[]{"describe",  backupId }; 
90      // Run backup
91      int ret = ToolRunner.run(conf1, new BackupDriver(), args);
92      assertTrue(ret == 0);    
93      String response = baos.toString();
94      assertTrue(response.indexOf(backupId) > 0);
95      assertTrue(response.indexOf("COMPLETE") > 0);
96  
97      BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection());
98      BackupInfo status = table.readBackupInfo(backupId);
99      String desc = status.getShortDescription();
100     table.close();
101     assertTrue(response.indexOf(desc) >= 0);
102 
103   }
104   
105   
106 }