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