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 java
.io
.IOException
;
23 import org
.apache
.hadoop
.conf
.Configuration
;
24 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
25 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
26 import org
.apache
.hadoop
.hbase
.MiniHBaseCluster
;
27 import org
.apache
.hadoop
.hbase
.StartMiniClusterOption
;
28 import org
.apache
.hadoop
.hbase
.Stoppable
;
29 import org
.apache
.hadoop
.hbase
.testclassification
.MasterTests
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
31 import org
.junit
.After
;
32 import org
.junit
.Assert
;
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 HBaseTestingUtility HBASE_TESTING_UTILITY
= new HBaseTestingUtility();
50 private MiniHBaseCluster cluster
;
52 private HMaster hMaster
;
54 private RegionsRecoveryChore regionsRecoveryChore
;
56 private RegionsRecoveryConfigManager regionsRecoveryConfigManager
;
58 private Configuration conf
;
61 public void setup() throws Exception
{
62 conf
= HBASE_TESTING_UTILITY
.getConfiguration();
63 conf
.unset("hbase.regions.recovery.store.file.ref.count");
64 conf
.unset("hbase.master.regions.recovery.check.interval");
65 StartMiniClusterOption option
= StartMiniClusterOption
.builder()
66 .masterClass(TestHMaster
.class)
68 .numDataNodes(1).build();
69 HBASE_TESTING_UTILITY
.startMiniCluster(option
);
70 cluster
= HBASE_TESTING_UTILITY
.getMiniHBaseCluster();
74 public void tearDown() throws Exception
{
75 HBASE_TESTING_UTILITY
.shutdownMiniCluster();
79 public void testChoreSchedule() throws Exception
{
81 this.hMaster
= cluster
.getMaster();
83 Stoppable stoppable
= new StoppableImplementation();
84 this.regionsRecoveryChore
= new RegionsRecoveryChore(stoppable
, conf
, hMaster
);
86 this.regionsRecoveryConfigManager
= new RegionsRecoveryConfigManager(this.hMaster
);
88 Assert
.assertFalse(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryChore
));
90 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
92 Assert
.assertFalse(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryChore
));
94 conf
.setInt("hbase.master.regions.recovery.check.interval", 10);
95 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
96 // not yet scheduled - missing config: hbase.regions.recovery.store.file.ref.count
97 Assert
.assertFalse(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryChore
));
99 conf
.setInt("hbase.regions.recovery.store.file.ref.count", 10);
100 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
102 Assert
.assertTrue(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryChore
));
104 conf
.setInt("hbase.regions.recovery.store.file.ref.count", 20);
105 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
106 // chore re-scheduled
107 Assert
.assertTrue(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryChore
));
109 conf
.setInt("hbase.regions.recovery.store.file.ref.count", 20);
110 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
111 // chore scheduling untouched
112 Assert
.assertTrue(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryChore
));
114 conf
.unset("hbase.regions.recovery.store.file.ref.count");
115 this.regionsRecoveryConfigManager
.onConfigurationChange(conf
);
116 // chore un-scheduled
117 Assert
.assertFalse(hMaster
.getChoreService().isChoreScheduled(regionsRecoveryChore
));
120 // Make it public so that JVMClusterUtil can access it.
121 public static class TestHMaster
extends HMaster
{
122 public TestHMaster(Configuration conf
) throws IOException
{
128 * Simple helper class that just keeps track of whether or not its stopped.
130 private static class StoppableImplementation
implements Stoppable
{
132 private boolean stop
= false;
135 public void stop(String why
) {
140 public boolean isStopped() {