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.master.region; 019 020import static org.junit.Assert.assertSame; 021import static org.mockito.Mockito.mock; 022import static org.mockito.Mockito.when; 023 024import java.io.IOException; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.client.Put; 027import org.apache.hadoop.hbase.ipc.RpcCall; 028import org.apache.hadoop.hbase.ipc.RpcServer; 029import org.apache.hadoop.hbase.testclassification.MasterTests; 030import org.apache.hadoop.hbase.testclassification.MediumTests; 031import org.apache.hadoop.hbase.util.Bytes; 032import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; 033import org.junit.ClassRule; 034import org.junit.Test; 035import org.junit.experimental.categories.Category; 036 037/** 038 * Make sure that we will not get rpc timeout when updating master region. 039 */ 040@Category({ MasterTests.class, MediumTests.class }) 041public class TestMasterRegionRpcTimeout extends MasterRegionTestBase { 042 043 @ClassRule 044 public static final HBaseClassTestRule CLASS_RULE = 045 HBaseClassTestRule.forClass(TestMasterRegionRpcTimeout.class); 046 047 @Test 048 public void testRpcTimeout() throws IOException { 049 RpcCall call = mock(RpcCall.class); 050 // fake a RpcCall which is already timed out 051 when(call.getDeadline()).thenReturn(EnvironmentEdgeManager.currentTime() - 10000); 052 RpcServer.setCurrentCall(call); 053 // make sure that the update operation does not throw timeout exception 054 region.update( 055 r -> r.put(new Put(Bytes.toBytes("row")).addColumn(CF1, QUALIFIER, Bytes.toBytes("value")))); 056 assertSame(call, RpcServer.getCurrentCall().get()); 057 } 058}