HBASE-26700 The way we bypass broken track file is not enough in StoreFileListFile...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestMaxResultsPerColumnFamily.java
blobd8a10bfca5f38e7b4230a072ff7aacd0dcef617e
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.regionserver;
20 import static org.junit.Assert.assertEquals;
21 import org.apache.hadoop.hbase.HBaseClassTestRule;
22 import org.apache.hadoop.hbase.HBaseTestingUtil;
23 import org.apache.hadoop.hbase.TableName;
24 import org.apache.hadoop.hbase.client.Admin;
25 import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
26 import org.apache.hadoop.hbase.client.Put;
27 import org.apache.hadoop.hbase.client.Result;
28 import org.apache.hadoop.hbase.client.ResultScanner;
29 import org.apache.hadoop.hbase.client.Scan;
30 import org.apache.hadoop.hbase.client.Table;
31 import org.apache.hadoop.hbase.client.TableDescriptor;
32 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
33 import org.apache.hadoop.hbase.testclassification.MediumTests;
34 import org.apache.hadoop.hbase.util.Bytes;
35 import org.junit.AfterClass;
36 import org.junit.BeforeClass;
37 import org.junit.ClassRule;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.experimental.categories.Category;
41 import org.junit.rules.TestName;
43 @Category(MediumTests.class)
44 public class TestMaxResultsPerColumnFamily {
46 @ClassRule
47 public static final HBaseClassTestRule CLASS_RULE =
48 HBaseClassTestRule.forClass(TestMaxResultsPerColumnFamily.class);
50 private static final byte [][] FAMILIES = {
51 Bytes.toBytes("1"), Bytes.toBytes("2")
54 private static final byte [][] VALUES = {
55 Bytes.toBytes("testValueOne"), Bytes.toBytes("testValueTwo")
58 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
60 @BeforeClass
61 public static void setUpBeforeClass() throws Exception {
62 UTIL.startMiniCluster(1);
65 @AfterClass
66 public static void tearDownAfterClass() throws Exception {
67 UTIL.shutdownMiniCluster();
70 @Rule
71 public TestName name = new TestName();
73 @Test
74 public void testSetMaxResultsPerColumnFamilySimple() throws Exception {
75 TableName tableName = TableName.valueOf(name.getMethodName());
76 Admin admin = UTIL.getAdmin();
77 ColumnFamilyDescriptorBuilder cfBuilder0 =
78 ColumnFamilyDescriptorBuilder.newBuilder(FAMILIES[0]);
80 TableDescriptor tableDescriptor =
81 TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(cfBuilder0.build()).build();
82 admin.createTable(tableDescriptor);
83 try (Table table = UTIL.getConnection().getTable(tableName)) {
85 for (int i = 0; i < 30000; i++) {
86 byte[] ROW = Bytes.toBytes("" + i);
87 Put p = new Put(ROW);
89 p.addColumn(FAMILIES[0], Bytes.toBytes("" + 1), VALUES[1]);
90 p.addColumn(FAMILIES[0], Bytes.toBytes("" + 2), VALUES[0]);
92 table.put(p);
96 try (Table t = UTIL.getConnection().getTable(tableName)) {
97 int expected = 30000;
99 Scan limits = new Scan().setReadType(Scan.ReadType.PREAD);
100 limits.setMaxResultsPerColumnFamily(1);
102 int count1 = countScanRows(t, limits);
103 assertEquals(expected, count1);
107 static int countScanRows(Table t, Scan scan) throws Exception {
109 int count = 0;
110 try(ResultScanner scanner = t.getScanner(scan)) {
111 for(Result r:scanner) {
112 count ++;
115 return count;