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.assertTrue;
22
23 import java.io.ByteArrayOutputStream;
24 import java.io.PrintStream;
25 import java.util.List;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.hadoop.hbase.TableName;
30 import org.apache.hadoop.hbase.testclassification.LargeTests;
31 import org.apache.hadoop.util.ToolRunner;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
34
35 import com.google.common.collect.Lists;
36
37 @Category(LargeTests.class)
38 public class TestBackupShowHistory extends TestBackupBase {
39
40 private static final Log LOG = LogFactory.getLog(TestBackupShowHistory.class);
41
42
43
44
45
46
47 @Test
48 public void testBackupHistory() throws Exception {
49
50 LOG.info("test backup history on a single table with data");
51
52 List<TableName> tableList = Lists.newArrayList(table1);
53 String backupId = fullTableBackup(tableList);
54 assertTrue(checkSucceeded(backupId));
55 LOG.info("backup complete");
56
57 List<BackupInfo> history = getBackupAdmin().getHistory(10);
58 assertTrue(history.size() > 0);
59 boolean success = false;
60 for(BackupInfo info: history){
61 if(info.getBackupId().equals(backupId)){
62 success = true; break;
63 }
64 }
65 assertTrue(success);
66 LOG.info("show_history");
67
68 }
69
70 @Test
71 public void testBackupHistoryCommand() throws Exception {
72
73 LOG.info("test backup history on a single table with data: command-line");
74
75 List<TableName> tableList = Lists.newArrayList(table1);
76 String backupId = fullTableBackup(tableList);
77 assertTrue(checkSucceeded(backupId));
78 LOG.info("backup complete");
79
80 ByteArrayOutputStream baos = new ByteArrayOutputStream();
81 System.setOut(new PrintStream(baos));
82
83 String[] args = new String[]{"history", "-n", "10" };
84
85 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
86 assertTrue(ret == 0);
87 LOG.info("show_history");
88 String output = baos.toString();
89 LOG.info(baos.toString());
90 assertTrue(output.indexOf(backupId) > 0);
91 }
92 }