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 java
.net
.SocketTimeoutException
;
24 import org
.apache
.hadoop
.hbase
.TableName
;
25 import org
.junit
.Before
;
26 import org
.junit
.Test
;
27 import org
.slf4j
.Logger
;
28 import org
.slf4j
.LoggerFactory
;
31 * Based class for testing operation timeout logic.
33 public abstract class AbstractTestCIOperationTimeout
extends AbstractTestCITimeout
{
35 private static final Logger LOG
= LoggerFactory
.getLogger(AbstractTestCIOperationTimeout
.class);
37 private TableName tableName
;
40 public void setUp() throws IOException
{
41 tableName
= TableName
.valueOf(name
.getMethodName());
42 TableDescriptor htd
= TableDescriptorBuilder
.newBuilder(tableName
)
43 .setCoprocessor(SleepAndFailFirstTime
.class.getName())
44 .setColumnFamily(ColumnFamilyDescriptorBuilder
.of(FAM_NAM
)).build();
45 TEST_UTIL
.getAdmin().createTable(htd
);
48 protected abstract void execute(Table table
) throws IOException
;
51 * Test that an operation can fail if we read the global operation timeout, even if the individual
52 * timeout is fine. We do that with:
54 * <li>client side: an operation timeout of 30 seconds</li>
55 * <li>server side: we sleep 20 second at each attempt. The first work fails, the second one
56 * succeeds. But the client won't wait that much, because 20 + 20 > 30, so the client timed out
57 * when the server answers.</li>
61 public void testOperationTimeout() throws IOException
{
62 TableBuilder builder
=
63 TEST_UTIL
.getConnection().getTableBuilder(tableName
, null).setRpcTimeout(Integer
.MAX_VALUE
)
64 .setReadRpcTimeout(Integer
.MAX_VALUE
).setWriteRpcTimeout(Integer
.MAX_VALUE
);
65 // Check that it works if the timeout is big enough
66 SleepAndFailFirstTime
.ct
.set(0);
67 try (Table table
= builder
.setOperationTimeout(120 * 1000).build()) {
70 // Resetting and retrying. Will fail this time, not enough time for the second try
71 SleepAndFailFirstTime
.ct
.set(0);
72 try (Table table
= builder
.setOperationTimeout(30 * 1000).build()) {
73 SleepAndFailFirstTime
.ct
.set(0);
75 fail("We expect an exception here");
76 } catch (SocketTimeoutException
| RetriesExhaustedException e
) {
77 // The client has a CallTimeout class, but it's not shared. We're not very clean today,
78 // in the general case you can expect the call to stop, but the exception may vary.
79 // In this test however, we're sure that it will be a socket timeout.
80 LOG
.info("We received an exception, as expected ", e
);