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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.hadoop
.hbase
.regionserver
;
20 import java
.io
.IOException
;
22 import org
.apache
.hadoop
.conf
.Configuration
;
23 import org
.apache
.hadoop
.fs
.FileSystem
;
24 import org
.apache
.hadoop
.fs
.Path
;
25 import org
.apache
.hadoop
.hbase
.ArrayBackedTag
;
26 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
27 import org
.apache
.hadoop
.hbase
.HBaseConfiguration
;
28 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
29 import org
.apache
.hadoop
.hbase
.KeyValue
;
30 import org
.apache
.hadoop
.hbase
.Tag
;
31 import org
.apache
.hadoop
.hbase
.io
.compress
.Compression
;
32 import org
.apache
.hadoop
.hbase
.io
.hfile
.HFileContext
;
33 import org
.apache
.hadoop
.hbase
.io
.hfile
.HFileContextBuilder
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.MiscTests
;
35 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
36 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
37 import org
.apache
.hadoop
.hbase
.util
.EnvironmentEdgeManager
;
38 import org
.junit
.Before
;
39 import org
.junit
.ClassRule
;
40 import org
.junit
.Test
;
41 import org
.junit
.experimental
.categories
.Category
;
44 * Test DataBlockEncodingTool.
46 @Category({MiscTests
.class, SmallTests
.class})
47 public class TestDataBlockEncodingTool
{
50 public static final HBaseClassTestRule CLASS_RULE
=
51 HBaseClassTestRule
.forClass(TestDataBlockEncodingTool
.class);
53 private static final HBaseTestingUtil TEST_UTIL
= new HBaseTestingUtil();
54 private static final String ROOT_DIR
=
55 TEST_UTIL
.getDataTestDir("TestDataBlockEncodingTool").toString();
56 private static final Configuration conf
= TEST_UTIL
.getConfiguration();
57 private static FileSystem fs
;
58 private static StoreFileWriter sfw
;
61 public void setUp() throws IOException
{
62 fs
= TEST_UTIL
.getTestFileSystem();
65 private void testHFile(String fileName
, boolean useTags
, boolean allTags
) throws IOException
{
66 Path path
= new Path(ROOT_DIR
, fileName
);
68 createHFileWithTags(path
, useTags
, allTags
);
69 testDataBlockingTool(path
);
71 if (fs
.exists(path
)) {
72 fs
.delete(path
, false);
77 private void createHFileWithTags(Path path
, boolean useTags
, boolean allTags
) throws IOException
{
78 HFileContext meta
= new HFileContextBuilder()
79 .withBlockSize(64 * 1024)
80 .withIncludesTags(useTags
).build();
82 new StoreFileWriter
.Builder(conf
, fs
)
84 .withFileContext(meta
).build();
85 long now
= EnvironmentEdgeManager
.currentTime();
86 byte[] FAMILY
= Bytes
.toBytes("cf");
87 byte[] QUALIFIER
= Bytes
.toBytes("q");
89 for (char d
= 'a'; d
<= 'z'; d
++) {
90 for (char e
= 'a'; e
<= 'z'; e
++) {
91 byte[] b
= new byte[] { (byte) d
, (byte) e
};
95 // Write cells with tags to HFile.
96 Tag
[] tags
= new Tag
[]{
97 new ArrayBackedTag((byte) 0, Bytes
.toString(b
)),
98 new ArrayBackedTag((byte) 0, Bytes
.toString(b
))};
99 kv
= new KeyValue(b
, FAMILY
, QUALIFIER
, now
, b
, tags
);
101 // Write half cells with tags and half without tags to HFile.
102 if ((e
- 'a') % 2 == 0) {
103 kv
= new KeyValue(b
, FAMILY
, QUALIFIER
, now
, b
);
105 Tag
[] tags
= new Tag
[]{
106 new ArrayBackedTag((byte) 0, Bytes
.toString(b
)),
107 new ArrayBackedTag((byte) 0, Bytes
.toString(b
))};
108 kv
= new KeyValue(b
, FAMILY
, QUALIFIER
, now
, b
, tags
);
112 // Write cells without tags to HFile.
113 kv
= new KeyValue(b
, FAMILY
, QUALIFIER
, now
, b
);
118 sfw
.appendMetadata(0, false);
124 private static void testDataBlockingTool(Path path
) throws IOException
{
125 Configuration conf
= HBaseConfiguration
.create();
126 int maxKV
= Integer
.MAX_VALUE
;
127 boolean doVerify
= true;
128 boolean doBenchmark
= true;
129 String testHFilePath
= path
.toString();
130 DataBlockEncodingTool
.testCodecs(conf
, maxKV
, testHFilePath
,
131 Compression
.Algorithm
.GZ
.getName(), doBenchmark
, doVerify
);
135 public void testHFileAllCellsWithTags() throws IOException
{
136 testHFile("1234567890", true, true);
140 public void testHFileAllCellsWithoutTags() throws IOException
{
141 testHFile("1234567089", false, false);
145 public void testHFileHalfCellsWithTags() throws IOException
{
146 testHFile("1234560789", true, false);