001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver;
019
020import java.util.HashMap;
021import java.util.Map;
022import java.util.Map.Entry;
023import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
024import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
025import org.apache.hadoop.hbase.io.hfile.HFileDataBlockEncoder;
026import org.apache.hadoop.hbase.io.hfile.HFileDataBlockEncoderImpl;
027import org.apache.hadoop.hbase.testclassification.LargeTests;
028import org.apache.hadoop.hbase.testclassification.RegionServerTests;
029import org.junit.jupiter.api.Tag;
030import org.junit.jupiter.api.TestTemplate;
031
032@Tag(RegionServerTests.TAG)
033@Tag(LargeTests.TAG)
034@HBaseParameterizedTestTemplate(name = "{index}: compType={0}")
035public class TestMajorCompactionDataBlockEncoding extends MajorCompactionTestBase {
036
037  public TestMajorCompactionDataBlockEncoding(String compType) {
038    super(compType);
039  }
040
041  @TestTemplate
042  public void testDataBlockEncodingInCacheOnly() throws Exception {
043    majorCompactionWithDataBlockEncoding(true);
044  }
045
046  @TestTemplate
047  public void testDataBlockEncodingEverywhere() throws Exception {
048    majorCompactionWithDataBlockEncoding(false);
049  }
050
051  private void majorCompactionWithDataBlockEncoding(boolean inCacheOnly) throws Exception {
052    Map<HStore, HFileDataBlockEncoder> replaceBlockCache = new HashMap<>();
053    for (HStore store : r.getStores()) {
054      HFileDataBlockEncoder blockEncoder = store.getDataBlockEncoder();
055      replaceBlockCache.put(store, blockEncoder);
056      final DataBlockEncoding inCache = DataBlockEncoding.PREFIX;
057      final DataBlockEncoding onDisk = inCacheOnly ? DataBlockEncoding.NONE : inCache;
058      ((HStore) store).setDataBlockEncoderInTest(new HFileDataBlockEncoderImpl(onDisk));
059    }
060
061    majorCompaction();
062
063    // restore settings
064    for (Entry<HStore, HFileDataBlockEncoder> entry : replaceBlockCache.entrySet()) {
065      ((HStore) entry.getKey()).setDataBlockEncoderInTest(entry.getValue());
066    }
067  }
068}