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