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 org.apache.hadoop.hbase.util.Bytes;
28
29 import junit.framework.TestCase;
30
31
32
33
34 public class TestInclusiveStopFilter extends TestCase {
35 private final byte [] STOP_ROW = Bytes.toBytes("stop_row");
36 private final byte [] GOOD_ROW = Bytes.toBytes("good_row");
37 private final byte [] PAST_STOP_ROW = Bytes.toBytes("zzzzzz");
38
39 Filter mainFilter;
40
41 @Override
42 protected void setUp() throws Exception {
43 super.setUp();
44 mainFilter = new InclusiveStopFilter(STOP_ROW);
45 }
46
47
48
49
50
51 public void testStopRowIdentification() throws Exception {
52 stopRowTests(mainFilter);
53 }
54
55
56
57
58
59 public void testSerialization() throws Exception {
60
61 ByteArrayOutputStream stream = new ByteArrayOutputStream();
62 DataOutputStream out = new DataOutputStream(stream);
63 mainFilter.write(out);
64 out.close();
65 byte[] buffer = stream.toByteArray();
66
67
68 DataInputStream in = new DataInputStream(new ByteArrayInputStream(buffer));
69 Filter newFilter = new InclusiveStopFilter();
70 newFilter.readFields(in);
71
72
73 stopRowTests(newFilter);
74 }
75
76 private void stopRowTests(Filter filter) throws Exception {
77 assertFalse("Filtering on " + Bytes.toString(GOOD_ROW),
78 filter.filterRowKey(GOOD_ROW, 0, GOOD_ROW.length));
79 assertFalse("Filtering on " + Bytes.toString(STOP_ROW),
80 filter.filterRowKey(STOP_ROW, 0, STOP_ROW.length));
81 assertTrue("Filtering on " + Bytes.toString(PAST_STOP_ROW),
82 filter.filterRowKey(PAST_STOP_ROW, 0, PAST_STOP_ROW.length));
83
84 assertTrue("FilterAllRemaining", filter.filterAllRemaining());
85 assertFalse("FilterNotNull", filter.filterRow());
86
87 assertFalse("Filter a null", filter.filterRowKey(null, 0, 0));
88 }
89 }