HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestRSRpcServices.java
blob9a2456d207d8a8aa4b6a3260e539f3790c20503b
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.regionserver;
20 import static org.junit.Assert.assertEquals;
21 import java.net.InetAddress;
22 import java.net.UnknownHostException;
23 import java.util.Optional;
24 import org.apache.hadoop.hbase.HBaseClassTestRule;
25 import org.apache.hadoop.hbase.client.RegionInfoBuilder;
26 import org.apache.hadoop.hbase.ipc.RpcCall;
27 import org.apache.hadoop.hbase.ipc.RpcServer;
28 import org.apache.hadoop.hbase.testclassification.MediumTests;
29 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
30 import org.junit.ClassRule;
31 import org.junit.Test;
32 import org.junit.experimental.categories.Category;
33 import org.mockito.Mockito;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 /**
38 * Test parts of {@link RSRpcServices}
40 @Category({ RegionServerTests.class, MediumTests.class})
41 public class TestRSRpcServices {
42 @ClassRule
43 public static final HBaseClassTestRule CLASS_RULE =
44 HBaseClassTestRule.forClass(TestRSRpcServices.class);
46 private static final Logger LOG = LoggerFactory.getLogger(TestRSRpcServices.class);
48 /**
49 * Simple test of the toString on RegionScannerHolder works.
50 * Just creates one and calls #toString on it.
52 @Test
53 public void testRegionScannerHolderToString() throws UnknownHostException {
54 RpcCall call = Mockito.mock(RpcCall.class);
55 int port = 1234;
56 Mockito.when(call.getRemotePort()).thenReturn(port);
57 InetAddress address = InetAddress.getLocalHost();
58 Mockito.when(call.getRemoteAddress()).thenReturn(address);
59 Optional<String> userName = Optional.ofNullable("test");
60 Mockito.when(call.getRequestUserName()).thenReturn(userName);
61 RpcServer.setCurrentCall(call);
62 String clientIpAndPort = RSRpcServices.getRemoteClientIpAndPort();
63 String userNameTest = RSRpcServices.getUserName();
64 assertEquals("test", userNameTest);
65 HRegion region = Mockito.mock(HRegion.class);
66 Mockito.when(region.getRegionInfo()).thenReturn(RegionInfoBuilder.FIRST_META_REGIONINFO);
67 RSRpcServices.RegionScannerHolder rsh = new RSRpcServices.RegionScannerHolder(null, region,
68 null, null, false, false, clientIpAndPort,
69 userNameTest);
70 LOG.info("rsh: {}", rsh);