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 org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.fs.FileSystem; 022import org.apache.hadoop.fs.Path; 023import org.apache.hadoop.hbase.HBaseConfiguration; 024import org.apache.hadoop.hbase.IntegrationTestingUtility; 025import org.apache.hadoop.hbase.backup.impl.BackupManager; 026import org.apache.hadoop.hbase.testclassification.IntegrationTests; 027import org.apache.hadoop.util.ToolRunner; 028import org.junit.jupiter.api.BeforeEach; 029import org.junit.jupiter.api.Tag; 030import org.junit.jupiter.api.Test; 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033 034/** 035 * An integration test to detect regressions in HBASE-7912. Create a table with many regions, load 036 * data, perform series backup/load operations, then restore and verify data 037 * @see <a href="https://issues.apache.org/jira/browse/HBASE-7912">HBASE-7912</a> 038 * @see <a href="https://issues.apache.org/jira/browse/HBASE-14123">HBASE-14123</a> 039 */ 040@Tag(IntegrationTests.TAG) 041public class IntegrationTestBackupRestore extends IntegrationTestBackupRestoreBase { 042 private static final String CLASS_NAME = IntegrationTestBackupRestore.class.getSimpleName(); 043 protected static final Logger LOG = LoggerFactory.getLogger(IntegrationTestBackupRestore.class); 044 045 @Override 046 @BeforeEach 047 public void setUp() throws Exception { 048 initializeTestParameters(); 049 BackupTestUtil.enableBackup(conf); 050 LOG.info("Initializing cluster with {} region servers.", regionServerCount); 051 util.initializeCluster(regionServerCount); 052 LOG.info("Cluster initialized and ready"); 053 054 backupRootDir = util.getDataTestDirOnTestFS() + Path.SEPARATOR + DEFAULT_BACKUP_ROOT_DIR; 055 LOG.info("The backup root directory is: {}", backupRootDir); 056 fs = FileSystem.get(conf); 057 } 058 059 @Test 060 public void testBackupRestore() throws Exception { 061 LOG.info("Running backup and restore integration test with continuous backup disabled"); 062 createTables(CLASS_NAME); 063 runTestMulti(false); 064 } 065 066 /** Returns status of CLI execution */ 067 @Override 068 public int runTestFromCommandLine() throws Exception { 069 // Check if backup is enabled 070 if (!BackupManager.isBackupEnabled(getConf())) { 071 System.err.println(BackupRestoreConstants.ENABLE_BACKUP); 072 return -1; 073 } 074 System.out.println(BackupRestoreConstants.VERIFY_BACKUP); 075 testBackupRestore(); 076 return 0; 077 } 078 079 public static void main(String[] args) throws Exception { 080 Configuration conf = HBaseConfiguration.create(); 081 IntegrationTestingUtility.setUseDistributedCluster(conf); 082 int status = ToolRunner.run(conf, new IntegrationTestBackupRestore(), args); 083 System.exit(status); 084 } 085}