HBASE-23949 refactor loadBalancer implements for rsgroup balance by table to achieve...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / ipc / TestHBaseClient.java
blobad4741ccf8af4cd485c98c044f024dfa7a1d20b9
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.hadoop.hbase.ipc;
20 import java.net.InetSocketAddress;
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.hbase.HBaseClassTestRule;
23 import org.apache.hadoop.hbase.testclassification.RPCTests;
24 import org.apache.hadoop.hbase.testclassification.SmallTests;
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.ClassRule;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
32 @Category({RPCTests.class, SmallTests.class})
33 public class TestHBaseClient {
34 @ClassRule
35 public static final HBaseClassTestRule CLASS_RULE =
36 HBaseClassTestRule.forClass(TestHBaseClient.class);
38 @Test
39 public void testFailedServer(){
40 ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
41 EnvironmentEdgeManager.injectEdge(ee);
42 FailedServers fs = new FailedServers(new Configuration());
43 Throwable testThrowable = new Throwable();//throwable already tested in TestFailedServers.java
45 InetSocketAddress ia = InetSocketAddress.createUnresolved("bad", 12);
46 // same server as ia
47 InetSocketAddress ia2 = InetSocketAddress.createUnresolved("bad", 12);
48 InetSocketAddress ia3 = InetSocketAddress.createUnresolved("badtoo", 12);
49 InetSocketAddress ia4 = InetSocketAddress.createUnresolved("badtoo", 13);
52 Assert.assertFalse(fs.isFailedServer(ia));
54 fs.addToFailedServers(ia,testThrowable);
55 Assert.assertTrue(fs.isFailedServer(ia));
56 Assert.assertTrue(fs.isFailedServer(ia2));
58 ee.incValue(1);
59 Assert.assertTrue(fs.isFailedServer(ia));
60 Assert.assertTrue(fs.isFailedServer(ia2));
62 ee.incValue(RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1);
63 Assert.assertFalse(fs.isFailedServer(ia));
64 Assert.assertFalse(fs.isFailedServer(ia2));
66 fs.addToFailedServers(ia,testThrowable);
67 fs.addToFailedServers(ia3,testThrowable);
68 fs.addToFailedServers(ia4,testThrowable);
70 Assert.assertTrue(fs.isFailedServer(ia));
71 Assert.assertTrue(fs.isFailedServer(ia2));
72 Assert.assertTrue(fs.isFailedServer(ia3));
73 Assert.assertTrue(fs.isFailedServer(ia4));
75 ee.incValue(RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1);
76 Assert.assertFalse(fs.isFailedServer(ia));
77 Assert.assertFalse(fs.isFailedServer(ia2));
78 Assert.assertFalse(fs.isFailedServer(ia3));
79 Assert.assertFalse(fs.isFailedServer(ia4));
82 fs.addToFailedServers(ia3,testThrowable);
83 Assert.assertFalse(fs.isFailedServer(ia4));