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
.assertFalse
;
21 import static org
.junit
.Assert
.assertTrue
;
23 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
.backup
.impl
.TableBackupClient
;
29 import org
.apache
.hadoop
.hbase
.backup
.impl
.TableBackupClient
.Stage
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.LargeTests
;
31 import org
.apache
.hadoop
.util
.ToolRunner
;
32 import org
.junit
.ClassRule
;
33 import org
.junit
.Test
;
34 import org
.junit
.experimental
.categories
.Category
;
35 import org
.slf4j
.Logger
;
36 import org
.slf4j
.LoggerFactory
;
38 @Category(LargeTests
.class)
39 public class TestBackupRepair
extends TestBackupBase
{
42 public static final HBaseClassTestRule CLASS_RULE
=
43 HBaseClassTestRule
.forClass(TestBackupRepair
.class);
45 private static final Logger LOG
= LoggerFactory
.getLogger(TestBackupRepair
.class);
49 public void testFullBackupWithFailuresAndRestore() throws Exception
{
51 autoRestoreOnFailure
= false;
53 conf1
.set(TableBackupClient
.BACKUP_CLIENT_IMPL_CLASS
,
54 FullTableBackupClientForTest
.class.getName());
55 int maxStage
= Stage
.values().length
-1;
56 // Fail stage in loop between 0 and 4 inclusive
57 for (int stage
= 0; stage
< maxStage
; stage
++) {
58 LOG
.info("Running stage " + stage
);
59 runBackupAndFailAtStageWithRestore(stage
);
63 public void runBackupAndFailAtStageWithRestore(int stage
) throws Exception
{
65 conf1
.setInt(FullTableBackupClientForTest
.BACKUP_TEST_MODE_STAGE
, stage
);
66 try (BackupSystemTable table
= new BackupSystemTable(TEST_UTIL
.getConnection())) {
67 int before
= table
.getBackupHistory().size();
69 new String
[] { "create", "full", BACKUP_ROOT_DIR
, "-t",
70 table1
.getNameAsString() + "," + table2
.getNameAsString() };
72 int ret
= ToolRunner
.run(conf1
, new BackupDriver(), args
);
73 assertFalse(ret
== 0);
76 args
= new String
[] {"repair"};
78 ret
= ToolRunner
.run(conf1
, new BackupDriver(), args
);
81 List
<BackupInfo
> backups
= table
.getBackupHistory();
82 int after
= table
.getBackupHistory().size();
84 assertTrue(after
== before
+1);
85 for (BackupInfo data
: backups
) {
86 String backupId
= data
.getBackupId();
87 assertFalse(checkSucceeded(backupId
));
89 Set
<TableName
> tables
= table
.getIncrementalBackupTableSet(BACKUP_ROOT_DIR
);
90 assertTrue(tables
.size() == 0);