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.client;
019
020import static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertTrue;
022
023import java.util.concurrent.TimeUnit;
024import org.apache.hadoop.conf.Configuration;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.HBaseConfiguration;
027import org.apache.hadoop.hbase.HConstants;
028import org.apache.hadoop.hbase.testclassification.ClientTests;
029import org.apache.hadoop.hbase.testclassification.SmallTests;
030import org.junit.ClassRule;
031import org.junit.Test;
032import org.junit.experimental.categories.Category;
033
034/**
035 * See HBASE-24513.
036 */
037@Category({ ClientTests.class, SmallTests.class })
038public class TestAsyncConnectionConfiguration {
039
040  @ClassRule
041  public static final HBaseClassTestRule CLASS_RULE =
042    HBaseClassTestRule.forClass(TestAsyncConnectionConfiguration.class);
043
044  @Test
045  public void itHandlesDeprecatedPauseForCQTBE() {
046    Configuration conf = new Configuration();
047    long timeoutMs = 1000;
048    conf.setLong(HConstants.HBASE_CLIENT_PAUSE_FOR_CQTBE, timeoutMs);
049    AsyncConnectionConfiguration config = new AsyncConnectionConfiguration(conf);
050
051    assertTrue(Configuration.isDeprecated(HConstants.HBASE_CLIENT_PAUSE_FOR_CQTBE));
052    long expected = TimeUnit.MILLISECONDS.toNanos(timeoutMs);
053    assertEquals(expected, config.getPauseNsForServerOverloaded());
054
055    conf = new Configuration();
056    conf.setLong(AsyncConnectionConfiguration.HBASE_CLIENT_PAUSE_FOR_SERVER_OVERLOADED, timeoutMs);
057    config = new AsyncConnectionConfiguration(conf);
058    assertEquals(expected, config.getPauseNsForServerOverloaded());
059  }
060
061  @Test
062  public void testDefaultReadWriteRpcTimeout() {
063    Configuration conf = HBaseConfiguration.create();
064    long timeoutMs = 1000;
065    conf.setLong(HConstants.HBASE_RPC_TIMEOUT_KEY, timeoutMs);
066    AsyncConnectionConfiguration config = new AsyncConnectionConfiguration(conf);
067    long expected = TimeUnit.MILLISECONDS.toNanos(timeoutMs);
068    assertEquals(expected, config.getRpcTimeoutNs());
069    assertEquals(expected, config.getReadRpcTimeoutNs());
070    assertEquals(expected, config.getWriteRpcTimeoutNs());
071  }
072}