HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestIntraRowPagination.java
blobb4533c569db67fc720a3cf0e6dda23641c0f552b
1 /**
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 java.util.ArrayList;
21 import java.util.List;
22 import org.apache.hadoop.hbase.Cell;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HBaseTestingUtility;
25 import org.apache.hadoop.hbase.HRegionInfo;
26 import org.apache.hadoop.hbase.HTestConst;
27 import org.apache.hadoop.hbase.KeyValue;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.regionserver.HRegion;
30 import org.apache.hadoop.hbase.regionserver.RegionScanner;
31 import org.apache.hadoop.hbase.testclassification.ClientTests;
32 import org.apache.hadoop.hbase.testclassification.SmallTests;
33 import org.junit.ClassRule;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
37 /**
38 * Test scan/get offset and limit settings within one row through HRegion API.
40 @Category({SmallTests.class, ClientTests.class})
41 public class TestIntraRowPagination {
43 @ClassRule
44 public static final HBaseClassTestRule CLASS_RULE =
45 HBaseClassTestRule.forClass(TestIntraRowPagination.class);
47 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
49 /**
50 * Test from client side for scan with maxResultPerCF set
52 * @throws Exception
54 @Test
55 public void testScanLimitAndOffset() throws Exception {
56 //byte [] TABLE = HTestConst.DEFAULT_TABLE_BYTES;
57 byte [][] ROWS = HTestConst.makeNAscii(HTestConst.DEFAULT_ROW_BYTES, 2);
58 byte [][] FAMILIES = HTestConst.makeNAscii(HTestConst.DEFAULT_CF_BYTES, 3);
59 byte [][] QUALIFIERS = HTestConst.makeNAscii(HTestConst.DEFAULT_QUALIFIER_BYTES, 10);
61 TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
62 new TableDescriptorBuilder.ModifyableTableDescriptor(
63 TableName.valueOf(HTestConst.DEFAULT_TABLE_BYTES));
65 HRegionInfo info = new HRegionInfo(HTestConst.DEFAULT_TABLE, null, null, false);
66 for (byte[] family : FAMILIES) {
67 ColumnFamilyDescriptor familyDescriptor =
68 new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
69 tableDescriptor.setColumnFamily(familyDescriptor);
71 HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
72 TEST_UTIL.getConfiguration(), tableDescriptor);
73 try {
74 Put put;
75 Scan scan;
76 Result result;
77 boolean toLog = true;
79 List<Cell> kvListExp = new ArrayList<>();
81 int storeOffset = 1;
82 int storeLimit = 3;
83 for (int r = 0; r < ROWS.length; r++) {
84 put = new Put(ROWS[r]);
85 for (int c = 0; c < FAMILIES.length; c++) {
86 for (int q = 0; q < QUALIFIERS.length; q++) {
87 KeyValue kv = new KeyValue(ROWS[r], FAMILIES[c], QUALIFIERS[q], 1,
88 HTestConst.DEFAULT_VALUE_BYTES);
89 put.add(kv);
90 if (storeOffset <= q && q < storeOffset + storeLimit) {
91 kvListExp.add(kv);
95 region.put(put);
98 scan = new Scan();
99 scan.setRowOffsetPerColumnFamily(storeOffset);
100 scan.setMaxResultsPerColumnFamily(storeLimit);
101 RegionScanner scanner = region.getScanner(scan);
102 List<Cell> kvListScan = new ArrayList<>();
103 List<Cell> results = new ArrayList<>();
104 while (scanner.next(results) || !results.isEmpty()) {
105 kvListScan.addAll(results);
106 results.clear();
108 result = Result.create(kvListScan);
109 TestScannersFromClientSide.verifyResult(result, kvListExp, toLog,
110 "Testing scan with storeOffset and storeLimit");
111 } finally {
112 HBaseTestingUtility.closeRegionAndWAL(region);