HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / TestLocalHBaseCluster.java
blob7e9e7cb7af6fd185b340e84d68802625ae536bd1
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;
20 import static org.junit.Assert.*;
22 import java.io.IOException;
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.hbase.master.HMaster;
25 import org.apache.hadoop.hbase.testclassification.MediumTests;
26 import org.apache.hadoop.hbase.testclassification.MiscTests;
27 import org.apache.zookeeper.KeeperException;
28 import org.junit.ClassRule;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
32 @Category({MiscTests.class, MediumTests.class})
33 public class TestLocalHBaseCluster {
35 @ClassRule
36 public static final HBaseClassTestRule CLASS_RULE =
37 HBaseClassTestRule.forClass(TestLocalHBaseCluster.class);
39 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
41 /**
42 * Check that we can start a local HBase cluster specifying a custom master
43 * and regionserver class and then cast back to those classes; also that
44 * the cluster will launch and terminate cleanly. See HBASE-6011. Uses the
45 * HBaseTestingUtility facilities for creating a LocalHBaseCluster with
46 * custom master and regionserver classes.
48 @Test
49 public void testLocalHBaseCluster() throws Exception {
50 // Set Master class and RegionServer class, and use default values for other options.
51 StartMiniClusterOption option = StartMiniClusterOption.builder()
52 .masterClass(MyHMaster.class).rsClass(MyHRegionServer.class).build();
53 TEST_UTIL.startMiniCluster(option);
54 // Can we cast back to our master class?
55 try {
56 int val = ((MyHMaster)TEST_UTIL.getHBaseCluster().getMaster(0)).echo(42);
57 assertEquals(42, val);
58 } catch (ClassCastException e) {
59 fail("Could not cast master to our class");
61 // Can we cast back to our regionserver class?
62 try {
63 int val = ((MyHRegionServer)TEST_UTIL.getHBaseCluster().getRegionServer(0)).echo(42);
64 assertEquals(42, val);
65 } catch (ClassCastException e) {
66 fail("Could not cast regionserver to our class");
68 TEST_UTIL.shutdownMiniCluster();
71 /**
72 * A private master class similar to that used by HMasterCommandLine when
73 * running in local mode.
75 public static class MyHMaster extends HMaster {
76 public MyHMaster(Configuration conf) throws IOException, KeeperException,
77 InterruptedException {
78 super(conf);
81 public int echo(int val) {
82 return val;
86 /**
87 * A private regionserver class with a dummy method for testing casts
89 public static class MyHRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer {
91 public MyHRegionServer(Configuration conf) throws IOException, InterruptedException {
92 super(conf);
95 public int echo(int val) {
96 return val;