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.Assert.assertTrue; 021 022import java.io.ByteArrayOutputStream; 023import java.io.PrintStream; 024import java.util.List; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.TableName; 027import org.apache.hadoop.hbase.backup.BackupInfo.BackupState; 028import org.apache.hadoop.hbase.testclassification.LargeTests; 029import org.apache.hadoop.util.ToolRunner; 030import org.junit.ClassRule; 031import org.junit.Test; 032import org.junit.experimental.categories.Category; 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035 036import org.apache.hbase.thirdparty.com.google.common.collect.Lists; 037 038@Category(LargeTests.class) 039public class TestBackupStatusProgress extends TestBackupBase { 040 041 @ClassRule 042 public static final HBaseClassTestRule CLASS_RULE = 043 HBaseClassTestRule.forClass(TestBackupStatusProgress.class); 044 045 private static final Logger LOG = LoggerFactory.getLogger(TestBackupStatusProgress.class); 046 047 /** 048 * Verify that full backup is created on a single table with data correctly. 049 * @throws Exception if doing the backup or an operation on the tables fails 050 */ 051 @Test 052 public void testBackupStatusProgress() throws Exception { 053 LOG.info("test backup status/progress on a single table with data"); 054 055 List<TableName> tableList = Lists.newArrayList(table1); 056 String backupId = fullTableBackup(tableList); 057 LOG.info("backup complete"); 058 assertTrue(checkSucceeded(backupId)); 059 060 BackupInfo info = getBackupAdmin().getBackupInfo(backupId); 061 assertTrue(info.getState() == BackupState.COMPLETE); 062 063 LOG.debug(info.getShortDescription()); 064 assertTrue(info.getProgress() > 0); 065 066 } 067 068 @Test 069 public void testBackupStatusProgressCommand() throws Exception { 070 LOG.info("test backup status/progress on a single table with data: command-line"); 071 072 List<TableName> tableList = Lists.newArrayList(table1); 073 String backupId = fullTableBackup(tableList); 074 LOG.info("backup complete"); 075 assertTrue(checkSucceeded(backupId)); 076 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 077 System.setOut(new PrintStream(baos)); 078 079 String[] args = new String[] { "describe", backupId }; 080 int ret = ToolRunner.run(conf1, new BackupDriver(), args); 081 assertTrue(ret == 0); 082 String responce = baos.toString(); 083 assertTrue(responce.indexOf(backupId) > 0); 084 assertTrue(responce.indexOf("COMPLETE") > 0); 085 086 baos = new ByteArrayOutputStream(); 087 System.setOut(new PrintStream(baos)); 088 089 args = new String[] { "progress", backupId }; 090 ret = ToolRunner.run(conf1, new BackupDriver(), args); 091 assertTrue(ret == 0); 092 responce = baos.toString(); 093 assertTrue(responce.indexOf(backupId) >= 0); 094 assertTrue(responce.indexOf("progress") > 0); 095 assertTrue(responce.indexOf("100") > 0); 096 } 097}