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 static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertTrue
;
23 import java
.io
.IOException
;
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
.ClientTests
;
28 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
29 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
30 import org
.junit
.AfterClass
;
31 import org
.junit
.BeforeClass
;
32 import org
.junit
.ClassRule
;
33 import org
.junit
.Test
;
34 import org
.junit
.experimental
.categories
.Category
;
37 * Testcase for HBASE-21032, where use the wrong readType from a Scan instance which is actually a
38 * get scan and cause returning only 1 cell per rpc call.
40 @Category({ ClientTests
.class, MediumTests
.class })
41 public class TestGetScanPartialResult
{
44 public static final HBaseClassTestRule CLASS_RULE
=
45 HBaseClassTestRule
.forClass(TestGetScanPartialResult
.class);
47 private final static HBaseTestingUtility TEST_UTIL
= new HBaseTestingUtility();
48 private static final TableName TABLE
= TableName
.valueOf("table");
49 private static final byte[] CF
= { 'c', 'f' };
50 private static final byte[] ROW
= { 'r', 'o', 'w' };
51 private static final int VALUE_SIZE
= 10000;
52 private static final int NUM_COLUMNS
= 300;
55 public static void setUp() throws Exception
{
56 TEST_UTIL
.startMiniCluster();
57 TEST_UTIL
.createTable(TABLE
, CF
);
61 public static void tearDown() throws Exception
{
62 TEST_UTIL
.shutdownMiniCluster();
65 private static byte[] makeLargeValue(int size
) {
66 byte[] v
= new byte[size
];
67 for (int i
= 0; i
< size
; i
++) {
74 public void test() throws IOException
{
75 try (Table t
= TEST_UTIL
.getConnection().getTable(TABLE
)) {
76 // populate a row with bunch of columns and large values
77 // to cause scan to return partials
78 byte[] val
= makeLargeValue(VALUE_SIZE
);
80 for (int i
= 0; i
< NUM_COLUMNS
; i
++) {
81 p
.addColumn(CF
, Bytes
.toBytes(Integer
.toString(i
)), val
);
85 Scan scan
= new Scan();
86 scan
.withStartRow(ROW
);
87 scan
.withStopRow(ROW
, true);
88 scan
.setAllowPartialResults(true);
89 scan
.setMaxResultSize(2L * 1024 * 1024);
91 ResultScanner scanner
= t
.getScanner(scan
);
95 for (Result result
= scanner
.next(); (result
!= null); result
= scanner
.next()) {
97 nCells
+= result
.listCells().size();
99 assertEquals(NUM_COLUMNS
, nCells
);
100 assertTrue(nResults
< 5);