001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.ipc;
019
020import static org.junit.jupiter.api.Assertions.assertFalse;
021import static org.junit.jupiter.api.Assertions.assertTrue;
022
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.net.Address;
025import org.apache.hadoop.hbase.testclassification.RPCTests;
026import org.apache.hadoop.hbase.testclassification.SmallTests;
027import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
028import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
029import org.junit.jupiter.api.Tag;
030import org.junit.jupiter.api.Test;
031
032@Tag(RPCTests.TAG)
033@Tag(SmallTests.TAG)
034public class TestHBaseClient {
035  @Test
036  public void testFailedServer() {
037    ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
038    EnvironmentEdgeManager.injectEdge(ee);
039    FailedServers fs = new FailedServers(new Configuration());
040    Throwable testThrowable = new Throwable();// throwable already tested in TestFailedServers.java
041
042    Address ia = Address.fromParts("bad", 12);
043    // same server as ia
044    Address ia2 = Address.fromParts("bad", 12);
045    Address ia3 = Address.fromParts("badtoo", 12);
046    Address ia4 = Address.fromParts("badtoo", 13);
047
048    assertFalse(fs.isFailedServer(ia));
049
050    fs.addToFailedServers(ia, testThrowable);
051    assertTrue(fs.isFailedServer(ia));
052    assertTrue(fs.isFailedServer(ia2));
053
054    ee.incValue(1);
055    assertTrue(fs.isFailedServer(ia));
056    assertTrue(fs.isFailedServer(ia2));
057
058    ee.incValue(RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1);
059    assertFalse(fs.isFailedServer(ia));
060    assertFalse(fs.isFailedServer(ia2));
061
062    fs.addToFailedServers(ia, testThrowable);
063    fs.addToFailedServers(ia3, testThrowable);
064    fs.addToFailedServers(ia4, testThrowable);
065
066    assertTrue(fs.isFailedServer(ia));
067    assertTrue(fs.isFailedServer(ia2));
068    assertTrue(fs.isFailedServer(ia3));
069    assertTrue(fs.isFailedServer(ia4));
070
071    ee.incValue(RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1);
072    assertFalse(fs.isFailedServer(ia));
073    assertFalse(fs.isFailedServer(ia2));
074    assertFalse(fs.isFailedServer(ia3));
075    assertFalse(fs.isFailedServer(ia4));
076
077    fs.addToFailedServers(ia3, testThrowable);
078    assertFalse(fs.isFailedServer(ia4));
079  }
080}