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
.assertEquals
;
21 import static org
.junit
.Assert
.assertNotNull
;
22 import static org
.junit
.Assert
.assertTrue
;
24 import java
.util
.List
;
25 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
26 import org
.apache
.hadoop
.hbase
.TableName
;
27 import org
.apache
.hadoop
.hbase
.backup
.impl
.BackupSystemTable
;
28 import org
.apache
.hadoop
.hbase
.client
.Admin
;
29 import org
.apache
.hadoop
.hbase
.testclassification
.LargeTests
;
30 import org
.apache
.hadoop
.util
.ToolRunner
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.Test
;
33 import org
.junit
.experimental
.categories
.Category
;
34 import org
.slf4j
.Logger
;
35 import org
.slf4j
.LoggerFactory
;
37 @Category(LargeTests
.class)
38 public class TestFullBackupSet
extends TestBackupBase
{
41 public static final HBaseClassTestRule CLASS_RULE
=
42 HBaseClassTestRule
.forClass(TestFullBackupSet
.class);
44 private static final Logger LOG
= LoggerFactory
.getLogger(TestFullBackupSet
.class);
47 * Verify that full backup is created on a single table with data correctly.
49 * @throws Exception if doing the backup or an operation on the tables fails
52 public void testFullBackupSetExist() throws Exception
{
53 LOG
.info("Test full backup, backup set exists");
56 try (BackupSystemTable table
= new BackupSystemTable(TEST_UTIL
.getConnection())) {
58 table
.addToBackupSet(name
, new String
[] { table1
.getNameAsString() });
59 List
<TableName
> names
= table
.describeBackupSet(name
);
62 assertTrue(names
.size() == 1);
63 assertTrue(names
.get(0).equals(table1
));
65 String
[] args
= new String
[] { "create", "full", BACKUP_ROOT_DIR
, "-s", name
};
67 int ret
= ToolRunner
.run(conf1
, new BackupDriver(), args
);
69 List
<BackupInfo
> backups
= table
.getBackupHistory();
70 assertTrue(backups
.size() == 1);
71 String backupId
= backups
.get(0).getBackupId();
72 assertTrue(checkSucceeded(backupId
));
74 LOG
.info("backup complete");
76 // Restore from set into other table
78 new String
[] { BACKUP_ROOT_DIR
, backupId
, "-s", name
, "-m",
79 table1_restore
.getNameAsString(), "-o" };
81 ret
= ToolRunner
.run(conf1
, new RestoreDriver(), args
);
83 Admin hba
= TEST_UTIL
.getAdmin();
84 assertTrue(hba
.tableExists(table1_restore
));
85 // Verify number of rows in both tables
86 assertEquals(TEST_UTIL
.countRows(table1
), TEST_UTIL
.countRows(table1_restore
));
87 TEST_UTIL
.deleteTable(table1_restore
);
88 LOG
.info("restore into other table is complete");
94 public void testFullBackupSetDoesNotExist() throws Exception
{
95 LOG
.info("test full backup, backup set does not exist");
96 String name
= "name1";
97 String
[] args
= new String
[] { "create", "full", BACKUP_ROOT_DIR
, "-s", name
};
99 int ret
= ToolRunner
.run(conf1
, new BackupDriver(), args
);
100 assertTrue(ret
!= 0);