View Javadoc

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  
19  package org.apache.hadoop.hbase.ipc;
20  
21  import org.apache.hadoop.conf.Configuration;
22  import org.apache.hadoop.hbase.net.Address;
23  import org.apache.hadoop.hbase.testclassification.MediumTests;
24  import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
25  import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
26  import org.junit.Assert;
27  import org.junit.Test;
28  import org.junit.experimental.categories.Category;
29  
30  @Category(MediumTests.class)   // Can't be small, we're playing with the EnvironmentEdge
31  public class TestHBaseClient {
32  
33    @Test
34    public void testFailedServer(){
35      ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
36      EnvironmentEdgeManager.injectEdge(  ee );
37      FailedServers fs = new FailedServers(new Configuration());
38      Throwable testThrowable = new Throwable();//throwable already tested in TestFailedServers.java
39  
40      Address ia = Address.fromParts("bad", 12);
41      Address ia2 = Address.fromParts("bad", 12);  // same server as ia
42      Address ia3 = Address.fromParts("badtoo", 12);
43      Address ia4 = Address.fromParts("badtoo", 13);
44  
45      Assert.assertFalse( fs.isFailedServer(ia) );
46  
47      fs.addToFailedServers(ia,testThrowable);
48      Assert.assertTrue( fs.isFailedServer(ia) );
49      Assert.assertTrue( fs.isFailedServer(ia2) );
50  
51      ee.incValue( 1 );
52      Assert.assertTrue( fs.isFailedServer(ia) );
53      Assert.assertTrue( fs.isFailedServer(ia2) );
54  
55      ee.incValue( RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
56      Assert.assertFalse( fs.isFailedServer(ia) );
57      Assert.assertFalse( fs.isFailedServer(ia2) );
58  
59      fs.addToFailedServers(ia,testThrowable);
60      fs.addToFailedServers(ia3,testThrowable);
61      fs.addToFailedServers(ia4,testThrowable);
62  
63      Assert.assertTrue( fs.isFailedServer(ia) );
64      Assert.assertTrue( fs.isFailedServer(ia2) );
65      Assert.assertTrue( fs.isFailedServer(ia3) );
66      Assert.assertTrue( fs.isFailedServer(ia4) );
67  
68      ee.incValue( RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
69      Assert.assertFalse( fs.isFailedServer(ia) );
70      Assert.assertFalse( fs.isFailedServer(ia2) );
71      Assert.assertFalse( fs.isFailedServer(ia3) );
72      Assert.assertFalse( fs.isFailedServer(ia4) );
73  
74  
75      fs.addToFailedServers(ia3,testThrowable);
76      Assert.assertFalse( fs.isFailedServer(ia4) );
77    }
78  }