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.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  }