1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase;
19
20 import static org.junit.Assert.*;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.master.HMaster;
26 import org.apache.zookeeper.KeeperException;
27
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31 @Category(MediumTests.class)
32 public class TestLocalHBaseCluster {
33 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
34
35
36
37
38
39
40
41
42 @Test
43 public void testLocalHBaseCluster() throws Exception {
44 TEST_UTIL.startMiniCluster(1, 1, null, MyHMaster.class, MyHRegionServer.class);
45
46 try {
47 int val = ((MyHMaster)TEST_UTIL.getHBaseCluster().getMaster(0)).echo(42);
48 assertEquals(42, val);
49 } catch (ClassCastException e) {
50 fail("Could not cast master to our class");
51 }
52
53 try {
54 int val = ((MyHRegionServer)TEST_UTIL.getHBaseCluster().getRegionServer(0)).echo(42);
55 assertEquals(42, val);
56 } catch (ClassCastException e) {
57 fail("Could not cast regionserver to our class");
58 }
59 TEST_UTIL.shutdownMiniCluster();
60 }
61
62
63
64
65
66 public static class MyHMaster extends HMaster {
67 public MyHMaster(Configuration conf) throws IOException, KeeperException,
68 InterruptedException {
69 super(conf);
70 }
71
72 public int echo(int val) {
73 return val;
74 }
75 }
76
77
78
79
80 public static class MyHRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer {
81
82 public MyHRegionServer(Configuration conf) throws IOException,
83 InterruptedException {
84 super(conf);
85 }
86
87 public int echo(int val) {
88 return val;
89 }
90 }
91 }