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.backup.BackupInfo.BackupState;
31 import org.apache.hadoop.hbase.testclassification.LargeTests;
32 import org.apache.hadoop.util.ToolRunner;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36 import com.google.common.collect.Lists;
37
38 @Category(LargeTests.class)
39 public class TestBackupStatusProgress extends TestBackupBase {
40
41 private static final Log LOG = LogFactory.getLog(TestBackupStatusProgress.class);
42
43
44
45
46
47 @Test
48 public void testBackupStatusProgress() throws Exception {
49
50 LOG.info("test backup status/progress on a single table with data");
51
52 List<TableName> tableList = Lists.newArrayList(table1);
53 String backupId = fullTableBackup(tableList);
54 LOG.info("backup complete");
55 assertTrue(checkSucceeded(backupId));
56
57
58 BackupInfo info = getBackupAdmin().getBackupInfo(backupId);
59 assertTrue(info.getState() == BackupState.COMPLETE);
60 int p = getBackupAdmin().getProgress(backupId);
61 LOG.debug(info.getShortDescription());
62 assertTrue(p > 0);
63
64 }
65
66 @Test
67 public void testBackupStatusProgressCommand() throws Exception {
68
69 LOG.info("test backup status/progress on a single table with data: command-line");
70
71 List<TableName> tableList = Lists.newArrayList(table1);
72 String backupId = fullTableBackup(tableList);
73 LOG.info("backup complete");
74 assertTrue(checkSucceeded(backupId));
75 ByteArrayOutputStream baos = new ByteArrayOutputStream();
76 System.setOut(new PrintStream(baos));
77
78 String[] args = new String[]{"describe", backupId };
79 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
80 assertTrue(ret == 0);
81 String responce = baos.toString();
82 assertTrue(responce.indexOf(backupId) > 0);
83 assertTrue(responce.indexOf("COMPLETE") > 0);
84
85 baos = new ByteArrayOutputStream();
86 System.setOut(new PrintStream(baos));
87
88 args = new String[]{"progress", backupId };
89 ret = ToolRunner.run(conf1, new BackupDriver(), args);
90 assertTrue(ret ==0);
91 responce = baos.toString();
92 assertTrue(responce.indexOf(backupId) >= 0);
93 assertTrue(responce.indexOf("progress") > 0);
94 assertTrue(responce.indexOf("100") > 0);
95
96
97 }
98 }