View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.codec.prefixtree.row.data;
20  
21  import java.util.List;
22  
23  import org.apache.hadoop.hbase.KeyValue;
24  import org.apache.hadoop.hbase.KeyValueUtil;
25  import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeBlockMeta;
26  import org.apache.hadoop.hbase.codec.prefixtree.row.BaseTestRowData;
27  import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition;
28  import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher;
29  import org.apache.hadoop.hbase.util.Bytes;
30  import org.junit.Assert;
31  
32  import com.google.common.collect.Lists;
33  
34  /*
35   * Goes beyond a trivial trie to add a branch on the "cf" node
36   */
37  public class TestRowDataDeeper extends BaseTestRowData{
38  
39    static byte[]
40      cdc = Bytes.toBytes("cdc"),
41      cf6 = Bytes.toBytes("cf6"),
42      cfc = Bytes.toBytes("cfc"),
43      f = Bytes.toBytes("f"),
44      q = Bytes.toBytes("q"),
45      v = Bytes.toBytes("v");
46  
47    static long
48      ts = 55L;
49  
50    static List<KeyValue> d = Lists.newArrayList();
51    static{
52      d.add(new KeyValue(cdc, f, q, ts, v));
53      d.add(new KeyValue(cf6, f, q, ts, v));
54      d.add(new KeyValue(cfc, f, q, ts, v));
55    }
56  
57    @Override
58    public List<KeyValue> getInputs() {
59      return d;
60    }
61  
62    @Override
63    public void individualBlockMetaAssertions(PrefixTreeBlockMeta blockMeta) {
64      //0: token:c; fan:d,f
65      //1: token:f; fan:6,c
66      //2: leaves
67      Assert.assertEquals(3, blockMeta.getRowTreeDepth());
68    }
69  
70    @Override
71    public void individualSearcherAssertions(CellSearcher searcher) {
72      /**
73       * The searcher should get a token mismatch on the "r" branch.  Assert that it skips not only
74       * rA, but rB as well.
75       */
76      KeyValue cfcRow = KeyValueUtil.createFirstOnRow(Bytes.toBytes("cfc"));
77      CellScannerPosition position = searcher.positionAtOrAfter(cfcRow);
78      Assert.assertEquals(CellScannerPosition.AFTER, position);
79      Assert.assertEquals(d.get(2), searcher.current());
80      searcher.previous();
81      Assert.assertEquals(d.get(1), searcher.current());
82    }
83  }
84  
85