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.codec.prefixtree.PrefixTreeBlockMeta;
25  import org.apache.hadoop.hbase.codec.prefixtree.row.BaseTestRowData;
26  import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition;
27  import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher;
28  import org.apache.hadoop.hbase.util.Bytes;
29  import org.junit.Assert;
30  
31  import com.google.common.collect.Lists;
32  
33  /*
34   * Goes beyond a trivial trie to add a branch on the "cf" node
35   */
36  public class TestRowDataDeeper extends BaseTestRowData{
37  
38  	static byte[]
39          cdc = Bytes.toBytes("cdc"),
40          cf6 = Bytes.toBytes("cf6"),
41          cfc = Bytes.toBytes("cfc"),
42          f = Bytes.toBytes("f"),
43          q = Bytes.toBytes("q"),
44          v = Bytes.toBytes("v");
45  
46  	static long
47  		ts = 55L;
48  
49  	static List<KeyValue> d = Lists.newArrayList();
50  	static{
51  		d.add(new KeyValue(cdc, f, q, ts, v));
52      d.add(new KeyValue(cf6, f, q, ts, v));
53      d.add(new KeyValue(cfc, f, q, ts, v));
54  	}
55  
56  	@Override
57  	public List<KeyValue> getInputs() {
58  		return d;
59  	}
60  
61  	@Override
62  	public void individualBlockMetaAssertions(PrefixTreeBlockMeta blockMeta) {
63  	  //0: token:c; fan:d,f
64  	  //1: token:f; fan:6,c
65  	  //2: leaves
66  		Assert.assertEquals(3, blockMeta.getRowTreeDepth());
67  	}
68  
69    @Override
70    public void individualSearcherAssertions(CellSearcher searcher) {
71      /**
72       * The searcher should get a token mismatch on the "r" branch.  Assert that it skips not only
73       * rA, but rB as well.
74       */
75      KeyValue cfcRow = KeyValue.createFirstOnRow(Bytes.toBytes("cfc"));
76      CellScannerPosition position = searcher.positionAtOrAfter(cfcRow);
77      Assert.assertEquals(CellScannerPosition.AFTER, position);
78      Assert.assertEquals(d.get(2), searcher.current());
79      searcher.previous();
80      Assert.assertEquals(d.get(1), searcher.current());
81    }
82  }
83  
84