1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.master;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.IOException;
26
27 import org.apache.hadoop.hbase.HBaseTestingUtility;
28 import org.apache.hadoop.hbase.HServerAddress;
29 import org.apache.hadoop.hbase.HServerInfo;
30 import org.apache.hadoop.hbase.MiniHBaseCluster;
31 import org.apache.hadoop.hbase.MiniHBaseCluster.MiniHBaseClusterRegionServer;
32 import org.apache.hadoop.hbase.YouAreDeadException;
33 import org.apache.hadoop.hbase.regionserver.HRegionServer;
34 import org.junit.AfterClass;
35 import org.junit.Before;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38
39 public class TestKillingServersFromMaster {
40 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
41 private static MiniHBaseCluster cluster;
42
43 @BeforeClass
44 public static void beforeAllTests() throws Exception {
45 TEST_UTIL.startMiniCluster(2);
46 cluster = TEST_UTIL.getHBaseCluster();
47 }
48
49 @AfterClass
50 public static void afterAllTests() throws IOException {
51 TEST_UTIL.shutdownMiniCluster();
52 }
53
54 @Before
55 public void setup() throws IOException {
56 TEST_UTIL.ensureSomeRegionServersAvailable(2);
57 }
58
59
60
61
62
63
64
65 @Test (timeout=180000)
66 public void testRsReportsWrongStartCode() throws Exception {
67 MiniHBaseClusterRegionServer firstServer =
68 (MiniHBaseClusterRegionServer)cluster.getRegionServer(0);
69 HServerInfo hsi = firstServer.getServerInfo();
70
71 firstServer.setHServerInfo(new HServerInfo(hsi.getServerAddress(),
72 hsi.getInfoPort(), hsi.getHostname()));
73 cluster.waitOnRegionServer(0);
74 assertEquals(1, cluster.getLiveRegionServerThreads().size());
75 }
76
77
78
79
80
81
82
83 @Test (timeout=180000)
84 public void testRsReportsWrongAddress() throws Exception {
85 MiniHBaseClusterRegionServer firstServer =
86 (MiniHBaseClusterRegionServer)cluster.getRegionServer(0);
87 firstServer.getHServerInfo().setServerAddress(
88 new HServerAddress("0.0.0.0", 60010));
89 cluster.waitOnRegionServer(0);
90 assertEquals(1, cluster.getLiveRegionServerThreads().size());
91 }
92
93
94
95
96
97
98 @Test (timeout=180000)
99 public void testSendYouAreDead() throws Exception {
100 cluster.addExceptionToSendRegionServer(0, new YouAreDeadException("bam!"));
101 cluster.waitOnRegionServer(0);
102 assertEquals(1, cluster.getLiveRegionServerThreads().size());
103 }
104 }