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.master; 019 020import static org.junit.Assert.assertFalse; 021import static org.junit.Assert.assertTrue; 022 023import java.io.IOException; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.HBaseTestingUtil; 027import org.apache.hadoop.hbase.SingleProcessHBaseCluster; 028import org.apache.hadoop.hbase.StartTestingClusterOption; 029import org.apache.hadoop.hbase.testclassification.MasterTests; 030import org.apache.hadoop.hbase.testclassification.MediumTests; 031import org.junit.After; 032import org.junit.Before; 033import org.junit.ClassRule; 034import org.junit.Test; 035import org.junit.experimental.categories.Category; 036 037/** 038 * Test for Regions Recovery Config Manager 039 */ 040@Category({ MasterTests.class, MediumTests.class }) 041public class TestRegionsRecoveryConfigManager { 042 043 @ClassRule 044 public static final HBaseClassTestRule CLASS_RULE = 045 HBaseClassTestRule.forClass(TestRegionsRecoveryConfigManager.class); 046 047 private static final HBaseTestingUtil HBASE_TESTING_UTILITY = new HBaseTestingUtil(); 048 049 private SingleProcessHBaseCluster cluster; 050 051 private HMaster hMaster; 052 053 private RegionsRecoveryConfigManager regionsRecoveryConfigManager; 054 055 private Configuration conf; 056 057 @Before 058 public void setup() throws Exception { 059 conf = HBASE_TESTING_UTILITY.getConfiguration(); 060 conf.unset("hbase.regions.recovery.store.file.ref.count"); 061 conf.unset("hbase.master.regions.recovery.check.interval"); 062 StartTestingClusterOption option = StartTestingClusterOption.builder() 063 .masterClass(TestHMaster.class).numRegionServers(1).numDataNodes(1).build(); 064 HBASE_TESTING_UTILITY.startMiniCluster(option); 065 cluster = HBASE_TESTING_UTILITY.getMiniHBaseCluster(); 066 } 067 068 @After 069 public void tearDown() throws Exception { 070 HBASE_TESTING_UTILITY.shutdownMiniCluster(); 071 } 072 073 @Test 074 public void testChoreSchedule() throws Exception { 075 this.hMaster = cluster.getMaster(); 076 077 this.regionsRecoveryConfigManager = new RegionsRecoveryConfigManager(this.hMaster); 078 // not yet scheduled 079 assertFalse( 080 hMaster.getChoreService().isChoreScheduled(regionsRecoveryConfigManager.getChore())); 081 082 this.regionsRecoveryConfigManager.onConfigurationChange(conf); 083 // not yet scheduled 084 assertFalse( 085 hMaster.getChoreService().isChoreScheduled(regionsRecoveryConfigManager.getChore())); 086 087 conf.setInt("hbase.master.regions.recovery.check.interval", 10); 088 this.regionsRecoveryConfigManager.onConfigurationChange(conf); 089 // not yet scheduled - missing config: hbase.regions.recovery.store.file.ref.count 090 assertFalse( 091 hMaster.getChoreService().isChoreScheduled(regionsRecoveryConfigManager.getChore())); 092 093 conf.setInt("hbase.regions.recovery.store.file.ref.count", 10); 094 this.regionsRecoveryConfigManager.onConfigurationChange(conf); 095 // chore scheduled 096 assertTrue(hMaster.getChoreService().isChoreScheduled(regionsRecoveryConfigManager.getChore())); 097 098 conf.setInt("hbase.regions.recovery.store.file.ref.count", 20); 099 this.regionsRecoveryConfigManager.onConfigurationChange(conf); 100 // chore re-scheduled 101 assertTrue(hMaster.getChoreService().isChoreScheduled(regionsRecoveryConfigManager.getChore())); 102 103 conf.setInt("hbase.regions.recovery.store.file.ref.count", 20); 104 this.regionsRecoveryConfigManager.onConfigurationChange(conf); 105 // chore scheduling untouched 106 assertTrue(hMaster.getChoreService().isChoreScheduled(regionsRecoveryConfigManager.getChore())); 107 108 conf.unset("hbase.regions.recovery.store.file.ref.count"); 109 this.regionsRecoveryConfigManager.onConfigurationChange(conf); 110 // chore un-scheduled 111 assertFalse( 112 hMaster.getChoreService().isChoreScheduled(regionsRecoveryConfigManager.getChore())); 113 } 114 115 // Make it public so that JVMClusterUtil can access it. 116 public static class TestHMaster extends HMaster { 117 public TestHMaster(Configuration conf) throws IOException { 118 super(conf); 119 } 120 } 121}