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