1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.master;
20
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.hbase.HBaseTestingUtility;
23 import org.apache.hadoop.hbase.MiniHBaseCluster;
24 import org.apache.hadoop.hbase.Stoppable;
25 import org.apache.hadoop.hbase.testclassification.MasterTests;
26 import org.apache.hadoop.hbase.testclassification.MediumTests;
27 import org.junit.After;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.experimental.categories.Category;
32
33
34
35
36 @Category({MasterTests.class, MediumTests.class})
37 public class TestRegionsRecoveryConfigManager {
38
39 private static final HBaseTestingUtility HBASE_TESTING_UTILITY = new HBaseTestingUtility();
40
41 private MiniHBaseCluster cluster;
42
43 private HMaster hMaster;
44
45 private RegionsRecoveryChore regionsRecoveryChore;
46
47 private RegionsRecoveryConfigManager regionsRecoveryConfigManager;
48
49 private Configuration conf;
50
51 @Before
52 public void setup() throws Exception {
53 conf = HBASE_TESTING_UTILITY.getConfiguration();
54 conf.unset("hbase.regions.recovery.store.file.ref.count");
55 conf.unset("hbase.master.regions.recovery.check.interval");
56 HBASE_TESTING_UTILITY.startMiniCluster(1, 1);
57 cluster = HBASE_TESTING_UTILITY.getMiniHBaseCluster();
58 }
59
60 @After
61 public void tearDown() throws Exception {
62 HBASE_TESTING_UTILITY.shutdownMiniCluster();
63 }
64
65 @Test
66 public void testChoreSchedule() throws Exception {
67
68 this.hMaster = cluster.getMaster();
69
70 Stoppable stoppable = new StoppableImplementation();
71 this.regionsRecoveryChore = new RegionsRecoveryChore(stoppable, conf, hMaster);
72
73 this.regionsRecoveryConfigManager = new RegionsRecoveryConfigManager(this.hMaster);
74
75 Assert.assertFalse(hMaster.getChoreService().isChoreScheduled(regionsRecoveryChore));
76
77 this.regionsRecoveryConfigManager.onConfigurationChange(conf);
78
79 Assert.assertFalse(hMaster.getChoreService().isChoreScheduled(regionsRecoveryChore));
80
81 conf.setInt("hbase.master.regions.recovery.check.interval", 10);
82 this.regionsRecoveryConfigManager.onConfigurationChange(conf);
83
84 Assert.assertFalse(hMaster.getChoreService().isChoreScheduled(regionsRecoveryChore));
85
86 conf.setInt("hbase.regions.recovery.store.file.ref.count", 10);
87 this.regionsRecoveryConfigManager.onConfigurationChange(conf);
88
89 Assert.assertTrue(hMaster.getChoreService().isChoreScheduled(regionsRecoveryChore));
90
91 conf.setInt("hbase.regions.recovery.store.file.ref.count", 20);
92 this.regionsRecoveryConfigManager.onConfigurationChange(conf);
93
94 Assert.assertTrue(hMaster.getChoreService().isChoreScheduled(regionsRecoveryChore));
95
96 conf.setInt("hbase.regions.recovery.store.file.ref.count", 20);
97 this.regionsRecoveryConfigManager.onConfigurationChange(conf);
98
99 Assert.assertTrue(hMaster.getChoreService().isChoreScheduled(regionsRecoveryChore));
100
101 conf.unset("hbase.regions.recovery.store.file.ref.count");
102 this.regionsRecoveryConfigManager.onConfigurationChange(conf);
103
104 Assert.assertFalse(hMaster.getChoreService().isChoreScheduled(regionsRecoveryChore));
105 }
106
107
108
109
110 private static class StoppableImplementation implements Stoppable {
111
112 private boolean stop = false;
113
114 @Override
115 public void stop(String why) {
116 this.stop = true;
117 }
118
119 @Override
120 public boolean isStopped() {
121 return this.stop;
122 }
123
124 }
125 }