View Javadoc

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
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
17   */
18  package org.apache.hadoop.hbase.rsgroup;
19  
20  import java.io.IOException;
21  
22  import org.apache.hadoop.conf.Configuration;
23  import org.apache.hadoop.hbase.HBaseTestingUtility;
24  import org.apache.hadoop.hbase.HConstants;
25  import org.apache.hadoop.hbase.Waiter;
26  import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
27  import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
28  import org.apache.hadoop.hbase.testclassification.MediumTests;
29  import org.junit.AfterClass;
30  import org.junit.BeforeClass;
31  import org.junit.Test;
32  import org.junit.experimental.categories.Category;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  /**
37   * Test enable RSGroup
38   */
39  @Category({ MediumTests.class })
40  public class TestEnableRSGroups {
41  
42    protected static final Logger LOG = LoggerFactory.getLogger(TestEnableRSGroups.class);
43  
44    private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
45    private static Configuration conf = TEST_UTIL.getConfiguration();
46  
47    @BeforeClass
48    public static void setUp() throws Exception {
49      TEST_UTIL.startMiniCluster();
50    }
51  
52    @AfterClass
53    public static void tearDown() throws Exception {
54      TEST_UTIL.shutdownMiniCluster();
55    }
56  
57    @Test
58    public void testEnableRSGroups() throws IOException, InterruptedException {
59      TEST_UTIL.getMiniHBaseCluster().stopMaster(0);
60      LOG.info("stopped master...");
61      conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, RSGroupAdminEndpoint.class.getName());
62      conf.set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, RSGroupBasedLoadBalancer.class.getName());
63      TEST_UTIL.getMiniHBaseCluster().setConf(conf);
64  
65      TEST_UTIL.getMiniHBaseCluster().startMaster();
66      TEST_UTIL.getMiniHBaseCluster().waitForActiveAndReadyMaster(60000);
67      LOG.info("started master...");
68  
69      // check if master started successfully
70      Waiter.waitFor(TEST_UTIL.getConfiguration(), 60000, new ExplainingPredicate<IOException>() {
71        @Override
72        public boolean evaluate() throws IOException {
73          return TEST_UTIL.getMiniHBaseCluster().getMaster() != null;
74        }
75  
76        @Override
77        public String explainFailure() throws IOException {
78          return "Master failed to start up";
79        }
80      });
81  
82      // wait RSGroupBasedLoadBalancer online
83      Waiter.waitFor(TEST_UTIL.getConfiguration(), 60000, new ExplainingPredicate<IOException>() {
84        @Override
85        public boolean evaluate() throws IOException {
86          RSGroupBasedLoadBalancer loadBalancer =
87              (RSGroupBasedLoadBalancer) TEST_UTIL.getMiniHBaseCluster().getMaster().getLoadBalancer();
88          return loadBalancer != null && loadBalancer.isOnline();
89        }
90  
91        @Override
92        public String explainFailure() throws IOException {
93          return "RSGroupBasedLoadBalancer failed to come online";
94        }
95      });
96    }
97  
98  }