HBASE-23949 refactor loadBalancer implements for rsgroup balance by table to achieve...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / AbstractTestCIRpcTimeout.java
blobaedb8148dd1b629d3e9be6061109c674f4aced62
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.client;
20 import static org.junit.Assert.fail;
22 import java.io.IOException;
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.hbase.HConstants;
25 import org.apache.hadoop.hbase.TableName;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 /**
32 * Based class for testing rpc timeout logic.
34 public abstract class AbstractTestCIRpcTimeout extends AbstractTestCITimeout {
36 private static final Logger LOG = LoggerFactory.getLogger(AbstractTestCIRpcTimeout.class);
38 private TableName tableName;
40 @Before
41 public void setUp() throws IOException {
42 tableName = TableName.valueOf(name.getMethodName());
43 TableDescriptor htd =
44 TableDescriptorBuilder.newBuilder(tableName).setCoprocessor(SleepCoprocessor.class.getName())
45 .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM_NAM)).build();
46 TEST_UTIL.getAdmin().createTable(htd);
49 protected abstract void execute(Table table) throws IOException;
51 @Test
52 public void testRpcTimeout() throws IOException {
53 Configuration c = new Configuration(TEST_UTIL.getConfiguration());
54 try (Table table = TEST_UTIL.getConnection().getTableBuilder(tableName, null)
55 .setRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
56 .setReadRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
57 .setWriteRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
58 .setOperationTimeout(SleepCoprocessor.SLEEP_TIME * 100).build()) {
59 execute(table);
60 fail("Get should not have succeeded");
61 } catch (RetriesExhaustedException e) {
62 LOG.info("We received an exception, as expected ", e);
65 // Again, with configuration based override
66 c.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
67 c.setInt(HConstants.HBASE_RPC_READ_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
68 c.setInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
69 c.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, SleepCoprocessor.SLEEP_TIME * 100);
70 try (Connection conn = ConnectionFactory.createConnection(c)) {
71 try (Table table = conn.getTable(tableName)) {
72 execute(table);
73 fail("Get should not have succeeded");
74 } catch (RetriesExhaustedException e) {
75 LOG.info("We received an exception, as expected ", e);