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.apache.hadoop.hbase.util.CollectionUtils;
32 import org.junit.Assert;
33
34 import com.google.common.collect.Lists;
35
36 public class TestRowDataSimple extends BaseTestRowData {
37
38 static byte[]
39
40 rowA = Bytes.toBytes("Arow"),
41 rowB = Bytes.toBytes("Brow"), cf = Bytes.toBytes("fam"),
42 cq0 = Bytes.toBytes("cq0"),
43 cq1 = Bytes.toBytes("cq1tail"),
44 cq2 = Bytes.toBytes("dcq2"),
45 v0 = Bytes.toBytes("v0");
46
47 static long ts = 55L;
48
49 static List<KeyValue> d = Lists.newArrayList();
50 static {
51 d.add(new KeyValue(rowA, cf, cq0, ts, v0));
52 d.add(new KeyValue(rowA, cf, cq1, ts, v0));
53 d.add(new KeyValue(rowA, cf, cq2, ts, v0));
54 d.add(new KeyValue(rowB, cf, cq0, ts, v0));
55 d.add(new KeyValue(rowB, cf, cq1, ts, v0));
56 d.add(new KeyValue(rowB, cf, cq2, ts, v0));
57 }
58
59 @Override
60 public List<KeyValue> getInputs() {
61 return d;
62 }
63
64 @Override
65 public void individualSearcherAssertions(CellSearcher searcher) {
66 CellScannerPosition p;
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(3)));
80 Assert.assertTrue(CellComparator.equals(d.get(3), searcher.current()));
81
82 Cell between4And5 = new KeyValue(rowB, cf, cq1, ts - 2, v0);
83
84
85 Assert.assertFalse(searcher.positionAt(between4And5));
86
87
88 p = searcher.positionAtOrBefore(between4And5);
89 Assert.assertEquals(CellScannerPosition.BEFORE, p);
90 Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(4)));
91
92
93 p = searcher.positionAtOrAfter(between4And5);
94 Assert.assertEquals(CellScannerPosition.AFTER, p);
95 Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(5)));
96
97
98 Cell beforeFirst = new KeyValue(Bytes.toBytes("A"), cf, cq0, ts, v0);
99 Assert.assertFalse(searcher.positionAt(beforeFirst));
100 p = searcher.positionAtOrBefore(beforeFirst);
101 Assert.assertEquals(CellScannerPosition.BEFORE_FIRST, p);
102 p = searcher.positionAtOrAfter(beforeFirst);
103 Assert.assertEquals(CellScannerPosition.AFTER, p);
104 Assert.assertTrue(CellComparator.equals(searcher.current(), d.get(0)));
105 Assert.assertEquals(d.get(0), searcher.current());
106
107
108 Cell afterLast = new KeyValue(Bytes.toBytes("z"), cf, cq0, ts, v0);
109 Assert.assertFalse(searcher.positionAt(afterLast));
110 p = searcher.positionAtOrAfter(afterLast);
111 Assert.assertEquals(CellScannerPosition.AFTER_LAST, p);
112 p = searcher.positionAtOrBefore(afterLast);
113 Assert.assertEquals(CellScannerPosition.BEFORE, p);
114 Assert.assertTrue(CellComparator.equals(searcher.current(), CollectionUtils.getLast(d)));
115 }
116
117 }