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