1   /**
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.master;
21  
22  import static org.junit.Assert.assertEquals;
23  
24  import java.io.IOException;
25  
26  import org.apache.hadoop.hbase.HBaseTestingUtility;
27  import org.apache.hadoop.hbase.HServerAddress;
28  import org.apache.hadoop.hbase.HServerInfo;
29  import org.apache.hadoop.hbase.MiniHBaseCluster;
30  import org.apache.hadoop.hbase.YouAreDeadException;
31  import org.apache.hadoop.hbase.MiniHBaseCluster.MiniHBaseClusterRegionServer;
32  import org.junit.AfterClass;
33  import org.junit.Before;
34  import org.junit.BeforeClass;
35  import org.junit.Ignore;
36  import org.junit.Test;
37  
38  public class BROKE_FIX_TestKillingServersFromMaster {
39    private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
40    private static MiniHBaseCluster cluster;
41  
42    @BeforeClass
43    public static void beforeAllTests() throws Exception {
44      TEST_UTIL.startMiniCluster(2);
45      cluster = TEST_UTIL.getHBaseCluster();
46    }
47  
48    @AfterClass
49    public static void afterAllTests() throws IOException {
50      TEST_UTIL.shutdownMiniCluster();
51    }
52  
53    @Before
54    public void setup() throws IOException {
55      TEST_UTIL.ensureSomeRegionServersAvailable(2);
56    }
57  
58    /**
59     * Test that a region server that reports with the wrong start code
60     * gets shut down
61     * See HBASE-2613
62     * @throws Exception
63     */
64    @Ignore @Test (timeout=180000)
65    public void testRsReportsWrongStartCode() throws Exception {
66      MiniHBaseClusterRegionServer firstServer =
67        (MiniHBaseClusterRegionServer)cluster.getRegionServer(0);
68      HServerInfo hsi = firstServer.getServerInfo();
69      // This constructor creates a new startcode
70      firstServer.setHServerInfo(new HServerInfo(hsi.getServerAddress(),
71        hsi.getInfoPort(), hsi.getHostname()));
72      cluster.waitOnRegionServer(0);
73      assertEquals(1, cluster.getLiveRegionServerThreads().size());
74    }
75  
76    /**
77     * Test that a region server that reports with the wrong address
78     * gets shut down
79     * See HBASE-2613
80     * @throws Exception
81     */
82    @Ignore @Test (timeout=180000)
83    public void testRsReportsWrongAddress() throws Exception {
84      MiniHBaseClusterRegionServer firstServer =
85        (MiniHBaseClusterRegionServer)cluster.getRegionServer(0);
86      firstServer.getHServerInfo().setServerAddress(
87        new HServerAddress("0.0.0.0", 60010));
88      cluster.waitOnRegionServer(0);
89      assertEquals(1, cluster.getLiveRegionServerThreads().size());
90    }
91  
92    /**
93     * Send a YouAreDeadException to the region server and expect it to shut down
94     * See HBASE-2691
95     * @throws Exception
96     */
97    @Ignore @Test (timeout=180000)
98    public void testSendYouAreDead() throws Exception {
99      cluster.addExceptionToSendRegionServer(0, new YouAreDeadException("bam!"));
100     cluster.waitOnRegionServer(0);
101     assertEquals(1, cluster.getLiveRegionServerThreads().size());
102   }
103 }