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      // hostname123 should now be evicted
50      assertFalse(ds.isDeadServer(hostname123, false));
51      // but others should still be dead
52      assertTrue(ds.isDeadServer(hostname1234, false));
53      assertTrue(ds.isDeadServer(hostname12345, false));
54      assertTrue(ds.areDeadServersInProgress());
55      ds.finish(hostname12345);
56      assertFalse(ds.areDeadServersInProgress());
57    }
58  }