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
.mockito
.Mockito
.verify
;
22 import java
.io
.IOException
;
23 import org
.apache
.hadoop
.conf
.Configuration
;
24 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
25 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
26 import org
.apache
.hadoop
.hbase
.TableName
;
27 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
28 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
29 import org
.junit
.Before
;
30 import org
.junit
.BeforeClass
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.Test
;
33 import org
.junit
.experimental
.categories
.Category
;
34 import org
.mockito
.Mockito
;
36 import org
.apache
.hbase
.thirdparty
.com
.google
.protobuf
.RpcController
;
37 import org
.apache
.hbase
.thirdparty
.com
.google
.protobuf
.ServiceException
;
39 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.RequestConverter
;
40 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.ClientProtos
.Action
;
41 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.ClientProtos
.MultiRequest
;
42 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.ClientProtos
.RegionAction
;
43 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.HBaseProtos
;
46 * Tests logging of large batch commands via Multi. Tests are fast, but uses a mini-cluster (to test
47 * via "Multi" commands) so classified as MediumTests
49 @Category(MediumTests
.class)
50 public class TestMultiLogThreshold
{
53 public static final HBaseClassTestRule CLASS_RULE
=
54 HBaseClassTestRule
.forClass(TestMultiLogThreshold
.class);
56 private static RSRpcServices SERVICES
;
58 private static HBaseTestingUtility TEST_UTIL
;
59 private static Configuration CONF
;
60 private static final byte[] TEST_FAM
= Bytes
.toBytes("fam");
61 private static RSRpcServices
.LogDelegate LD
;
62 private static HRegionServer RS
;
63 private static int THRESHOLD
;
66 public static void setup() throws Exception
{
67 final TableName tableName
= TableName
.valueOf("tableName");
68 TEST_UTIL
= new HBaseTestingUtility();
69 CONF
= TEST_UTIL
.getConfiguration();
70 THRESHOLD
= CONF
.getInt(RSRpcServices
.BATCH_ROWS_THRESHOLD_NAME
,
71 RSRpcServices
.BATCH_ROWS_THRESHOLD_DEFAULT
);
72 TEST_UTIL
.startMiniCluster();
73 TEST_UTIL
.createTable(tableName
, TEST_FAM
);
74 RS
= TEST_UTIL
.getRSForFirstRegionInTable(tableName
);
78 public void setupTest() throws Exception
{
79 LD
= Mockito
.mock(RSRpcServices
.LogDelegate
.class);
80 SERVICES
= new RSRpcServices(RS
, LD
);
83 private enum ActionType
{
84 REGION_ACTIONS
, ACTIONS
88 * Sends a multi request with a certain amount of rows, will populate Multi command with either
89 * "rows" number of RegionActions with one Action each or one RegionAction with "rows" number of
92 private void sendMultiRequest(int rows
, ActionType actionType
) throws ServiceException
{
93 RpcController rpcc
= Mockito
.mock(RpcController
.class);
94 MultiRequest
.Builder builder
= MultiRequest
.newBuilder();
105 for (int i
= 0; i
< numRAs
; i
++) {
106 RegionAction
.Builder rab
= RegionAction
.newBuilder();
107 rab
.setRegion(RequestConverter
.buildRegionSpecifier(
108 HBaseProtos
.RegionSpecifier
.RegionSpecifierType
.REGION_NAME
,
109 Bytes
.toBytes("someStuff" + i
)));
110 for (int j
= 0; j
< numAs
; j
++) {
111 Action
.Builder ab
= Action
.newBuilder();
112 rab
.addAction(ab
.build());
114 builder
.addRegionAction(rab
.build());
117 SERVICES
.multi(rpcc
, builder
.build());
118 } catch (ClassCastException e
) {
119 // swallow expected exception due to mocked RpcController
124 public void testMultiLogThresholdRegionActions() throws ServiceException
, IOException
{
125 sendMultiRequest(THRESHOLD
+ 1, ActionType
.REGION_ACTIONS
);
126 verify(LD
, Mockito
.times(1)).logBatchWarning(Mockito
.anyString(), Mockito
.anyInt(), Mockito
.anyInt());
130 public void testMultiNoLogThresholdRegionActions() throws ServiceException
, IOException
{
131 sendMultiRequest(THRESHOLD
, ActionType
.REGION_ACTIONS
);
132 verify(LD
, Mockito
.never()).logBatchWarning(Mockito
.anyString(), Mockito
.anyInt(), Mockito
.anyInt());
136 public void testMultiLogThresholdActions() throws ServiceException
, IOException
{
137 sendMultiRequest(THRESHOLD
+ 1, ActionType
.ACTIONS
);
138 verify(LD
, Mockito
.times(1)).logBatchWarning(Mockito
.anyString(), Mockito
.anyInt(), Mockito
.anyInt());
142 public void testMultiNoLogThresholdAction() throws ServiceException
, IOException
{
143 sendMultiRequest(THRESHOLD
, ActionType
.ACTIONS
);
144 verify(LD
, Mockito
.never()).logBatchWarning(Mockito
.anyString(), Mockito
.anyInt(), Mockito
.anyInt());