1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.filter;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.IOException;
26
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31
32
33
34 @Category(SmallTests.class)
35 public class TestPageFilter {
36 static final int ROW_LIMIT = 3;
37
38
39
40
41
42 @Test
43 public void testPageSize() throws Exception {
44 Filter f = new PageFilter(ROW_LIMIT);
45 pageSizeTests(f);
46 }
47
48
49
50
51
52 @Test
53 public void testSerialization() throws Exception {
54 Filter f = new PageFilter(ROW_LIMIT);
55
56 byte[] buffer = f.toByteArray();
57
58 Filter newFilter = PageFilter.parseFrom(buffer);
59
60
61 pageSizeTests(newFilter);
62 }
63
64 private void pageSizeTests(Filter f) throws Exception {
65 testFiltersBeyondPageSize(f, ROW_LIMIT);
66 }
67
68 private void testFiltersBeyondPageSize(final Filter f, final int pageSize) throws IOException {
69 int count = 0;
70 for (int i = 0; i < (pageSize * 2); i++) {
71 boolean filterOut = f.filterRow();
72
73 if(filterOut) {
74 break;
75 } else {
76 count++;
77 }
78
79
80 if(count == pageSize) {
81 assertTrue(f.filterAllRemaining());
82 } else {
83 assertFalse(f.filterAllRemaining());
84 }
85
86 }
87 assertEquals(pageSize, count);
88 }
89
90 }
91