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.rsgroup; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021 022import java.util.List; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.HBaseTestingUtil; 025import org.apache.hadoop.hbase.SingleProcessHBaseCluster; 026import org.apache.hadoop.hbase.TableName; 027import org.apache.hadoop.hbase.Waiter; 028import org.apache.hadoop.hbase.master.HMaster; 029import org.apache.hadoop.hbase.master.ServerManager; 030import org.apache.hadoop.hbase.testclassification.MediumTests; 031import org.apache.hadoop.hbase.testclassification.RSGroupTests; 032import org.apache.hadoop.hbase.util.compaction.TestMajorCompactorTTL; 033import org.junit.jupiter.api.AfterEach; 034import org.junit.jupiter.api.BeforeEach; 035import org.junit.jupiter.api.Tag; 036import org.junit.jupiter.api.Test; 037import org.junit.jupiter.api.TestInfo; 038 039import org.apache.hbase.thirdparty.com.google.common.collect.Lists; 040 041@Tag(RSGroupTests.TAG) 042@Tag(MediumTests.TAG) 043public class TestRSGroupMajorCompactionTTL extends TestMajorCompactorTTL { 044 045 private final static int NUM_SLAVES_BASE = 6; 046 047 @BeforeEach 048 @Override 049 public void setUp() throws Exception { 050 utility = new HBaseTestingUtil(); 051 Configuration conf = utility.getConfiguration(); 052 RSGroupUtil.enableRSGroup(conf); 053 conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, NUM_SLAVES_BASE); 054 conf.setInt("hbase.hfile.compaction.discharger.interval", 10); 055 utility.startMiniCluster(NUM_SLAVES_BASE); 056 SingleProcessHBaseCluster cluster = utility.getHBaseCluster(); 057 final HMaster master = cluster.getMaster(); 058 059 // wait for balancer to come online 060 utility.waitFor(60000, new Waiter.Predicate<Exception>() { 061 @Override 062 public boolean evaluate() { 063 return master.isInitialized() 064 && ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline(); 065 } 066 }); 067 admin = utility.getAdmin(); 068 } 069 070 @AfterEach 071 @Override 072 public void tearDown() throws Exception { 073 utility.shutdownMiniCluster(); 074 } 075 076 @Test 077 public void testCompactingTables(TestInfo testInfo) throws Exception { 078 List<TableName> tableNames = Lists.newArrayList(); 079 for (int i = 0; i < 10; i++) { 080 tableNames.add(createTable(testInfo.getTestMethod().get().getName() + "___" + i)); 081 } 082 083 // Delay a bit, so we can set the table TTL to 5 seconds 084 Thread.sleep(10 * 1000); 085 086 for (TableName tableName : tableNames) { 087 int numberOfRegions = admin.getRegions(tableName).size(); 088 int numHFiles = utility.getNumHFiles(tableName, FAMILY); 089 modifyTTL(tableName); 090 } 091 092 RSGroupMajorCompactionTTL compactor = new RSGroupMajorCompactionTTL(); 093 compactor.compactTTLRegionsOnGroup(utility.getConfiguration(), RSGroupInfo.DEFAULT_GROUP, 1, 094 200, -1, -1, false, false); 095 096 for (TableName tableName : tableNames) { 097 int numberOfRegions = admin.getRegions(tableName).size(); 098 int numHFiles = utility.getNumHFiles(tableName, FAMILY); 099 assertEquals(numberOfRegions, numHFiles); 100 } 101 } 102}