View Javadoc

1   /**
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
9    * 
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * 
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.
17   */
18  
19  package org.apache.hadoop.hbase.backup;
20  
21  import static org.junit.Assert.assertTrue;
22  
23  import java.io.ByteArrayOutputStream;
24  import java.io.PrintStream;
25  import java.util.List;
26  
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.apache.hadoop.hbase.TableName;
30  import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
31  import org.apache.hadoop.hbase.testclassification.LargeTests;
32  import org.apache.hadoop.util.ToolRunner;
33  import org.junit.Test;
34  import org.junit.experimental.categories.Category;
35  
36  import com.google.common.collect.Lists;
37  
38  @Category(LargeTests.class)
39  public class TestBackupStatusProgress extends TestBackupBase {
40  
41    private static final Log LOG = LogFactory.getLog(TestBackupStatusProgress.class);
42  
43    /**
44     * Verify that full backup is created on a single table with data correctly.
45     * @throws Exception
46     */
47    @Test
48    public void testBackupStatusProgress() throws Exception {
49  
50      LOG.info("test backup status/progress on a single table with data");
51      
52      List<TableName> tableList = Lists.newArrayList(table1);
53      String backupId = fullTableBackup(tableList);
54      LOG.info("backup complete");
55      assertTrue(checkSucceeded(backupId));
56  
57  
58      BackupInfo info = getBackupAdmin().getBackupInfo(backupId);    
59      assertTrue(info.getState() == BackupState.COMPLETE);
60      int p = getBackupAdmin().getProgress(backupId);
61      LOG.debug(info.getShortDescription());
62      assertTrue(p > 0);
63  
64    }
65  
66    @Test
67    public void testBackupStatusProgressCommand() throws Exception {
68  
69      LOG.info("test backup status/progress on a single table with data: command-line");
70      
71      List<TableName> tableList = Lists.newArrayList(table1);
72      String backupId = fullTableBackup(tableList);
73      LOG.info("backup complete");
74      assertTrue(checkSucceeded(backupId));
75      ByteArrayOutputStream baos = new ByteArrayOutputStream();
76      System.setOut(new PrintStream(baos));
77  
78      String[] args = new String[]{"describe",  backupId }; 
79      int ret = ToolRunner.run(conf1, new BackupDriver(), args);
80      assertTrue(ret == 0);
81      String responce = baos.toString();
82      assertTrue(responce.indexOf(backupId) > 0);
83      assertTrue(responce.indexOf("COMPLETE") > 0);
84  
85      baos = new ByteArrayOutputStream();
86      System.setOut(new PrintStream(baos));
87  
88      args = new String[]{"progress",  backupId }; 
89      ret = ToolRunner.run(conf1, new BackupDriver(), args);
90      assertTrue(ret ==0);
91      responce = baos.toString();
92      assertTrue(responce.indexOf(backupId) >= 0);
93      assertTrue(responce.indexOf("progress") > 0);
94      assertTrue(responce.indexOf("100") > 0);
95  
96  
97    }  
98  }