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.hadoop.hbase.testclassification.MediumTests;
27 import org.apache.zookeeper.KeeperException;
28
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32 @Category(MediumTests.class)
33 public class TestLocalHBaseCluster {
34 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
35
36
37
38
39
40
41
42
43 @Test
44 public void testLocalHBaseCluster() throws Exception {
45 TEST_UTIL.startMiniCluster(1, 1, null, MyHMaster.class, MyHRegionServer.class);
46
47 try {
48 int val = ((MyHMaster)TEST_UTIL.getHBaseCluster().getMaster(0)).echo(42);
49 assertEquals(42, val);
50 } catch (ClassCastException e) {
51 fail("Could not cast master to our class");
52 }
53
54 try {
55 int val = ((MyHRegionServer)TEST_UTIL.getHBaseCluster().getRegionServer(0)).echo(42);
56 assertEquals(42, val);
57 } catch (ClassCastException e) {
58 fail("Could not cast regionserver to our class");
59 }
60 TEST_UTIL.shutdownMiniCluster();
61 }
62
63
64
65
66
67 public static class MyHMaster extends HMaster {
68 public MyHMaster(Configuration conf, CoordinatedStateManager cp)
69 throws IOException, KeeperException,
70 InterruptedException {
71 super(conf, cp);
72 }
73
74 public int echo(int val) {
75 return val;
76 }
77 }
78
79
80
81
82 public static class MyHRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer {
83
84 public MyHRegionServer(Configuration conf, CoordinatedStateManager cp) throws IOException,
85 InterruptedException {
86 super(conf, cp);
87 }
88
89 public int echo(int val) {
90 return val;
91 }
92 }
93 }