1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
47
48
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
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
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 }