001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.backup;
019
020import static org.junit.jupiter.api.Assertions.assertTrue;
021
022import java.io.ByteArrayOutputStream;
023import java.io.PrintStream;
024import java.util.List;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
027import org.apache.hadoop.hbase.testclassification.LargeTests;
028import org.apache.hadoop.util.ToolRunner;
029import org.junit.jupiter.api.Tag;
030import org.junit.jupiter.api.Test;
031import org.slf4j.Logger;
032import org.slf4j.LoggerFactory;
033
034import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
035
036@Tag(LargeTests.TAG)
037public class TestBackupStatusProgress extends TestBackupBase {
038
039  private static final Logger LOG = LoggerFactory.getLogger(TestBackupStatusProgress.class);
040
041  /**
042   * Verify that full backup is created on a single table with data correctly.
043   * @throws Exception if doing the backup or an operation on the tables fails
044   */
045  @Test
046  public void testBackupStatusProgress() throws Exception {
047    LOG.info("test backup status/progress on a single table with data");
048
049    List<TableName> tableList = Lists.newArrayList(table1);
050    String backupId = fullTableBackup(tableList);
051    LOG.info("backup complete");
052    assertTrue(checkSucceeded(backupId));
053
054    BackupInfo info = getBackupAdmin().getBackupInfo(backupId);
055    assertTrue(info.getState() == BackupState.COMPLETE);
056
057    LOG.debug(info.getShortDescription());
058    assertTrue(info.getProgress() > 0);
059
060  }
061
062  @Test
063  public void testBackupStatusProgressCommand() throws Exception {
064    LOG.info("test backup status/progress on a single table with data: command-line");
065
066    List<TableName> tableList = Lists.newArrayList(table1);
067    String backupId = fullTableBackup(tableList);
068    LOG.info("backup complete");
069    assertTrue(checkSucceeded(backupId));
070    ByteArrayOutputStream baos = new ByteArrayOutputStream();
071    System.setOut(new PrintStream(baos));
072
073    String[] args = new String[] { "describe", backupId };
074    int ret = ToolRunner.run(conf1, new BackupDriver(), args);
075    assertTrue(ret == 0);
076    String responce = baos.toString();
077    assertTrue(responce.indexOf(backupId) > 0);
078    assertTrue(responce.indexOf("COMPLETE") > 0);
079
080    baos = new ByteArrayOutputStream();
081    System.setOut(new PrintStream(baos));
082
083    args = new String[] { "progress", backupId };
084    ret = ToolRunner.run(conf1, new BackupDriver(), args);
085    assertTrue(ret == 0);
086    responce = baos.toString();
087    assertTrue(responce.indexOf(backupId) >= 0);
088    assertTrue(responce.indexOf("progress") > 0);
089    assertTrue(responce.indexOf("100") > 0);
090  }
091}