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