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