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.assertThrows;
021
022import java.io.IOException;
023import java.util.List;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.hadoop.hbase.testclassification.LargeTests;
026import org.junit.jupiter.api.Tag;
027import org.junit.jupiter.api.Test;
028import org.slf4j.Logger;
029import org.slf4j.LoggerFactory;
030
031import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
032
033@Tag(LargeTests.TAG)
034public class TestBackupBoundaryTests extends TestBackupBase {
035
036  private static final Logger LOG = LoggerFactory.getLogger(TestBackupBoundaryTests.class);
037
038  /**
039   * Verify that full backup is created on a single empty table correctly.
040   * @throws Exception if doing the full backup fails
041   */
042  @Test
043  public void testFullBackupSingleEmpty() throws Exception {
044    LOG.info("create full backup image on single table");
045    List<TableName> tables = Lists.newArrayList(table3);
046    LOG.info("Finished Backup " + fullTableBackup(tables));
047  }
048
049  /**
050   * Verify that full backup is created on multiple empty tables correctly.
051   * @throws Exception if doing the full backup fails
052   */
053  @Test
054  public void testFullBackupMultipleEmpty() throws Exception {
055    LOG.info("create full backup image on mulitple empty tables");
056
057    List<TableName> tables = Lists.newArrayList(table3, table4);
058    fullTableBackup(tables);
059  }
060
061  /**
062   * Verify that full backup fails on a single table that does not exist.
063   * @throws Exception if doing the full backup fails
064   */
065  @Test
066  public void testFullBackupSingleDNE() throws Exception {
067    assertThrows(IOException.class, () -> {
068      LOG.info("test full backup fails on a single table that does not exist");
069      List<TableName> tables = toList("tabledne");
070      fullTableBackup(tables);
071    });
072  }
073
074  /**
075   * Verify that full backup fails on multiple tables that do not exist.
076   * @throws Exception if doing the full backup fails
077   */
078  @Test
079  public void testFullBackupMultipleDNE() throws Exception {
080    assertThrows(IOException.class, () -> {
081      LOG.info("test full backup fails on multiple tables that do not exist");
082      List<TableName> tables = toList("table1dne", "table2dne");
083      fullTableBackup(tables);
084    });
085  }
086
087  /**
088   * Verify that full backup fails on tableset containing real and fake tables.
089   * @throws Exception if doing the full backup fails
090   */
091  @Test
092  public void testFullBackupMixExistAndDNE() throws Exception {
093    assertThrows(IOException.class, () -> {
094      LOG.info("create full backup fails on tableset containing real and fake table");
095
096      List<TableName> tables = toList(table1.getNameAsString(), "tabledne");
097      fullTableBackup(tables);
098    });
099  }
100}