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 org
.apache
.hadoop
.conf
.Configuration
;
21 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
22 import org
.apache
.hadoop
.hbase
.HRegionLocation
;
23 import org
.apache
.hadoop
.hbase
.RegionLocations
;
24 import org
.apache
.hadoop
.hbase
.ServerName
;
25 import org
.apache
.hadoop
.hbase
.TableName
;
26 import org
.apache
.hadoop
.hbase
.ipc
.RpcControllerFactory
;
27 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
28 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
29 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
30 import org
.junit
.Before
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.Test
;
33 import org
.junit
.experimental
.categories
.Category
;
34 import org
.junit
.runner
.RunWith
;
35 import org
.mockito
.Mock
;
36 import org
.mockito
.Mockito
;
37 import org
.mockito
.runners
.MockitoJUnitRunner
;
39 @RunWith(MockitoJUnitRunner
.class)
40 @Category({ ClientTests
.class, SmallTests
.class })
41 public class TestReversedScannerCallable
{
44 public static final HBaseClassTestRule CLASS_RULE
=
45 HBaseClassTestRule
.forClass(TestReversedScannerCallable
.class);
48 private ConnectionImplementation connection
;
52 private RpcControllerFactory rpcFactory
;
54 private RegionLocations regionLocations
;
56 private final byte[] ROW
= Bytes
.toBytes("row1");
59 public void setUp() throws Exception
{
60 HRegionLocation regionLocation
= Mockito
.mock(HRegionLocation
.class);
61 ServerName serverName
= Mockito
.mock(ServerName
.class);
63 Mockito
.when(connection
.getConfiguration()).thenReturn(new Configuration());
64 Mockito
.when(regionLocations
.size()).thenReturn(1);
65 Mockito
.when(regionLocations
.getRegionLocation(0)).thenReturn(regionLocation
);
66 Mockito
.when(regionLocation
.getHostname()).thenReturn("localhost");
67 Mockito
.when(regionLocation
.getServerName()).thenReturn(serverName
);
68 Mockito
.when(scan
.includeStartRow()).thenReturn(true);
69 Mockito
.when(scan
.getStartRow()).thenReturn(ROW
);
73 public void testPrepareDoesNotUseCache() throws Exception
{
74 TableName tableName
= TableName
.valueOf("MyTable");
75 Mockito
.when(connection
.relocateRegion(tableName
, ROW
, 0)).thenReturn(regionLocations
);
77 ReversedScannerCallable callable
=
78 new ReversedScannerCallable(connection
, tableName
, scan
, null, rpcFactory
);
79 callable
.prepare(true);
81 Mockito
.verify(connection
).relocateRegion(tableName
, ROW
, 0);
85 public void testPrepareUsesCache() throws Exception
{
86 TableName tableName
= TableName
.valueOf("MyTable");
87 Mockito
.when(connection
.locateRegion(tableName
, ROW
, true, true, 0))
88 .thenReturn(regionLocations
);
90 ReversedScannerCallable callable
=
91 new ReversedScannerCallable(connection
, tableName
, scan
, null, rpcFactory
);
92 callable
.prepare(false);
94 Mockito
.verify(connection
).locateRegion(tableName
, ROW
, true, true, 0);