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 static org.apache.hadoop.hbase.regionserver.Store.PRIORITY_USER;
021import static org.junit.jupiter.api.Assertions.assertEquals;
022import static org.junit.jupiter.api.Assertions.assertNotNull;
023import static org.junit.jupiter.api.Assertions.assertTrue;
024
025import java.io.IOException;
026import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
027import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker;
028import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequestImpl;
029import org.apache.hadoop.hbase.testclassification.LargeTests;
030import org.apache.hadoop.hbase.testclassification.RegionServerTests;
031import org.junit.jupiter.api.Tag;
032import org.junit.jupiter.api.TestTemplate;
033
034@Tag(RegionServerTests.TAG)
035@Tag(LargeTests.TAG)
036@HBaseParameterizedTestTemplate(name = "{index}: compType={0}")
037public class TestMajorCompactionRequest extends MajorCompactionTestBase {
038
039  public TestMajorCompactionRequest(String compType) {
040    super(compType);
041  }
042
043  /**
044   * Test for HBASE-5920 - Test user requested major compactions always occurring
045   */
046  @TestTemplate
047  public void testNonUserMajorCompactionRequest() throws Exception {
048    HStore store = r.getStore(COLUMN_FAMILY);
049    createStoreFile(r);
050    for (int i = 0; i < MAX_FILES_TO_COMPACT + 1; i++) {
051      createStoreFile(r);
052    }
053    store.triggerMajorCompaction();
054
055    CompactionRequestImpl request = store.requestCompaction().get().getRequest();
056    assertNotNull(request, "Expected to receive a compaction request");
057    assertEquals(false, request.isMajor(),
058      "System-requested major compaction should not occur if there are too many store files");
059  }
060
061  /**
062   * Test for HBASE-5920
063   */
064  @TestTemplate
065  public void testUserMajorCompactionRequest() throws IOException {
066    HStore store = r.getStore(COLUMN_FAMILY);
067    createStoreFile(r);
068    for (int i = 0; i < MAX_FILES_TO_COMPACT + 1; i++) {
069      createStoreFile(r);
070    }
071    store.triggerMajorCompaction();
072    CompactionRequestImpl request = store
073      .requestCompaction(PRIORITY_USER, CompactionLifeCycleTracker.DUMMY, null).get().getRequest();
074    assertNotNull(request, "Expected to receive a compaction request");
075    assertTrue(request.isMajor(), "User-requested major compaction should always occur, "
076      + "even if there are too many store files");
077  }
078}