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