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 TestFullBackupWithFailures
extends TestBackupBase
{
42 public static final HBaseClassTestRule CLASS_RULE
=
43 HBaseClassTestRule
.forClass(TestFullBackupWithFailures
.class);
45 private static final Logger LOG
= LoggerFactory
.getLogger(TestFullBackupWithFailures
.class);
48 public void testFullBackupWithFailures() throws Exception
{
49 conf1
.set(TableBackupClient
.BACKUP_CLIENT_IMPL_CLASS
,
50 FullTableBackupClientForTest
.class.getName());
51 int maxStage
= Stage
.values().length
-1;
52 // Fail stages between 0 and 4 inclusive
53 for (int stage
= 0; stage
<= maxStage
; stage
++) {
54 LOG
.info("Running stage " + stage
);
55 runBackupAndFailAtStage(stage
);
59 public void runBackupAndFailAtStage(int stage
) throws Exception
{
61 conf1
.setInt(FullTableBackupClientForTest
.BACKUP_TEST_MODE_STAGE
, stage
);
62 try (BackupSystemTable table
= new BackupSystemTable(TEST_UTIL
.getConnection())) {
63 int before
= table
.getBackupHistory().size();
65 new String
[] { "create", "full", BACKUP_ROOT_DIR
, "-t",
66 table1
.getNameAsString() + "," + table2
.getNameAsString() };
68 int ret
= ToolRunner
.run(conf1
, new BackupDriver(), args
);
69 assertFalse(ret
== 0);
70 List
<BackupInfo
> backups
= table
.getBackupHistory();
71 int after
= table
.getBackupHistory().size();
73 assertTrue(after
== before
+1);
74 for (BackupInfo data
: backups
) {
75 String backupId
= data
.getBackupId();
76 assertFalse(checkSucceeded(backupId
));
78 Set
<TableName
> tables
= table
.getIncrementalBackupTableSet(BACKUP_ROOT_DIR
);
79 assertTrue(tables
.size() == 0);