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
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
17   */
18  package org.apache.hadoop.hbase.master;
19  
20  import static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertTrue;
22  
23  import org.junit.Test;
24  
25  
26  public class TestDeadServer {
27    @Test public void testIsDead() {
28      DeadServer ds = new DeadServer(2);
29      final String hostname123 = "127.0.0.1,123,3";
30      assertFalse(ds.isDeadServer(hostname123, false));
31      assertFalse(ds.isDeadServer(hostname123, true));
32      ds.add(hostname123);
33      assertTrue(ds.isDeadServer(hostname123, false));
34      assertFalse(ds.isDeadServer("127.0.0.1:1", true));
35      assertFalse(ds.isDeadServer("127.0.0.1:1234", true));
36      assertTrue(ds.isDeadServer("127.0.0.1:123", true));
37      assertTrue(ds.areDeadServersInProgress());
38      ds.finish(hostname123);
39      assertFalse(ds.areDeadServersInProgress());
40      final String hostname1234 = "127.0.0.2,1234,4";
41      ds.add(hostname1234);
42      assertTrue(ds.isDeadServer(hostname123, false));
43      assertTrue(ds.isDeadServer(hostname1234, false));
44      assertTrue(ds.areDeadServersInProgress());
45      ds.finish(hostname1234);
46      assertFalse(ds.areDeadServersInProgress());
47      final String hostname12345 = "127.0.0.2,12345,4";
48      ds.add(hostname12345);
49      assertTrue(ds.isDeadServer(hostname1234, false));
50      assertTrue(ds.isDeadServer(hostname12345, false));
51      assertTrue(ds.areDeadServersInProgress());
52      ds.finish(hostname12345);
53      assertFalse(ds.areDeadServersInProgress());
54  
55      // Already dead =       127.0.0.1,9090,112321
56      // Coming back alive =  127.0.0.1,9090,223341
57  
58      final String deadServer = "127.0.0.1,9090,112321";
59      assertFalse(ds.cleanPreviousInstance(deadServer));
60      ds.add(deadServer);
61      assertTrue(ds.isDeadServer(deadServer));
62      final String deadServerHostComingAlive = "127.0.0.1,9090,112321";
63      assertTrue(ds.cleanPreviousInstance(deadServerHostComingAlive));
64      assertFalse(ds.isDeadServer(deadServer));
65      assertFalse(ds.cleanPreviousInstance(deadServerHostComingAlive));
66  
67    }
68  }