HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / rsgroup / EnableRSGroupsTestBase.java
blobdc3144f37187215b0a95a7fbb47564db16f46144
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.rsgroup;
20 import static java.lang.Thread.sleep;
21 import static org.junit.Assert.assertTrue;
23 import java.io.IOException;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseTestingUtility;
26 import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public abstract class EnableRSGroupsTestBase {
35 private static final Logger LOG = LoggerFactory.getLogger(TestEnableRSGroupsCompatibility.class);
37 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
39 @BeforeClass
40 public static void setUp() throws Exception {
41 final Configuration conf = TEST_UTIL.getConfiguration();
42 conf.setBoolean(CoprocessorHost.COPROCESSORS_ENABLED_CONF_KEY, true);
43 TEST_UTIL.startMiniCluster(5);
46 @AfterClass
47 public static void tearDown() throws Exception {
48 LOG.info("to stop miniCluster");
49 TEST_UTIL.shutdownMiniCluster();
52 protected abstract void enableRSGroup(Configuration conf);
54 @Test
55 public void testEnableRSGroup() throws IOException, InterruptedException {
56 TEST_UTIL.getMiniHBaseCluster().stopMaster(0);
57 TEST_UTIL.getMiniHBaseCluster().waitOnMaster(0);
59 LOG.info("stopped master...");
60 enableRSGroup(TEST_UTIL.getMiniHBaseCluster().getConfiguration());
62 TEST_UTIL.getMiniHBaseCluster().startMaster();
63 TEST_UTIL.getMiniHBaseCluster().waitForActiveAndReadyMaster(60000);
64 LOG.info("started master...");
66 // check if master started successfully
67 assertTrue(TEST_UTIL.getMiniHBaseCluster().getMaster() != null);
69 // wait RSGroupBasedLoadBalancer online
70 RSGroupBasedLoadBalancer loadBalancer =
71 (RSGroupBasedLoadBalancer) TEST_UTIL.getMiniHBaseCluster().getMaster().getLoadBalancer();
72 long start = System.currentTimeMillis();
73 while (System.currentTimeMillis() - start <= 60000 && !loadBalancer.isOnline()) {
74 LOG.info("waiting for rsgroup load balancer onLine...");
75 sleep(200);
78 assertTrue(loadBalancer.isOnline());