提交 6914aff8 编写于 作者: D Dave Syer 提交者: Sam Brannen

Add additional test for daylight savings glitch

The problem was that clocks go forward *at* 2am, so
2am doesn't exist once a year. Users might be surprised
that their cron trigger doesn't go off one night, but that
is arguably correct (and what happens now). The test can be
modified if we decide to change the trigger behaviour.
上级 41716464
......@@ -56,7 +56,7 @@ public class CronTriggerTests {
@Parameters
public static List<Object[]> getParameters() {
List<Object[]> list = new ArrayList<Object[]>();
list.add(new Object[] { new Date(), TimeZone.getDefault() });
list.add(new Object[] { new Date(), TimeZone.getTimeZone("PST") });
list.add(new Object[] { new Date(), TimeZone.getTimeZone("CET") });
return list;
}
......@@ -694,6 +694,26 @@ public class CronTriggerTests {
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context3));
}
@Test
public void testDaylightSavingMissingHour() throws Exception {
// This trigger has to be somewhere in between 2am and 3am
CronTrigger trigger = new CronTrigger("0 10 2 * * *", timeZone);
calendar.set(Calendar.DAY_OF_MONTH, 31);
calendar.set(Calendar.MONTH, Calendar.MARCH);
calendar.set(Calendar.YEAR, 2013);
calendar.set(Calendar.HOUR_OF_DAY, 1);
calendar.set(Calendar.SECOND, 54);
Date date = calendar.getTime();
TriggerContext context1 = getTriggerContext(date);
if (timeZone.equals(TimeZone.getTimeZone("CET"))) {
// Clocks go forward an hour so 2am doesn't exist in CET for this date
calendar.add(Calendar.DAY_OF_MONTH, 1);
}
calendar.add(Calendar.HOUR_OF_DAY, 1);
calendar.set(Calendar.MINUTE, 10);
calendar.set(Calendar.SECOND, 0);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
}
private void assertMatchesNextSecond(CronTrigger trigger, Calendar calendar) {
Date date = calendar.getTime();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册