1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.codec.prefixtree.row.data;
20
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.apache.hadoop.hbase.Cell;
25 import org.apache.hadoop.hbase.CellComparator;
26 import org.apache.hadoop.hbase.KeyValue;
27 import org.apache.hadoop.hbase.codec.prefixtree.row.BaseTestRowData;
28 import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition;
29 import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher;
30 import org.apache.hadoop.hbase.util.Bytes;
31 import org.junit.Assert;
32
33 import com.google.common.collect.Lists;
34
35 public class TestRowDataSearcherRowMiss extends BaseTestRowData{
36
37 static byte[]
38
39 A = Bytes.toBytes("A"),
40 AA = Bytes.toBytes("AA"),
41 AAA = Bytes.toBytes("AAA"),
42 B = Bytes.toBytes("B"),
43 cf = Bytes.toBytes("fam"),
44 cq = Bytes.toBytes("cq0"),
45 v = Bytes.toBytes("v0");
46
47 static long
48 ts = 55L;
49
50 static List<KeyValue> d = Lists.newArrayList();
51 static{
52 d.add(new KeyValue(A, cf, cq, ts, v));
53 d.add(new KeyValue(AA, cf, cq, ts, v));
54 d.add(new KeyValue(AAA, cf, cq, ts, v));
55 d.add(new KeyValue(B, cf, cq, ts, v));
56 }
57
58 @Override
59 public List<KeyValue> getInputs() {
60 return d;
61 }
62
63 @Override
64 public void individualSearcherAssertions(CellSearcher searcher) {
65 assertRowOffsetsCorrect();
66
67 searcher.resetToBeforeFirstEntry();
68
69
70 try {
71 searcher.advance();
72 } catch (IOException e) {
73 throw new RuntimeException(e);
74 }
75 Cell first = searcher.current();
76 Assert.assertTrue(CellComparator.equals(d.get(0), first));
77
78
79 Assert.assertTrue(searcher.positionAt(d.get(1)));
80 Assert.assertTrue(CellComparator.equals(d.get(1), searcher.current()));
81
82 testBetween1and2(searcher);
83 testBetween2and3(searcher);
84 }
85
86
87
88 private void assertRowOffsetsCorrect(){
89 Assert.assertEquals(4, getRowStartIndexes().size());
90 }
91
92 private void testBetween1and2(CellSearcher searcher){
93 CellScannerPosition p;
94 Cell betweenAAndAAA = new KeyValue(AA, cf, cq, ts-2, v);
95
96
97 Assert.assertFalse(searcher.positionAt(betweenAAndAAA));
98
99
100 p = searcher.positionAtOrBefore(betweenAAndAAA);
101 Assert.assertEquals(CellScannerPosition.BEFORE, p);
102 Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(1)));
103
104
105 p = searcher.positionAtOrAfter(betweenAAndAAA);
106 Assert.assertEquals(CellScannerPosition.AFTER, p);
107 Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(2)));
108 }
109
110 private void testBetween2and3(CellSearcher searcher){
111 CellScannerPosition p;
112 Cell betweenAAAndB = new KeyValue(AAA, cf, cq, ts-2, v);
113
114
115 Assert.assertFalse(searcher.positionAt(betweenAAAndB));
116
117
118 p = searcher.positionAtOrBefore(betweenAAAndB);
119 Assert.assertEquals(CellScannerPosition.BEFORE, p);
120 Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(2)));
121
122
123 p = searcher.positionAtOrAfter(betweenAAAndB);
124 Assert.assertEquals(CellScannerPosition.AFTER, p);
125 Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(3)));
126 }
127
128 }