1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.hadoop.hbase.client;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.hadoop.hbase.Cell;
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.HColumnDescriptor;
25 import org.apache.hadoop.hbase.HRegionInfo;
26 import org.apache.hadoop.hbase.HTableDescriptor;
27 import org.apache.hadoop.hbase.HTestConst;
28 import org.apache.hadoop.hbase.KeyValue;
29 import org.apache.hadoop.hbase.testclassification.SmallTests;
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.regionserver.HRegion;
32 import org.apache.hadoop.hbase.regionserver.RegionScanner;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36
37
38
39 @Category(SmallTests.class)
40 public class TestIntraRowPagination {
41
42 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
43
44
45
46
47
48
49 @Test
50 public void testScanLimitAndOffset() throws Exception {
51
52 byte [][] ROWS = HTestConst.makeNAscii(HTestConst.DEFAULT_ROW_BYTES, 2);
53 byte [][] FAMILIES = HTestConst.makeNAscii(HTestConst.DEFAULT_CF_BYTES, 3);
54 byte [][] QUALIFIERS = HTestConst.makeNAscii(HTestConst.DEFAULT_QUALIFIER_BYTES, 10);
55
56 HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(HTestConst.DEFAULT_TABLE_BYTES));
57 HRegionInfo info = new HRegionInfo(HTestConst.DEFAULT_TABLE, null, null, false);
58 for (byte[] family : FAMILIES) {
59 HColumnDescriptor hcd = new HColumnDescriptor(family);
60 htd.addFamily(hcd);
61 }
62 HRegion region =
63 HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(), htd);
64 try {
65 Put put;
66 Scan scan;
67 Result result;
68 boolean toLog = true;
69
70 List<Cell> kvListExp = new ArrayList<Cell>();
71
72 int storeOffset = 1;
73 int storeLimit = 3;
74 for (int r = 0; r < ROWS.length; r++) {
75 put = new Put(ROWS[r]);
76 for (int c = 0; c < FAMILIES.length; c++) {
77 for (int q = 0; q < QUALIFIERS.length; q++) {
78 KeyValue kv = new KeyValue(ROWS[r], FAMILIES[c], QUALIFIERS[q], 1,
79 HTestConst.DEFAULT_VALUE_BYTES);
80 put.add(kv);
81 if (storeOffset <= q && q < storeOffset + storeLimit) {
82 kvListExp.add(kv);
83 }
84 }
85 }
86 region.put(put);
87 }
88
89 scan = new Scan();
90 scan.setRowOffsetPerColumnFamily(storeOffset);
91 scan.setMaxResultsPerColumnFamily(storeLimit);
92 RegionScanner scanner = region.getScanner(scan);
93 List<Cell> kvListScan = new ArrayList<Cell>();
94 List<Cell> results = new ArrayList<Cell>();
95 while (scanner.next(results) || !results.isEmpty()) {
96 kvListScan.addAll(results);
97 results.clear();
98 }
99 result = Result.create(kvListScan);
100 TestScannersFromClientSide.verifyResult(result, kvListExp, toLog,
101 "Testing scan with storeOffset and storeLimit");
102 } finally {
103 region.close();
104 }
105 }
106
107 }