support through all day offPeak to cover all the usage scenario

This commit is contained in:
tianliuliu 2022-11-21 10:29:11 +08:00
parent f68b61a027
commit 185ecb87e5
2 changed files with 17 additions and 3 deletions

View File

@ -46,7 +46,7 @@ public abstract class OffPeakHours {
/**
* @param startHour inclusive
* @param endHour exclusive
* @param endHour inclusive
*/
public static OffPeakHours getInstance(int startHour, int endHour) {
if (startHour == -1 && endHour == -1) {
@ -84,7 +84,7 @@ public abstract class OffPeakHours {
/**
* @param startHour inclusive
* @param endHour exclusive
* @param endHour inclusive
*/
OffPeakHoursImpl(int startHour, int endHour) {
this.startHour = startHour;
@ -99,7 +99,7 @@ public abstract class OffPeakHours {
@Override
public boolean isOffPeakHour(int targetHour) {
if (startHour <= endHour) {
return startHour <= targetHour && targetHour < endHour;
return startHour <= targetHour && targetHour <= endHour;
}
return targetHour < endHour || startHour <= targetHour;
}

View File

@ -49,6 +49,8 @@ public class TestOffPeakHours {
private int hourPlusOne;
private int hourMinusOne;
private int hourMinusTwo;
private int hourAllDayStart;
private int hourAllDayEnd;
private Configuration conf;
@Before
@ -57,6 +59,8 @@ public class TestOffPeakHours {
hourPlusOne = ((hourOfDay + 1) % 24);
hourMinusOne = ((hourOfDay - 1 + 24) % 24);
hourMinusTwo = ((hourOfDay - 2 + 24) % 24);
hourAllDayStart = 0;
hourAllDayEnd = 23;
conf = testUtil.getConfiguration();
}
@ -82,4 +86,14 @@ public class TestOffPeakHours {
OffPeakHours target = OffPeakHours.getInstance(conf);
assertFalse(target.isOffPeakHour(hourOfDay));
}
@Test
public void testSetPeakHourAllDay() {
conf.setLong(CompactionConfiguration.HBASE_HSTORE_OFFPEAK_START_HOUR, hourAllDayStart);
conf.setLong(CompactionConfiguration.HBASE_HSTORE_OFFPEAK_END_HOUR, hourAllDayEnd);
OffPeakHours target = OffPeakHours.getInstance(conf);
assertTrue(target.isOffPeakHour(hourAllDayStart));
assertTrue(target.isOffPeakHour(hourOfDay));
assertTrue(target.isOffPeakHour(hourAllDayEnd));
}
}