2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.backup
;
20 import static org
.junit
.Assert
.assertTrue
;
22 import java
.util
.List
;
23 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
24 import org
.apache
.hadoop
.hbase
.TableName
;
25 import org
.apache
.hadoop
.hbase
.backup
.impl
.BackupAdminImpl
;
26 import org
.apache
.hadoop
.hbase
.backup
.util
.BackupUtils
;
27 import org
.apache
.hadoop
.hbase
.client
.Admin
;
28 import org
.apache
.hadoop
.hbase
.client
.Connection
;
29 import org
.apache
.hadoop
.hbase
.client
.ConnectionFactory
;
30 import org
.apache
.hadoop
.hbase
.client
.Put
;
31 import org
.apache
.hadoop
.hbase
.client
.Table
;
32 import org
.apache
.hadoop
.hbase
.testclassification
.LargeTests
;
33 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
34 import org
.junit
.Assert
;
35 import org
.junit
.ClassRule
;
36 import org
.junit
.Test
;
37 import org
.junit
.experimental
.categories
.Category
;
38 import org
.slf4j
.Logger
;
39 import org
.slf4j
.LoggerFactory
;
41 import org
.apache
.hbase
.thirdparty
.com
.google
.common
.collect
.Lists
;
44 * 1. Create table t1, t2
45 * 2. Load data to t1, t2
46 * 3 Full backup t1, t2
49 * 6 Incremental backup t1
51 @Category(LargeTests
.class)
52 public class TestIncrementalBackupDeleteTable
extends TestBackupBase
{
55 public static final HBaseClassTestRule CLASS_RULE
=
56 HBaseClassTestRule
.forClass(TestIncrementalBackupDeleteTable
.class);
58 private static final Logger LOG
= LoggerFactory
.getLogger(TestIncrementalBackupDeleteTable
.class);
60 // implement all test cases in 1 test since incremental backup/restore has dependencies
62 public void testIncBackupDeleteTable() throws Exception
{
63 // #1 - create full backup for all tables
64 LOG
.info("create full backup image for all tables");
66 List
<TableName
> tables
= Lists
.newArrayList(table1
, table2
);
67 Connection conn
= ConnectionFactory
.createConnection(conf1
);
68 Admin admin
= conn
.getAdmin();
69 BackupAdminImpl client
= new BackupAdminImpl(conn
);
71 BackupRequest request
= createBackupRequest(BackupType
.FULL
, tables
, BACKUP_ROOT_DIR
);
72 String backupIdFull
= client
.backupTables(request
);
74 assertTrue(checkSucceeded(backupIdFull
));
76 // #2 - insert some data to table table1
77 Table t1
= conn
.getTable(table1
);
79 for (int i
= 0; i
< NB_ROWS_IN_BATCH
; i
++) {
80 p1
= new Put(Bytes
.toBytes("row-t1" + i
));
81 p1
.addColumn(famName
, qualName
, Bytes
.toBytes("val" + i
));
85 Assert
.assertEquals(TEST_UTIL
.countRows(t1
), NB_ROWS_IN_BATCH
* 2);
88 // Delete table table2
89 admin
.disableTable(table2
);
90 admin
.deleteTable(table2
);
92 // #3 - incremental backup for table1
93 tables
= Lists
.newArrayList(table1
);
94 request
= createBackupRequest(BackupType
.INCREMENTAL
, tables
, BACKUP_ROOT_DIR
);
95 String backupIdIncMultiple
= client
.backupTables(request
);
96 assertTrue(checkSucceeded(backupIdIncMultiple
));
98 // #4 - restore full backup for all tables, without overwrite
99 TableName
[] tablesRestoreFull
= new TableName
[] { table1
, table2
};
101 TableName
[] tablesMapFull
= new TableName
[] { table1_restore
, table2_restore
};
103 client
.restore(BackupUtils
.createRestoreRequest(BACKUP_ROOT_DIR
, backupIdFull
, false,
104 tablesRestoreFull
, tablesMapFull
, false));
106 // #5.1 - check tables for full restore
107 Admin hAdmin
= TEST_UTIL
.getAdmin();
108 assertTrue(hAdmin
.tableExists(table1_restore
));
109 assertTrue(hAdmin
.tableExists(table2_restore
));
111 // #5.2 - checking row count of tables for full restore
112 Table hTable
= conn
.getTable(table1_restore
);
113 Assert
.assertEquals(TEST_UTIL
.countRows(hTable
), NB_ROWS_IN_BATCH
);
116 hTable
= conn
.getTable(table2_restore
);
117 Assert
.assertEquals(TEST_UTIL
.countRows(hTable
), NB_ROWS_IN_BATCH
);
120 // #6 - restore incremental backup for table1
121 TableName
[] tablesRestoreIncMultiple
= new TableName
[] { table1
};
122 TableName
[] tablesMapIncMultiple
= new TableName
[] { table1_restore
};
123 client
.restore(BackupUtils
.createRestoreRequest(BACKUP_ROOT_DIR
, backupIdIncMultiple
,
124 false, tablesRestoreIncMultiple
, tablesMapIncMultiple
, true));
126 hTable
= conn
.getTable(table1_restore
);
127 Assert
.assertEquals(TEST_UTIL
.countRows(hTable
), NB_ROWS_IN_BATCH
* 2);