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.blockmeta;
20
21 import java.io.ByteArrayOutputStream;
22 import java.io.IOException;
23 import java.nio.ByteBuffer;
24
25 import org.apache.hadoop.hbase.KeyValue;
26 import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeBlockMeta;
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32 @Category(SmallTests.class)
33 public class TestBlockMeta {
34
35 static int BLOCK_START = 123;
36
37 private static PrefixTreeBlockMeta createSample() {
38 PrefixTreeBlockMeta m = new PrefixTreeBlockMeta();
39 m.setNumMetaBytes(0);
40 m.setNumKeyValueBytes(3195);
41
42 m.setNumRowBytes(0);
43 m.setNumFamilyBytes(3);
44 m.setNumQualifierBytes(12345);
45 m.setNumTagsBytes(50);
46 m.setNumTimestampBytes(23456);
47 m.setNumMvccVersionBytes(5);
48 m.setNumValueBytes(34567);
49
50 m.setNextNodeOffsetWidth(3);
51 m.setFamilyOffsetWidth(1);
52 m.setQualifierOffsetWidth(2);
53 m.setTagsOffsetWidth(2);
54 m.setTimestampIndexWidth(1);
55 m.setMvccVersionIndexWidth(2);
56 m.setValueOffsetWidth(8);
57 m.setValueLengthWidth(3);
58
59 m.setRowTreeDepth(11);
60 m.setMaxRowLength(200);
61 m.setMaxQualifierLength(50);
62 m.setMaxTagsLength(40);
63
64 m.setMinTimestamp(1318966363481L);
65 m.setTimestampDeltaWidth(3);
66 m.setMinMvccVersion(100L);
67 m.setMvccVersionDeltaWidth(4);
68
69 m.setAllSameType(false);
70 m.setAllTypes(KeyValue.Type.Delete.getCode());
71
72 m.setNumUniqueRows(88);
73 m.setNumUniqueFamilies(1);
74 m.setNumUniqueQualifiers(56);
75 m.setNumUniqueTags(5);
76 return m;
77 }
78
79 @Test
80 public void testStreamSerialization() throws IOException {
81 PrefixTreeBlockMeta original = createSample();
82 ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
83 original.writeVariableBytesToOutputStream(os);
84 ByteBuffer buffer = ByteBuffer.wrap(os.toByteArray());
85 PrefixTreeBlockMeta roundTripped = new PrefixTreeBlockMeta(buffer);
86 Assert.assertTrue(original.equals(roundTripped));
87 }
88
89 }