1
2
3
4
5
6
7
8
9
10
11
12 package org.apache.hadoop.hbase.backup;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.List;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.hadoop.hbase.TableName;
22 import org.apache.hadoop.hbase.client.BackupAdmin;
23 import org.apache.hadoop.hbase.client.Delete;
24 import org.apache.hadoop.hbase.client.HBaseAdmin;
25 import org.apache.hadoop.hbase.client.Table;
26 import org.apache.hadoop.hbase.testclassification.MediumTests;
27 import org.junit.Test;
28 import org.junit.experimental.categories.Category;
29
30 import com.google.common.collect.Lists;
31
32 @Category(MediumTests.class)
33 public class TestBackupDeleteRestore extends TestBackupBase {
34
35 private static final Log LOG = LogFactory.getLog(TestBackupDeleteRestore.class);
36
37
38
39
40
41
42 @Test
43 public void testBackupDeleteRestore() throws Exception {
44
45 LOG.info("test full restore on a single table empty table");
46
47 List<TableName> tables = Lists.newArrayList(table1);
48 String backupId = fullTableBackup(tables);
49 assertTrue(checkSucceeded(backupId));
50 LOG.info("backup complete");
51 int numRows = TEST_UTIL.countRows(table1);
52 HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
53
54 try ( Table table = TEST_UTIL.getConnection().getTable(table1);) {
55 Delete delete = new Delete("row0".getBytes());
56 table.delete(delete);
57 hba.flush(table1);
58 }
59 int numRowsAfterDelete = TEST_UTIL.countRows(table1);
60 assertTrue(numRowsAfterDelete == numRows -1);
61
62 TableName[] tableset = new TableName[] { table1 };
63 TableName[] tablemap = null;
64 BackupAdmin client = getBackupAdmin();
65 client.restore(createRestoreRequest(BACKUP_ROOT_DIR, backupId, true, tableset, tablemap, true));
66
67 int numRowsAfterRestore = TEST_UTIL.countRows(table1);
68 assertEquals( numRows, numRowsAfterRestore);
69 hba.close();
70 }
71 }