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