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.builder;
20
21 import java.util.List;
22
23
24 import org.apache.hadoop.hbase.SmallTests;
25 import org.apache.hadoop.hbase.codec.prefixtree.encode.tokenize.Tokenizer;
26 import org.apache.hadoop.hbase.util.SimpleByteRange;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32 import com.google.common.collect.Lists;
33
34 @Category(SmallTests.class)
35 public class TestTreeDepth {
36
37 @Test
38 public void testSingleNode() {
39 List<String> inputs = Lists.newArrayList("a");
40 testInternal(inputs, 1);
41 }
42
43 @Test
44 public void testSimpleBranch() {
45 List<String> inputs = Lists.newArrayList("a", "aa", "ab");
46 testInternal(inputs, 2);
47 }
48
49 @Test
50 public void testEmptyRoot() {
51 List<String> inputs = Lists.newArrayList("a", "b");
52 testInternal(inputs, 2);
53 }
54
55 @Test
56 public void testRootAsNub() {
57 List<String> inputs = Lists.newArrayList("a", "aa");
58 testInternal(inputs, 2);
59 }
60
61 @Test
62 public void testRootAsNubPlusNub() {
63 List<String> inputs = Lists.newArrayList("a", "aa", "aaa");
64 testInternal(inputs, 3);
65 }
66
67 @Test
68 public void testEmptyRootPlusNub() {
69 List<String> inputs = Lists.newArrayList("a", "aa", "b");
70 testInternal(inputs, 3);
71 }
72
73 @Test
74 public void testSplitDistantAncestor() {
75 List<String> inputs = Lists.newArrayList("a", "ac", "acd", "b");
76 testInternal(inputs, 4);
77 }
78
79 protected void testInternal(List<String> inputs, int expectedTreeDepth) {
80 Tokenizer builder = new Tokenizer();
81 for (String s : inputs) {
82 SimpleByteRange b = new SimpleByteRange(Bytes.toBytes(s));
83 builder.addSorted(b);
84 }
85 Assert.assertEquals(1, builder.getRoot().getNodeDepth());
86 Assert.assertEquals(expectedTreeDepth, builder.getTreeDepth());
87 }
88
89 }