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.SmallTests;
27  import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeBlockMeta;
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  }