1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver.compactions;
19
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.hbase.HBaseTestingUtility;
25 import org.apache.hadoop.hbase.testclassification.SmallTests;
26 import org.junit.Before;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31 @Category(SmallTests.class)
32 public class TestOffPeakHours {
33 private static HBaseTestingUtility testUtil;
34
35 @BeforeClass
36 public static void setUpClass() {
37 testUtil = new HBaseTestingUtility();
38 }
39
40 private int hourOfDay;
41 private int hourPlusOne;
42 private int hourMinusOne;
43 private int hourMinusTwo;
44 private Configuration conf;
45
46 @Before
47 public void setUp() {
48 hourOfDay = 15;
49 hourPlusOne = ((hourOfDay+1)%24);
50 hourMinusOne = ((hourOfDay-1+24)%24);
51 hourMinusTwo = ((hourOfDay-2+24)%24);
52 conf = testUtil.getConfiguration();
53 }
54
55 @Test
56 public void testWithoutSettings() {
57 Configuration conf = testUtil.getConfiguration();
58 OffPeakHours target = OffPeakHours.getInstance(conf);
59 assertFalse(target.isOffPeakHour(hourOfDay));
60 }
61
62 @Test
63 public void testSetPeakHourToTargetTime() {
64 conf.setLong(CompactionConfiguration.HBASE_HSTORE_OFFPEAK_START_HOUR, hourMinusOne);
65 conf.setLong(CompactionConfiguration.HBASE_HSTORE_OFFPEAK_END_HOUR, hourPlusOne);
66 OffPeakHours target = OffPeakHours.getInstance(conf);
67 assertTrue(target.isOffPeakHour(hourOfDay));
68 }
69
70 @Test
71 public void testSetPeakHourOutsideCurrentSelection() {
72 conf.setLong(CompactionConfiguration.HBASE_HSTORE_OFFPEAK_START_HOUR, hourMinusTwo);
73 conf.setLong(CompactionConfiguration.HBASE_HSTORE_OFFPEAK_END_HOUR, hourMinusOne);
74 OffPeakHours target = OffPeakHours.getInstance(conf);
75 assertFalse(target.isOffPeakHour(hourOfDay));
76 }
77 }