HBASE-26416 Implement a new method for region replication instead of using replay...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / master / TestBalancer.java
blob7fef729e91ab2210644e06adb724abea2aefeced
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.master;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
23 import java.util.List;
24 import java.util.Map;
26 import org.apache.hadoop.hbase.HBaseClassTestRule;
27 import org.apache.hadoop.hbase.HBaseTestingUtil;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.ServerName;
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.client.RegionInfo;
32 import org.apache.hadoop.hbase.master.assignment.AssignmentManager;
33 import org.apache.hadoop.hbase.master.assignment.RegionStates;
34 import org.apache.hadoop.hbase.testclassification.LargeTests;
35 import org.apache.hadoop.hbase.testclassification.MasterTests;
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.ClassRule;
39 import org.junit.Rule;
40 import org.junit.Test;
41 import org.junit.experimental.categories.Category;
42 import org.junit.rules.TestName;
44 /**
45 * Test balancer with disabled table
47 @Category({ MasterTests.class, LargeTests.class })
48 public class TestBalancer {
50 @ClassRule
51 public static final HBaseClassTestRule CLASS_RULE =
52 HBaseClassTestRule.forClass(TestBalancer.class);
54 private final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
56 @Rule
57 public TestName name = new TestName();
59 @Before
60 public void before() throws Exception {
61 TEST_UTIL.startMiniCluster();
64 @After
65 public void after() throws Exception {
66 TEST_UTIL.shutdownMiniCluster();
69 @Test
70 public void testAssignmentsForBalancer() throws Exception {
71 final TableName tableName = TableName.valueOf(name.getMethodName());
72 TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY, 10);
73 // disable table
74 final TableName disableTableName = TableName.valueOf("testDisableTable");
75 TEST_UTIL.createMultiRegionTable(disableTableName, HConstants.CATALOG_FAMILY, 10);
76 TEST_UTIL.getAdmin().disableTable(disableTableName);
78 HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
79 AssignmentManager assignmentManager = master.getAssignmentManager();
80 RegionStates regionStates = assignmentManager.getRegionStates();
81 ServerName sn1 = ServerName.parseServerName("asf903.gq1.ygridcore.net,52690,1517835491385");
82 regionStates.getOrCreateServer(sn1);
84 TableStateManager tableStateManager = master.getTableStateManager();
85 ServerManager serverManager = master.getServerManager();
86 Map<TableName, Map<ServerName, List<RegionInfo>>> assignments =
87 assignmentManager.getRegionStates()
88 .getAssignmentsForBalancer(tableStateManager, serverManager.getOnlineServersList());
89 assertFalse(assignments.containsKey(disableTableName));
90 assertTrue(assignments.containsKey(tableName));
91 assertFalse(assignments.get(tableName).containsKey(sn1));