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