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
.rsgroup
;
20 import static java
.lang
.Thread
.sleep
;
21 import static org
.junit
.Assert
.assertTrue
;
23 import java
.io
.IOException
;
25 import org
.apache
.hadoop
.conf
.Configuration
;
26 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
27 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
28 import org
.apache
.hadoop
.hbase
.HConstants
;
29 import org
.apache
.hadoop
.hbase
.coprocessor
.CoprocessorHost
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
31 import org
.junit
.AfterClass
;
32 import org
.junit
.BeforeClass
;
33 import org
.junit
.ClassRule
;
34 import org
.junit
.Test
;
35 import org
.junit
.experimental
.categories
.Category
;
36 import org
.slf4j
.Logger
;
37 import org
.slf4j
.LoggerFactory
;
42 @Category({ MediumTests
.class })
43 public class TestEnableRSGroup
{
46 public static final HBaseClassTestRule CLASS_RULE
=
47 HBaseClassTestRule
.forClass(TestEnableRSGroup
.class);
49 protected static final Logger LOG
= LoggerFactory
.getLogger(TestEnableRSGroup
.class);
51 private static final HBaseTestingUtility TEST_UTIL
= new HBaseTestingUtility();
54 public static void setUp() throws Exception
{
55 final Configuration conf
= TEST_UTIL
.getConfiguration();
56 conf
.setBoolean(CoprocessorHost
.COPROCESSORS_ENABLED_CONF_KEY
, true);
57 TEST_UTIL
.startMiniCluster(5);
61 public static void tearDown() throws Exception
{
62 LOG
.info("to stop miniCluster");
63 TEST_UTIL
.shutdownMiniCluster();
67 public void testEnableRSGroup() throws IOException
, InterruptedException
{
68 TEST_UTIL
.getMiniHBaseCluster().stopMaster(0);
69 TEST_UTIL
.getMiniHBaseCluster().waitOnMaster(0);
71 LOG
.info("stopped master...");
72 final Configuration conf
= TEST_UTIL
.getMiniHBaseCluster().getConfiguration();
73 conf
.set(CoprocessorHost
.MASTER_COPROCESSOR_CONF_KEY
, RSGroupAdminEndpoint
.class.getName());
74 conf
.set(HConstants
.HBASE_MASTER_LOADBALANCER_CLASS
, RSGroupBasedLoadBalancer
.class.getName());
76 TEST_UTIL
.getMiniHBaseCluster().startMaster();
77 TEST_UTIL
.getMiniHBaseCluster().waitForActiveAndReadyMaster(60000);
78 LOG
.info("started master...");
80 // check if master started successfully
81 assertTrue(TEST_UTIL
.getMiniHBaseCluster().getMaster() != null);
83 // wait RSGroupBasedLoadBalancer online
84 RSGroupBasedLoadBalancer loadBalancer
=
85 (RSGroupBasedLoadBalancer
) TEST_UTIL
.getMiniHBaseCluster().getMaster().getLoadBalancer();
86 long start
= System
.currentTimeMillis();
87 while (System
.currentTimeMillis() - start
<= 60000 && !loadBalancer
.isOnline()) {
88 LOG
.info("waiting for rsgroup load balancer onLine...");
92 assertTrue(loadBalancer
.isOnline());