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