2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org
.apache
.hadoop
.hbase
.master
;
21 import static org
.junit
.Assert
.assertFalse
;
22 import static org
.junit
.Assert
.assertTrue
;
24 import java
.io
.IOException
;
25 import org
.apache
.hadoop
.conf
.Configuration
;
26 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
27 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
28 import org
.apache
.hadoop
.hbase
.SingleProcessHBaseCluster
;
29 import org
.apache
.hadoop
.hbase
.StartTestingClusterOption
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.MasterTests
;
31 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
32 import org
.junit
.After
;
33 import org
.junit
.Before
;
34 import org
.junit
.ClassRule
;
35 import org
.junit
.Test
;
36 import org
.junit
.experimental
.categories
.Category
;
39 * Test for Regions Recovery Config Manager
41 @Category({ MasterTests
.class, MediumTests
.class })
42 public class TestRegionsRecoveryConfigManager
{
45 public static final HBaseClassTestRule CLASS_RULE
=
46 HBaseClassTestRule
.forClass(TestRegionsRecoveryConfigManager
.class);
48 private static final HBaseTestingUtil HBASE_TESTING_UTILITY
= new HBaseTestingUtil();
50 private SingleProcessHBaseCluster cluster
;
52 private HMaster hMaster
;
54 private RegionsRecoveryConfigManager regionsRecoveryConfigManager
;
56 private Configuration conf
;
59 public void setup() throws Exception
{
60 conf
= HBASE_TESTING_UTILITY
.getConfiguration();
61 conf
.unset("hbase.regions.recovery.store.file.ref.count");
62 conf
.unset("hbase.master.regions.recovery.check.interval");
63 StartTestingClusterOption option
= StartTestingClusterOption
.builder()
64 .masterClass(TestHMaster
.class).numRegionServers(1).numDataNodes(1).build();
65 HBASE_TESTING_UTILITY
.startMiniCluster(option
);
66 cluster
= HBASE_TESTING_UTILITY
.getMiniHBaseCluster();
70 public void tearDown() throws Exception
{
71 HBASE_TESTING_UTILITY
.shutdownMiniCluster();
75 public void testChoreSchedule() throws Exception
{
76 this.hMaster
= cluster
.getMaster();
78 this.regionsRecoveryConfigManager
= new RegionsRecoveryConfigManager(this.hMaster
);
81 hMaster
.getChoreService().isChoreScheduled(regionsRecoveryConfigManager
.getChore()));
83 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
86 hMaster
.getChoreService().isChoreScheduled(regionsRecoveryConfigManager
.getChore()));
88 conf
.setInt("hbase.master.regions.recovery.check.interval", 10);
89 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
90 // not yet scheduled - missing config: hbase.regions.recovery.store.file.ref.count
92 hMaster
.getChoreService().isChoreScheduled(regionsRecoveryConfigManager
.getChore()));
94 conf
.setInt("hbase.regions.recovery.store.file.ref.count", 10);
95 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
97 assertTrue(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryConfigManager
.getChore()));
99 conf
.setInt("hbase.regions.recovery.store.file.ref.count", 20);
100 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
101 // chore re-scheduled
102 assertTrue(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryConfigManager
.getChore()));
104 conf
.setInt("hbase.regions.recovery.store.file.ref.count", 20);
105 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
106 // chore scheduling untouched
107 assertTrue(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryConfigManager
.getChore()));
109 conf
.unset("hbase.regions.recovery.store.file.ref.count");
110 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
111 // chore un-scheduled
113 hMaster
.getChoreService().isChoreScheduled(regionsRecoveryConfigManager
.getChore()));
116 // Make it public so that JVMClusterUtil can access it.
117 public static class TestHMaster
extends HMaster
{
118 public TestHMaster(Configuration conf
) throws IOException
{