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.io.IOException;
021import org.apache.hadoop.hbase.HBaseClassTestRule;
022import org.apache.hadoop.hbase.HConstants;
023import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration;
024import org.apache.hadoop.hbase.regionserver.compactions.ExponentialCompactionWindowFactory;
025import org.apache.hadoop.hbase.testclassification.RegionServerTests;
026import org.apache.hadoop.hbase.testclassification.SmallTests;
027import org.junit.ClassRule;
028import org.junit.Test;
029import org.junit.experimental.categories.Category;
030
031@Category({ RegionServerTests.class, SmallTests.class })
032public class TestDateTieredCompactionPolicyOverflow extends AbstractTestDateTieredCompactionPolicy {
033
034  @ClassRule
035  public static final HBaseClassTestRule CLASS_RULE =
036    HBaseClassTestRule.forClass(TestDateTieredCompactionPolicyOverflow.class);
037
038  @Override
039  protected void config() {
040    super.config();
041
042    // Set up policy
043    conf.set(StoreEngine.STORE_ENGINE_CLASS_KEY,
044      "org.apache.hadoop.hbase.regionserver.DateTieredStoreEngine");
045    conf.setLong(CompactionConfiguration.DATE_TIERED_MAX_AGE_MILLIS_KEY, 100);
046    conf.setLong(CompactionConfiguration.DATE_TIERED_INCOMING_WINDOW_MIN_KEY, 3);
047    conf.setLong(ExponentialCompactionWindowFactory.BASE_WINDOW_MILLIS_KEY, Long.MAX_VALUE / 2);
048    conf.setInt(ExponentialCompactionWindowFactory.WINDOWS_PER_TIER_KEY, 2);
049    conf.setBoolean(CompactionConfiguration.DATE_TIERED_SINGLE_OUTPUT_FOR_MINOR_COMPACTION_KEY,
050      false);
051
052    // Special settings for compaction policy per window
053    this.conf.setInt(CompactionConfiguration.HBASE_HSTORE_COMPACTION_MIN_KEY, 2);
054    this.conf.setInt(CompactionConfiguration.HBASE_HSTORE_COMPACTION_MAX_KEY, 12);
055    this.conf.setFloat(CompactionConfiguration.HBASE_HSTORE_COMPACTION_RATIO_KEY, 1.2F);
056
057    conf.setInt(HStore.BLOCKING_STOREFILES_KEY, 20);
058    conf.setLong(HConstants.MAJOR_COMPACTION_PERIOD, 10);
059  }
060
061  /**
062   * Major compaction with maximum values
063   * @throws IOException with error
064   */
065  @Test
066  public void maxValuesForMajor() throws IOException {
067    long[] minTimestamps = new long[] { Long.MIN_VALUE, -100 };
068    long[] maxTimestamps = new long[] { -8, Long.MAX_VALUE };
069    long[] sizes = new long[] { 0, 1 };
070
071    compactEquals(Long.MAX_VALUE, sfCreate(minTimestamps, maxTimestamps, sizes),
072      new long[] { 0, 1 }, new long[] { Long.MIN_VALUE, -4611686018427387903L, 0,
073        4611686018427387903L, 9223372036854775806L },
074      true, true);
075  }
076}