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; 019 020import static org.junit.Assert.assertFalse; 021import static org.junit.Assert.assertTrue; 022 023import java.util.List; 024import java.util.Map; 025 026import org.apache.hadoop.hbase.HBaseClassTestRule; 027import org.apache.hadoop.hbase.HBaseTestingUtility; 028import org.apache.hadoop.hbase.HConstants; 029import org.apache.hadoop.hbase.ServerName; 030import org.apache.hadoop.hbase.TableName; 031import org.apache.hadoop.hbase.client.RegionInfo; 032import org.apache.hadoop.hbase.master.assignment.AssignmentManager; 033import org.apache.hadoop.hbase.master.assignment.RegionStates; 034import org.apache.hadoop.hbase.testclassification.LargeTests; 035import org.apache.hadoop.hbase.testclassification.MasterTests; 036import org.junit.After; 037import org.junit.Before; 038import org.junit.ClassRule; 039import org.junit.Rule; 040import org.junit.Test; 041import org.junit.experimental.categories.Category; 042import org.junit.rules.TestName; 043 044/** 045 * Test balancer with disabled table 046 */ 047@Category({ MasterTests.class, LargeTests.class }) 048public class TestBalancer { 049 050 @ClassRule 051 public static final HBaseClassTestRule CLASS_RULE = 052 HBaseClassTestRule.forClass(TestBalancer.class); 053 054 private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 055 056 @Rule 057 public TestName name = new TestName(); 058 059 @Before 060 public void before() throws Exception { 061 TEST_UTIL.startMiniCluster(); 062 } 063 064 @After 065 public void after() throws Exception { 066 TEST_UTIL.shutdownMiniCluster(); 067 } 068 069 @Test 070 public void testAssignmentsForBalancer() throws Exception { 071 final TableName tableName = TableName.valueOf(name.getMethodName()); 072 TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY, 10); 073 // disable table 074 final TableName disableTableName = TableName.valueOf("testDisableTable"); 075 TEST_UTIL.createMultiRegionTable(disableTableName, HConstants.CATALOG_FAMILY, 10); 076 TEST_UTIL.getAdmin().disableTable(disableTableName); 077 078 HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); 079 AssignmentManager assignmentManager = master.getAssignmentManager(); 080 RegionStates regionStates = assignmentManager.getRegionStates(); 081 ServerName sn1 = ServerName.parseServerName("asf903.gq1.ygridcore.net,52690,1517835491385"); 082 regionStates.getOrCreateServer(sn1); 083 084 TableStateManager tableStateManager = master.getTableStateManager(); 085 ServerManager serverManager = master.getServerManager(); 086 Map<TableName, Map<ServerName, List<RegionInfo>>> assignments = 087 assignmentManager.getRegionStates() 088 .getAssignmentsForBalancer(tableStateManager, serverManager.getOnlineServersList()); 089 assertFalse(assignments.containsKey(disableTableName)); 090 assertTrue(assignments.containsKey(tableName)); 091 assertFalse(assignments.get(tableName).containsKey(sn1)); 092 } 093}