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