1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
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
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 }