From 6914aff825bfbf58291fa39a131471f312eafe04 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Sun, 10 Mar 2013 10:59:51 -0700 Subject: [PATCH] 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. --- .../scheduling/support/CronTriggerTests.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/spring-context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java b/spring-context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java index a34477496385..261ea34bd806 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java @@ -56,7 +56,7 @@ public CronTriggerTests(Date date, TimeZone timeZone) { @Parameters public static List getParameters() { List list = new ArrayList(); - 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 void testMonthSequence() throws Exception { 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();