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