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