|
|
|
@ -18,24 +18,45 @@ package org.springframework.scheduling.support;
@@ -18,24 +18,45 @@ package org.springframework.scheduling.support;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Calendar; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.GregorianCalendar; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.TimeZone; |
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.junit.runners.Parameterized; |
|
|
|
|
import org.junit.runners.Parameterized.Parameters; |
|
|
|
|
import org.springframework.scheduling.TriggerContext; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Dave Syer |
|
|
|
|
* @author Mark Fisher |
|
|
|
|
*/ |
|
|
|
|
@RunWith(Parameterized.class) |
|
|
|
|
public class CronTriggerTests { |
|
|
|
|
|
|
|
|
|
private Calendar calendar = new GregorianCalendar(); |
|
|
|
|
|
|
|
|
|
private Date date = new Date(); |
|
|
|
|
private final Date date; |
|
|
|
|
|
|
|
|
|
private final TimeZone timeZone; |
|
|
|
|
|
|
|
|
|
public CronTriggerTests(Date date, TimeZone timeZone) { |
|
|
|
|
this.timeZone = timeZone; |
|
|
|
|
this.date = date; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@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("CET")}); |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param calendar |
|
|
|
@ -48,20 +69,21 @@ public class CronTriggerTests {
@@ -48,20 +69,21 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void setUp() { |
|
|
|
|
calendar.setTimeZone(timeZone); |
|
|
|
|
calendar.setTime(date); |
|
|
|
|
roundup(calendar); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMatchAll() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * * * *", timeZone); |
|
|
|
|
TriggerContext context = getTriggerContext(date); |
|
|
|
|
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMatchLastSecond() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * * * *", timeZone); |
|
|
|
|
GregorianCalendar calendar = new GregorianCalendar(); |
|
|
|
|
calendar.set(Calendar.SECOND, 58); |
|
|
|
|
assertMatchesNextSecond(trigger, calendar); |
|
|
|
@ -69,7 +91,7 @@ public class CronTriggerTests {
@@ -69,7 +91,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMatchSpecificSecond() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("10 * * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("10 * * * * *", timeZone); |
|
|
|
|
GregorianCalendar calendar = new GregorianCalendar(); |
|
|
|
|
calendar.set(Calendar.SECOND, 9); |
|
|
|
|
assertMatchesNextSecond(trigger, calendar); |
|
|
|
@ -77,7 +99,7 @@ public class CronTriggerTests {
@@ -77,7 +99,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementSecondByOne() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("11 * * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("11 * * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.SECOND, 10); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.SECOND, 1); |
|
|
|
@ -87,7 +109,7 @@ public class CronTriggerTests {
@@ -87,7 +109,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementSecondAndRollover() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("10 * * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("10 * * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.SECOND, 11); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.SECOND, 59); |
|
|
|
@ -97,7 +119,7 @@ public class CronTriggerTests {
@@ -97,7 +119,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSecondRange() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("10-15 * * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("10-15 * * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.SECOND, 9); |
|
|
|
|
assertMatchesNextSecond(trigger, calendar); |
|
|
|
|
calendar.set(Calendar.SECOND, 14); |
|
|
|
@ -106,7 +128,7 @@ public class CronTriggerTests {
@@ -106,7 +128,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementMinuteByOne() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 11 * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 11 * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MINUTE, 10); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.MINUTE, 1); |
|
|
|
@ -117,7 +139,7 @@ public class CronTriggerTests {
@@ -117,7 +139,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementMinute() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 * * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 * * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MINUTE, 10); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.MINUTE, 1); |
|
|
|
@ -131,7 +153,7 @@ public class CronTriggerTests {
@@ -131,7 +153,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementMinuteAndRollover() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 10 * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 10 * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MINUTE, 11); |
|
|
|
|
calendar.set(Calendar.SECOND, 0); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -142,7 +164,7 @@ public class CronTriggerTests {
@@ -142,7 +164,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementHour() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 9); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 30); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 11); |
|
|
|
@ -158,9 +180,28 @@ public class CronTriggerTests {
@@ -158,9 +180,28 @@ public class CronTriggerTests {
|
|
|
|
|
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementHourAndRollover() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 9); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 10); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 23); |
|
|
|
|
calendar.set(Calendar.MINUTE, 1); |
|
|
|
|
calendar.set(Calendar.SECOND, 0); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.set(Calendar.MINUTE, 0); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 11); |
|
|
|
|
TriggerContext context1 = getTriggerContext(date); |
|
|
|
|
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1)); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 1); |
|
|
|
|
TriggerContext context2 = getTriggerContext(date); |
|
|
|
|
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementDayOfMonth() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 1); |
|
|
|
@ -178,7 +219,7 @@ public class CronTriggerTests {
@@ -178,7 +219,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementDayOfMonthByOne() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * 10 * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * 10 * *", timeZone); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 9); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 1); |
|
|
|
@ -191,7 +232,7 @@ public class CronTriggerTests {
@@ -191,7 +232,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementDayOfMonthAndRollover() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * 10 * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * 10 * *", timeZone); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 11); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.MONTH, 1); |
|
|
|
@ -205,7 +246,7 @@ public class CronTriggerTests {
@@ -205,7 +246,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDailyTriggerInShortMonth() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 8); // September: 30 days
|
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 30); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -223,8 +264,26 @@ public class CronTriggerTests {
@@ -223,8 +264,26 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDailyTriggerInLongMonth() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 * * *"); |
|
|
|
|
calendar.set(Calendar.MONTH, 9); // October: 31 days
|
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 7); // August: 31 days and not a daylight saving boundary
|
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 30); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0); |
|
|
|
|
calendar.set(Calendar.MINUTE, 0); |
|
|
|
|
calendar.set(Calendar.SECOND, 0); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 31); |
|
|
|
|
TriggerContext context1 = getTriggerContext(date); |
|
|
|
|
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1)); |
|
|
|
|
calendar.set(Calendar.MONTH, 8); // September
|
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1); |
|
|
|
|
TriggerContext context2 = getTriggerContext(date); |
|
|
|
|
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDailyTriggerOnDaylightSavingBoundary() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 9); // October: 31 days and a daylight saving boundary in CET
|
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 30); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0); |
|
|
|
@ -241,7 +300,7 @@ public class CronTriggerTests {
@@ -241,7 +300,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementMonth() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 1 * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 9); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 30); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -257,9 +316,29 @@ public class CronTriggerTests {
@@ -257,9 +316,29 @@ public class CronTriggerTests {
|
|
|
|
|
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementMonthAndRollover() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 11); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 31); |
|
|
|
|
calendar.set(Calendar.YEAR, 2010); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0); |
|
|
|
|
calendar.set(Calendar.MINUTE, 0); |
|
|
|
|
calendar.set(Calendar.SECOND, 0); |
|
|
|
|
calendar.set(Calendar.MONTH, 0); |
|
|
|
|
calendar.set(Calendar.YEAR, 2011); |
|
|
|
|
TriggerContext context1 = getTriggerContext(date); |
|
|
|
|
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1)); |
|
|
|
|
calendar.set(Calendar.MONTH, 1); |
|
|
|
|
TriggerContext context2 = getTriggerContext(date); |
|
|
|
|
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMonthlyTriggerInLongMonth() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 31 * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 31 * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 9); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 30); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -273,7 +352,7 @@ public class CronTriggerTests {
@@ -273,7 +352,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMonthlyTriggerInShortMonth() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 1 * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MONTH, 9); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 30); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -288,7 +367,7 @@ public class CronTriggerTests {
@@ -288,7 +367,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementDayOfWeekByOne() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * * * 2"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * * * 2", timeZone); |
|
|
|
|
calendar.set(Calendar.DAY_OF_WEEK, 2); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.DAY_OF_WEEK, 1); |
|
|
|
@ -302,7 +381,7 @@ public class CronTriggerTests {
@@ -302,7 +381,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testIncrementDayOfWeekAndRollover() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * * * 2"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * * * 2", timeZone); |
|
|
|
|
calendar.set(Calendar.DAY_OF_WEEK, 4); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 6); |
|
|
|
@ -316,7 +395,7 @@ public class CronTriggerTests {
@@ -316,7 +395,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSpecificMinuteSecond() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("55 5 * * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("55 5 * * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MINUTE, 4); |
|
|
|
|
calendar.set(Calendar.SECOND, 54); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -331,7 +410,7 @@ public class CronTriggerTests {
@@ -331,7 +410,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSpecificHourSecond() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("55 * 2 * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("55 * 2 * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 1); |
|
|
|
|
calendar.set(Calendar.SECOND, 54); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -347,7 +426,7 @@ public class CronTriggerTests {
@@ -347,7 +426,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSpecificMinuteHour() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("* 5 10 * * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("* 5 10 * * *", timeZone); |
|
|
|
|
calendar.set(Calendar.MINUTE, 4); |
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 9); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -364,7 +443,7 @@ public class CronTriggerTests {
@@ -364,7 +443,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSpecificDayOfMonthSecond() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("55 * * 3 * *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("55 * * 3 * *", timeZone); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 2); |
|
|
|
|
calendar.set(Calendar.SECOND, 54); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -381,7 +460,7 @@ public class CronTriggerTests {
@@ -381,7 +460,7 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSpecificDate() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * 3 10 *"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("* * * 3 10 *", timeZone); |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 2); |
|
|
|
|
calendar.set(Calendar.MONTH, 10); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
@ -398,10 +477,10 @@ public class CronTriggerTests {
@@ -398,10 +477,10 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testWeekDaySequence() throws Exception { |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 7 ? * MON-FRI"); |
|
|
|
|
CronTrigger trigger = new CronTrigger("0 0 7 ? * MON-FRI", timeZone); |
|
|
|
|
// This is a Saturday
|
|
|
|
|
calendar.set(2009, 8, 26); |
|
|
|
|
date = calendar.getTime(); |
|
|
|
|
Date date = calendar.getTime(); |
|
|
|
|
// 7 am is the trigger time
|
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 7); |
|
|
|
|
calendar.set(Calendar.MINUTE, 0); |
|
|
|
@ -421,71 +500,71 @@ public class CronTriggerTests {
@@ -421,71 +500,71 @@ public class CronTriggerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDayOfWeekIndifferent() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * 2 * *"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * 2 * ?"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * 2 * *", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * 2 * ?", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSecondIncrementer() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("57,59 * * * * *"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("57/2 * * * * *"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("57,59 * * * * *", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("57/2 * * * * *", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSecondIncrementerWithRange() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("1,3,5 * * * * *"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("1-6/2 * * * * *"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("1,3,5 * * * * *", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("1-6/2 * * * * *", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testHourIncrementer() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * 4,8,12,16,20 * * *"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * 4/4 * * *"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * 4,8,12,16,20 * * *", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * 4/4 * * *", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDayNames() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * * 0-6"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * * TUE,WED,THU,FRI,SAT,SUN,MON"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * * 0-6", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * * TUE,WED,THU,FRI,SAT,SUN,MON", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSundayIsZero() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * * 0"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * * SUN"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * * 0", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * * SUN", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSundaySynonym() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * * 0"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * * 7"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * * 0", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * * 7", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMonthNames() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * 0-11 *"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * FEB,JAN,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC *"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * 0-11 *", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * FEB,JAN,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC *", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMonthNamesMixedCase() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * 1 *"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * Feb *"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * 1 *", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * Feb *", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testWhitespace() throws Exception { |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * 1 *"); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * 1 *"); |
|
|
|
|
CronTrigger trigger1 = new CronTrigger("* * * * 1 *", timeZone); |
|
|
|
|
CronTrigger trigger2 = new CronTrigger("* * * * 1 *", timeZone); |
|
|
|
|
assertEquals(trigger1, trigger2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|