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