HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestCISleep.java
blob1c8480931ef354b08c52e55a5f6e47393bd5a7de
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 org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HConstants;
25 import org.apache.hadoop.hbase.TableName;
26 import org.apache.hadoop.hbase.testclassification.ClientTests;
27 import org.apache.hadoop.hbase.testclassification.MediumTests;
28 import org.junit.Before;
29 import org.junit.ClassRule;
30 import org.junit.Test;
31 import org.junit.experimental.categories.Category;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 @Category({ ClientTests.class, MediumTests.class })
36 public class TestCISleep extends AbstractTestCITimeout {
38 @ClassRule
39 public static final HBaseClassTestRule CLASS_RULE =
40 HBaseClassTestRule.forClass(TestCISleep.class);
42 private static Logger LOG = LoggerFactory.getLogger(TestCISleep.class);
44 private TableName tableName;
46 @Before
47 public void setUp() {
48 tableName = TableName.valueOf(name.getMethodName());
51 /**
52 * Test starting from 0 index when RpcRetryingCaller calculate the backoff time.
54 @Test
55 public void testRpcRetryingCallerSleep() throws Exception {
56 TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
57 .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM_NAM))
58 .setCoprocessor(CoprocessorDescriptorBuilder.newBuilder(SleepAndFailFirstTime.class.getName())
59 .setProperty(SleepAndFailFirstTime.SLEEP_TIME_CONF_KEY, String.valueOf(2000))
60 .build())
61 .build();
62 TEST_UTIL.getAdmin().createTable(htd);
64 Configuration c = new Configuration(TEST_UTIL.getConfiguration());
65 c.setInt(HConstants.HBASE_CLIENT_PAUSE, 3000);
66 c.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 4000);
68 try (Connection conn = ConnectionFactory.createConnection(c)) {
69 SleepAndFailFirstTime.ct.set(0);
70 try (Table table = conn.getTableBuilder(tableName, null).setOperationTimeout(8000).build()) {
71 // Check that it works. Because 2s + 3s * RETRY_BACKOFF[0] + 2s < 8s
72 table.get(new Get(FAM_NAM));
74 SleepAndFailFirstTime.ct.set(0);
75 try (Table table = conn.getTableBuilder(tableName, null).setOperationTimeout(6000).build()) {
76 // Will fail this time. After sleep, there are not enough time for second retry
77 // Beacuse 2s + 3s + 2s > 6s
78 table.get(new Get(FAM_NAM));
79 fail("We expect an exception here");
80 } catch (RetriesExhaustedException e) {
81 LOG.info("We received an exception, as expected ", e);