|
20 | 20 | import static org.junit.Assert.assertEquals; |
21 | 21 |
|
22 | 22 | import java.util.Date; |
| 23 | +import java.util.List; |
23 | 24 | import java.util.TimeZone; |
24 | 25 | import org.apache.hadoop.hbase.HBaseClassTestRule; |
25 | 26 | import org.apache.hadoop.hbase.testclassification.RegionServerTests; |
26 | 27 | import org.apache.hadoop.hbase.testclassification.SmallTests; |
27 | 28 | import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; |
28 | 29 | import org.junit.ClassRule; |
29 | | -import org.junit.Ignore; |
30 | 30 | import org.junit.Test; |
31 | 31 | import org.junit.experimental.categories.Category; |
32 | 32 |
|
33 | | -@Category({RegionServerTests.class, SmallTests.class}) |
34 | | -@Ignore("See HBASE-25385") |
| 33 | +import org.apache.hbase.thirdparty.com.google.common.collect.Lists; |
| 34 | + |
| 35 | +@Category({ RegionServerTests.class, SmallTests.class }) |
35 | 36 | public class TestCurrentHourProvider { |
| 37 | + |
36 | 38 | @ClassRule |
37 | 39 | public static final HBaseClassTestRule CLASS_RULE = |
38 | | - HBaseClassTestRule.forClass(TestCurrentHourProvider.class); |
| 40 | + HBaseClassTestRule.forClass(TestCurrentHourProvider.class); |
| 41 | + |
| 42 | + private static final List<String> ZONE_IDS = Lists.newArrayList("UTC", "US/Pacific", "Etc/GMT+8"); |
39 | 43 |
|
40 | 44 | /** |
41 | | - * In timezone GMT+08:00, the unix time of 2020-08-20 11:52:41 is 1597895561000 |
42 | | - * and the unix time of 2020-08-20 15:04:00 is 1597907081000, |
43 | | - * by calculating the delta time to get expected time in current timezone, |
44 | | - * then we can get special hour no matter which timezone it runs. |
45 | | - * |
46 | | - * In addition, we should consider the Daylight Saving Time. |
47 | | - * 1. If in DaylightTime, we need reduce one hour. |
48 | | - * 2. If in DaylightTime and timezone is "Antarctica/Troll", we need reduce two hours. |
| 45 | + * In timezone GMT+08:00, the unix time of 2020-08-20 11:52:41 is 1597895561000 and the unix time |
| 46 | + * of 2020-08-20 15:04:00 is 1597907081000, by calculating the delta time to get expected time in |
| 47 | + * current timezone, then we can get special hour no matter which timezone it runs. |
| 48 | + * <p/> |
| 49 | + * In addition, we should consider the Daylight Saving Time. If in DaylightTime, we need reduce |
| 50 | + * one hour. |
49 | 51 | */ |
50 | 52 | @Test |
51 | 53 | public void testWithEnvironmentEdge() { |
52 | 54 | // test for all available zoneID |
53 | | - for (String zoneID : TimeZone.getAvailableIDs()) { |
| 55 | + for (String zoneID : ZONE_IDS) { |
54 | 56 | TimeZone timezone = TimeZone.getTimeZone(zoneID); |
55 | 57 | TimeZone.setDefault(timezone); |
56 | 58 |
|
57 | 59 | // set a time represent hour 11 |
58 | 60 | long deltaFor11 = TimeZone.getDefault().getRawOffset() - 28800000; |
59 | 61 | long timeFor11 = 1597895561000L - deltaFor11; |
60 | 62 | EnvironmentEdgeManager.injectEdge(() -> timeFor11); |
61 | | - CurrentHourProvider.tick = CurrentHourProvider.nextTick(); |
| 63 | + CurrentHourProvider.advanceTick(); |
62 | 64 | int hour11 = CurrentHourProvider.getCurrentHour(); |
63 | 65 | if (TimeZone.getDefault().inDaylightTime(new Date(timeFor11))) { |
64 | | - hour11 = "Antarctica/Troll".equals(zoneID) ? |
65 | | - CurrentHourProvider.getCurrentHour() - 2 : |
66 | | - CurrentHourProvider.getCurrentHour() - 1; |
| 66 | + hour11 = CurrentHourProvider.getCurrentHour() - 1; |
67 | 67 | } |
68 | 68 | assertEquals(11, hour11); |
69 | 69 |
|
70 | 70 | // set a time represent hour 15 |
71 | 71 | long deltaFor15 = TimeZone.getDefault().getRawOffset() - 28800000; |
72 | 72 | long timeFor15 = 1597907081000L - deltaFor15; |
73 | 73 | EnvironmentEdgeManager.injectEdge(() -> timeFor15); |
74 | | - CurrentHourProvider.tick = CurrentHourProvider.nextTick(); |
| 74 | + CurrentHourProvider.advanceTick(); |
75 | 75 | int hour15 = CurrentHourProvider.getCurrentHour(); |
76 | 76 | if (TimeZone.getDefault().inDaylightTime(new Date(timeFor15))) { |
77 | | - hour15 = "Antarctica/Troll".equals(zoneID) ? |
78 | | - CurrentHourProvider.getCurrentHour() - 2 : |
79 | | - CurrentHourProvider.getCurrentHour() - 1; |
| 77 | + hour15 = CurrentHourProvider.getCurrentHour() - 1; |
80 | 78 | } |
81 | 79 | assertEquals(15, hour15); |
82 | 80 | } |
|
0 commit comments