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.apache.hadoop.hbase.MediumTests;
24  import org.apache.hadoop.hbase.ServerName;
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  @Category(MediumTests.class)
29  public class TestDeadServer {
30    @Test public void testIsDead() {
31      DeadServer ds = new DeadServer();
32      final ServerName hostname123 = new ServerName("127.0.0.1", 123, 3L);
33      ds.add(hostname123);
34      assertTrue(ds.areDeadServersInProgress());
35      ds.finish(hostname123);
36      assertFalse(ds.areDeadServersInProgress());
37      final ServerName hostname1234 = new ServerName("127.0.0.2", 1234, 4L);
38      ds.add(hostname1234);
39      assertTrue(ds.areDeadServersInProgress());
40      ds.finish(hostname1234);
41      assertFalse(ds.areDeadServersInProgress());
42      final ServerName hostname12345 = new ServerName("127.0.0.2", 12345, 4L);
43      ds.add(hostname12345);
44      assertTrue(ds.areDeadServersInProgress());
45      ds.finish(hostname12345);
46      assertFalse(ds.areDeadServersInProgress());
47  
48      // Already dead =       127.0.0.1,9090,112321
49      // Coming back alive =  127.0.0.1,9090,223341
50  
51      final ServerName deadServer = new ServerName("127.0.0.1", 9090, 112321L);
52      assertFalse(ds.cleanPreviousInstance(deadServer));
53      ds.add(deadServer);
54      assertTrue(ds.isDeadServer(deadServer));
55      final ServerName deadServerHostComingAlive =
56        new ServerName("127.0.0.1", 9090, 112321L);
57      assertTrue(ds.cleanPreviousInstance(deadServerHostComingAlive));
58      assertFalse(ds.isDeadServer(deadServer));
59      assertFalse(ds.cleanPreviousInstance(deadServerHostComingAlive));
60    }
61  
62    @org.junit.Rule
63    public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
64      new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
65  }
66