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