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.master; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021 022import java.util.HashMap; 023import java.util.HashSet; 024import java.util.Map; 025import java.util.Set; 026import org.apache.hadoop.hbase.HBaseTestingUtil; 027import org.apache.hadoop.hbase.TableName; 028import org.apache.hadoop.hbase.backup.impl.BackupSystemTable; 029import org.apache.hadoop.hbase.client.Admin; 030import org.apache.hadoop.hbase.testclassification.MasterTests; 031import org.apache.hadoop.hbase.testclassification.MediumTests; 032import org.junit.jupiter.api.AfterAll; 033import org.junit.jupiter.api.BeforeAll; 034import org.junit.jupiter.api.Tag; 035import org.junit.jupiter.api.Test; 036 037@Tag(MasterTests.TAG) 038@Tag(MediumTests.TAG) 039public class TestRestoreBackupSystemTable { 040 041 private static final String BACKUP_ROOT = "root"; 042 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 043 044 @BeforeAll 045 public static void setUp() throws Exception { 046 UTIL.startMiniCluster(); 047 } 048 049 @Test 050 public void itRestoresFromSnapshot() throws Exception { 051 BackupSystemTable table = new BackupSystemTable(UTIL.getConnection()); 052 Set<TableName> tables = new HashSet<>(); 053 054 tables.add(TableName.valueOf("test1")); 055 tables.add(TableName.valueOf("test2")); 056 tables.add(TableName.valueOf("test3")); 057 058 Map<String, Long> rsTimestampMap = new HashMap<>(); 059 rsTimestampMap.put("rs1:100", 100L); 060 rsTimestampMap.put("rs2:100", 101L); 061 rsTimestampMap.put("rs3:100", 103L); 062 063 table.writeRegionServerLogTimestamp(tables, rsTimestampMap, BACKUP_ROOT); 064 BackupSystemTable.snapshot(UTIL.getConnection()); 065 066 Admin admin = UTIL.getAdmin(); 067 TableName backupSystemTn = BackupSystemTable.getTableName(UTIL.getConfiguration()); 068 admin.disableTable(backupSystemTn); 069 admin.truncateTable(backupSystemTn, true); 070 071 BackupSystemTable.restoreFromSnapshot(UTIL.getConnection()); 072 Map<TableName, Map<String, Long>> results = table.readLogTimestampMap(BACKUP_ROOT); 073 074 assertEquals(tables.size(), results.size()); 075 076 for (TableName tableName : tables) { 077 Map<String, Long> resultMap = results.get(tableName); 078 assertEquals(rsTimestampMap, resultMap); 079 } 080 } 081 082 @AfterAll 083 public static void tearDown() throws Exception { 084 UTIL.shutdownMiniCluster(); 085 } 086}