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.master.assignment; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertTrue; 022 023import java.io.IOException; 024import java.util.HashSet; 025import java.util.List; 026import java.util.Set; 027import org.apache.hadoop.hbase.HBaseTestingUtil; 028import org.apache.hadoop.hbase.ServerName; 029import org.apache.hadoop.hbase.client.RegionInfo; 030import org.apache.hadoop.hbase.master.HMaster; 031import org.apache.hadoop.hbase.testclassification.MasterTests; 032import org.apache.hadoop.hbase.testclassification.MediumTests; 033import org.junit.jupiter.api.AfterAll; 034import org.junit.jupiter.api.BeforeAll; 035import org.junit.jupiter.api.Tag; 036import org.junit.jupiter.api.Test; 037 038@Tag(MasterTests.TAG) 039@Tag(MediumTests.TAG) 040public class TestAssignmentManagerLoadMetaRegionState { 041 042 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 043 044 @BeforeAll 045 public static void setUp() throws Exception { 046 UTIL.startMiniCluster(1); 047 } 048 049 @AfterAll 050 public static void tearDown() throws IOException { 051 UTIL.shutdownMiniCluster(); 052 } 053 054 @Test 055 public void testRestart() throws InterruptedException, IOException { 056 ServerName sn = UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName(); 057 AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager(); 058 Set<RegionInfo> regions = new HashSet<>(am.getRegionsOnServer(sn)); 059 060 UTIL.getMiniHBaseCluster().stopMaster(0).join(); 061 HMaster newMaster = UTIL.getMiniHBaseCluster().startMaster().getMaster(); 062 UTIL.waitFor(30000, () -> newMaster.isInitialized()); 063 064 am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager(); 065 List<RegionInfo> newRegions = am.getRegionsOnServer(sn); 066 assertEquals(regions.size(), newRegions.size()); 067 for (RegionInfo region : newRegions) { 068 assertTrue(regions.contains(region)); 069 } 070 } 071}