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.*;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
30 import org.apache.hadoop.hbase.client.HBaseAdmin;
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 @Category(LargeTests.class)
37 public class TestFullBackupSet extends TestBackupBase {
38
39 private static final Log LOG = LogFactory.getLog(TestFullBackupSet.class);
40
41
42
43
44
45
46 @Test
47 public void testFullBackupSetExist() throws Exception {
48
49 LOG.info("Test full backup, backup set exists");
50
51
52 try (BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
53 String name = "name";
54 table.addToBackupSet(name, new String[] { table1.getNameAsString() });
55 List<TableName> names = table.describeBackupSet(name);
56
57 assertNotNull(names);
58 assertTrue(names.size() == 1);
59 assertTrue(names.get(0).equals(table1));
60
61 String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-set", name };
62
63 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
64 assertTrue(ret == 0);
65 ArrayList<BackupInfo> backups = table.getBackupHistory();
66 assertTrue(backups.size() == 1);
67 String backupId = backups.get(0).getBackupId();
68 assertTrue(checkSucceeded(backupId));
69
70 LOG.info("backup complete");
71
72
73 args = new String[]{BACKUP_ROOT_DIR, backupId,
74 "-set", name, table1_restore.getNameAsString(), "-overwrite" };
75
76 ret = ToolRunner.run(conf1, new RestoreDriver(), args);
77 assertTrue(ret == 0);
78 HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
79 assertTrue(hba.tableExists(table1_restore));
80
81 assertEquals(TEST_UTIL.countRows(table1), TEST_UTIL.countRows(table1_restore));
82 TEST_UTIL.deleteTable(table1_restore);
83 LOG.info("restore into other table is complete");
84 hba.close();
85
86
87 }
88
89 }
90
91 @Test
92 public void testFullBackupSetDoesNotExist() throws Exception {
93
94 LOG.info("TFBSE test full backup, backup set does not exist");
95 String name = "name1";
96 String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR, "-set", name };
97
98 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
99 assertTrue(ret != 0);
100
101 }
102
103 }