View Javadoc

1   /*
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
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
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.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("hbase.offpeak.start.hour", hourMinusOne);
65      conf.setLong("hbase.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("hbase.offpeak.start.hour", hourMinusTwo);
73      conf.setLong("hbase.offpeak.end.hour", hourMinusOne);
74      OffPeakHours target = OffPeakHours.getInstance(conf);
75      assertFalse(target.isOffPeakHour(hourOfDay));
76    }
77  }