This is an automated email from the ASF dual-hosted git repository.
reidchan pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-1 by this push:
new c9d03c4 HBASE-25740 - Backport HBASE-25629 to branch-1 (#3130)
c9d03c4 is described below
commit c9d03c446d3b91007c99e34ed234b3ac9e3750b9
Author: Geoffrey Jacoby <[email protected]>
AuthorDate: Wed Apr 7 00:47:47 2021 -0700
HBASE-25740 - Backport HBASE-25629 to branch-1 (#3130)
Signed-off-by Reid Chan <[email protected]>
---
.../compactions/CurrentHourProvider.java | 18 ++++++++----
.../compactions/TestCurrentHourProvider.java | 32 ++++++++++------------
2 files changed, 28 insertions(+), 22 deletions(-)
diff --git
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CurrentHourProvider.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CurrentHourProvider.java
index 7eb93c7..7dd6f75 100644
---
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CurrentHourProvider.java
+++
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CurrentHourProvider.java
@@ -24,7 +24,10 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
@InterfaceAudience.Private
public class CurrentHourProvider {
- private CurrentHourProvider() { throw new AssertionError(); }
+
+ private CurrentHourProvider() {
+ throw new AssertionError();
+ }
private static final class Tick {
final int currentHour;
@@ -36,7 +39,7 @@ public class CurrentHourProvider {
}
}
- static Tick nextTick() {
+ private static Tick nextTick() {
Calendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(EnvironmentEdgeManager.currentTime());
int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
@@ -51,15 +54,20 @@ public class CurrentHourProvider {
calendar.set(Calendar.MILLISECOND, 0);
}
- static volatile Tick tick = nextTick();
+ private static volatile Tick tick = nextTick();
public static int getCurrentHour() {
Tick tick = CurrentHourProvider.tick;
if (EnvironmentEdgeManager.currentTime() < tick.expirationTimeInMillis) {
return tick.currentHour;
}
-
- CurrentHourProvider.tick = tick = nextTick();
+ tick = nextTick();
+ CurrentHourProvider.tick = tick;
return tick.currentHour;
}
+
+ //RestrictedApi - only to be called for tests
+ static void advanceTick() {
+ tick = nextTick();
+ }
}
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCurrentHourProvider.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCurrentHourProvider.java
index 7e98570..fbfa6cd 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCurrentHourProvider.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCurrentHourProvider.java
@@ -19,7 +19,9 @@ package org.apache.hadoop.hbase.regionserver.compactions;
import static org.junit.Assert.assertEquals;
+import com.google.common.collect.Lists;
import java.util.Date;
+import java.util.List;
import java.util.TimeZone;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
@@ -31,20 +33,20 @@ import org.junit.experimental.categories.Category;
@Category({RegionServerTests.class, SmallTests.class})
public class TestCurrentHourProvider {
+ private static final List<String> ZONE_IDS = Lists.newArrayList("UTC",
"US/Pacific", "Etc/GMT+8");
+
/**
- * In timezone GMT+08:00, the unix time of 2020-08-20 11:52:41 is
1597895561000
- * and the unix time of 2020-08-20 15:04:00 is 1597907081000,
- * by calculating the delta time to get expected time in current timezone,
- * then we can get special hour no matter which timezone it runs.
- *
- * In addition, we should consider the Daylight Saving Time.
- * 1. If in DaylightTime, we need reduce one hour.
- * 2. If in DaylightTime and timezone is "Antarctica/Troll", we need reduce
two hours.
+ * In timezone GMT+08:00, the unix time of 2020-08-20 11:52:41 is
1597895561000 and the unix time
+ * of 2020-08-20 15:04:00 is 1597907081000, by calculating the delta time to
get expected time in
+ * current timezone, then we can get special hour no matter which timezone
it runs.
+ * <p/>
+ * In addition, we should consider the Daylight Saving Time. If in
DaylightTime, we need reduce
+ * one hour.
*/
@Test
public void testWithEnvironmentEdge() {
// test for all available zoneID
- for (String zoneID : TimeZone.getAvailableIDs()) {
+ for (String zoneID : ZONE_IDS) {
TimeZone timezone = TimeZone.getTimeZone(zoneID);
TimeZone.setDefault(timezone);
@@ -57,12 +59,10 @@ public class TestCurrentHourProvider {
return timeFor11;
}
});
- CurrentHourProvider.tick = CurrentHourProvider.nextTick();
+ CurrentHourProvider.advanceTick();
int hour11 = CurrentHourProvider.getCurrentHour();
if (TimeZone.getDefault().inDaylightTime(new Date(timeFor11))) {
- hour11 = "Antarctica/Troll".equals(zoneID) ?
- CurrentHourProvider.getCurrentHour() - 2 :
- CurrentHourProvider.getCurrentHour() - 1;
+ hour11 = CurrentHourProvider.getCurrentHour() - 1;
}
assertEquals(11, hour11);
@@ -75,12 +75,10 @@ public class TestCurrentHourProvider {
return timeFor15;
}
});
- CurrentHourProvider.tick = CurrentHourProvider.nextTick();
+ CurrentHourProvider.advanceTick();
int hour15 = CurrentHourProvider.getCurrentHour();
if (TimeZone.getDefault().inDaylightTime(new Date(timeFor15))) {
- hour15 = "Antarctica/Troll".equals(zoneID) ?
- CurrentHourProvider.getCurrentHour() - 2 :
- CurrentHourProvider.getCurrentHour() - 1;
+ hour15 = CurrentHourProvider.getCurrentHour() - 1;
}
assertEquals(15, hour15);
}