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.assertEquals; 021import static org.junit.Assert.assertTrue; 022 023import java.util.List; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.backup.util.BackupUtils; 027import org.apache.hadoop.hbase.client.Admin; 028import org.apache.hadoop.hbase.client.Delete; 029import org.apache.hadoop.hbase.client.Table; 030import org.apache.hadoop.hbase.testclassification.MediumTests; 031import org.apache.hadoop.hbase.util.Bytes; 032import org.junit.ClassRule; 033import org.junit.Test; 034import org.junit.experimental.categories.Category; 035import org.slf4j.Logger; 036import org.slf4j.LoggerFactory; 037 038import org.apache.hbase.thirdparty.com.google.common.collect.Lists; 039 040@Category(MediumTests.class) 041public class TestBackupDeleteRestore extends TestBackupBase { 042 043 @ClassRule 044 public static final HBaseClassTestRule CLASS_RULE = 045 HBaseClassTestRule.forClass(TestBackupDeleteRestore.class); 046 047 private static final Logger LOG = LoggerFactory.getLogger(TestBackupDeleteRestore.class); 048 049 /** 050 * Verify that load data- backup - delete some data - restore works as expected - deleted data get 051 * restored. 052 * @throws Exception if doing the backup or an operation on the tables fails 053 */ 054 @Test 055 public void testBackupDeleteRestore() throws Exception { 056 LOG.info("test full restore on a single table empty table"); 057 058 List<TableName> tables = Lists.newArrayList(table1); 059 String backupId = fullTableBackup(tables); 060 assertTrue(checkSucceeded(backupId)); 061 LOG.info("backup complete"); 062 int numRows = TEST_UTIL.countRows(table1); 063 Admin hba = TEST_UTIL.getAdmin(); 064 // delete row 065 try (Table table = TEST_UTIL.getConnection().getTable(table1)) { 066 Delete delete = new Delete(Bytes.toBytes("row0")); 067 table.delete(delete); 068 hba.flush(table1); 069 } 070 071 TableName[] tableset = new TableName[] { table1 }; 072 TableName[] tablemap = null;// new TableName[] { table1_restore }; 073 BackupAdmin client = getBackupAdmin(); 074 client.restore( 075 BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, backupId, false, tableset, tablemap, true)); 076 077 int numRowsAfterRestore = TEST_UTIL.countRows(table1); 078 assertEquals(numRows, numRowsAfterRestore); 079 hba.close(); 080 } 081}