Java Code Examples for org.springframework.scheduling.TriggerContext

The following examples show how to use org.springframework.scheduling.TriggerContext. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testIncrementHour() throws Exception {
	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);
	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, 12);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.HOUR_OF_DAY, 13);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
Example 2
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@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));
}
 
Example 3
Source Project: spring4-understanding   Source File: CronTriggerTests.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 4
Source Project: spring4-understanding   Source File: CronTriggerTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSpecificDate() throws Exception {
	CronTrigger trigger = new CronTrigger("* * * 3 11 *", timeZone);
	calendar.set(Calendar.DAY_OF_MONTH, 2);
	calendar.set(Calendar.MONTH, 9);
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MONTH, 10); // 10=November
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.SECOND, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
Example 5
Source Project: spring4-understanding   Source File: CronTriggerTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWeekDaySequence() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 7 ? * MON-FRI", timeZone);
	// This is a Saturday
	calendar.set(2009, 8, 26);
	Date date = calendar.getTime();
	// 7 am is the trigger time
	calendar.set(Calendar.HOUR_OF_DAY, 7);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	// Add two days because we start on Saturday
	calendar.add(Calendar.DAY_OF_MONTH, 2);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// Next day is a week day so add one
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context3 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context3));
}
 
Example 6
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testDailyTriggerInLongMonth() throws Exception {
	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));
}
 
Example 7
Source Project: spring4-understanding   Source File: CronTriggerTests.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 8
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testIncrementMonth() throws Exception {
	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();
	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, 10);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.MONTH, 11);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
Example 9
Source Project: spring4-understanding   Source File: CronTriggerTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLeapYearSpecificDate() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 29 2 *", timeZone);
	calendar.set(Calendar.YEAR, 2007);
	calendar.set(Calendar.DAY_OF_MONTH, 10);
	calendar.set(Calendar.MONTH, 1); // 2=February
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.set(Calendar.YEAR, 2008);
	calendar.set(Calendar.DAY_OF_MONTH, 29);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.YEAR, 4);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
Example 10
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testSpecificMinuteHour() throws Exception {
	CronTrigger trigger = new CronTrigger("* 5 10 * * *", timeZone);
	calendar.set(Calendar.MINUTE, 4);
	calendar.set(Calendar.HOUR_OF_DAY, 9);
	Date date = calendar.getTime();
	calendar.add(Calendar.MINUTE, 1);
	calendar.add(Calendar.HOUR_OF_DAY, 1);
	calendar.set(Calendar.SECOND, 0);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// next trigger is in one second because second is wildcard
	calendar.add(Calendar.SECOND, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
Example 11
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testSpecificDayOfMonthSecond() throws Exception {
	CronTrigger trigger = new CronTrigger("55 * * 3 * *", timeZone);
	calendar.set(Calendar.DAY_OF_MONTH, 2);
	calendar.set(Calendar.SECOND, 54);
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 55);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.MINUTE, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
Example 12
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testSpecificDate() throws Exception {
	CronTrigger trigger = new CronTrigger("* * * 3 11 *", timeZone);
	calendar.set(Calendar.DAY_OF_MONTH, 2);
	calendar.set(Calendar.MONTH, 9);
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MONTH, 10); // 10=November
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.SECOND, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
Example 13
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testMonthSequence() throws Exception {
	CronTrigger trigger = new CronTrigger("0 30 23 30 1/3 ?", timeZone);
	calendar.set(2010, 11, 30);
	Date date = calendar.getTime();
	// set expected next trigger time
	calendar.set(Calendar.HOUR_OF_DAY, 23);
	calendar.set(Calendar.MINUTE, 30);
	calendar.set(Calendar.SECOND, 0);
	calendar.add(Calendar.MONTH, 1);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// Next trigger is 3 months latter
	calendar.add(Calendar.MONTH, 3);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
	// Next trigger is 3 months latter
	calendar.add(Calendar.MONTH, 3);
	TriggerContext context3 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context3));
}
 
Example 14
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@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));
}
 
Example 15
Source Project: spring4-understanding   Source File: CronTriggerTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDailyTriggerInLongMonth() throws Exception {
	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));
}
 
Example 16
Source Project: spring4-understanding   Source File: CronTriggerTests.java    License: Apache License 2.0 6 votes vote down vote up
@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);
	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, 10); // November
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
Example 17
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testDailyTriggerInShortMonth() throws Exception {
	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();
	calendar.set(Calendar.MONTH, 9); // October
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.DAY_OF_MONTH, 2);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
Example 18
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testDailyTriggerInLongMonth() throws Exception {
	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));
}
 
Example 19
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@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);
	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, 10); // November
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
Example 20
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testIncrementMonth() throws Exception {
	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();
	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, 10);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.MONTH, 11);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
Example 21
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@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));
}
 
Example 22
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testSpecificMinuteHour() throws Exception {
	CronTrigger trigger = new CronTrigger("* 5 10 * * *", timeZone);
	calendar.set(Calendar.MINUTE, 4);
	calendar.set(Calendar.HOUR_OF_DAY, 9);
	Date date = calendar.getTime();
	calendar.add(Calendar.MINUTE, 1);
	calendar.add(Calendar.HOUR_OF_DAY, 1);
	calendar.set(Calendar.SECOND, 0);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// next trigger is in one second because second is wildcard
	calendar.add(Calendar.SECOND, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
Example 23
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testSpecificDayOfMonthSecond() throws Exception {
	CronTrigger trigger = new CronTrigger("55 * * 3 * *", timeZone);
	calendar.set(Calendar.DAY_OF_MONTH, 2);
	calendar.set(Calendar.SECOND, 54);
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 55);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.MINUTE, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
Example 24
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testLeapYearSpecificDate() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 29 2 *", timeZone);
	calendar.set(Calendar.YEAR, 2007);
	calendar.set(Calendar.DAY_OF_MONTH, 10);
	calendar.set(Calendar.MONTH, 1); // 2=February
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.set(Calendar.YEAR, 2008);
	calendar.set(Calendar.DAY_OF_MONTH, 29);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.YEAR, 4);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
Example 25
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testWeekDaySequence() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 7 ? * MON-FRI", timeZone);
	// This is a Saturday
	calendar.set(2009, 8, 26);
	Date date = calendar.getTime();
	// 7 am is the trigger time
	calendar.set(Calendar.HOUR_OF_DAY, 7);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	// Add two days because we start on Saturday
	calendar.add(Calendar.DAY_OF_MONTH, 2);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// Next day is a week day so add one
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context3 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context3));
}
 
Example 26
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testMonthSequence() throws Exception {
	CronTrigger trigger = new CronTrigger("0 30 23 30 1/3 ?", timeZone);
	calendar.set(2010, 11, 30);
	Date date = calendar.getTime();
	// set expected next trigger time
	calendar.set(Calendar.HOUR_OF_DAY, 23);
	calendar.set(Calendar.MINUTE, 30);
	calendar.set(Calendar.SECOND, 0);
	calendar.add(Calendar.MONTH, 1);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// Next trigger is 3 months latter
	calendar.add(Calendar.MONTH, 3);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
	// Next trigger is 3 months latter
	calendar.add(Calendar.MONTH, 3);
	TriggerContext context3 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context3));
}
 
Example 27
Source Project: java-technology-stack   Source File: CronTriggerTests.java    License: MIT License 6 votes vote down vote up
@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));
}
 
Example 28
Source Project: spring4-understanding   Source File: CronTriggerTests.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 29
Source Project: spring-analysis-note   Source File: PeriodicTrigger.java    License: MIT License 5 votes vote down vote up
/**
 * Returns the time after which a task should run again.
 */
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
	Date lastExecution = triggerContext.lastScheduledExecutionTime();
	Date lastCompletion = triggerContext.lastCompletionTime();
	if (lastExecution == null || lastCompletion == null) {
		return new Date(System.currentTimeMillis() + this.initialDelay);
	}
	if (this.fixedRate) {
		return new Date(lastExecution.getTime() + this.period);
	}
	return new Date(lastCompletion.getTime() + this.period);
}
 
Example 30
Source Project: spring-analysis-note   Source File: CronTriggerTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testIncrementSecondByOne() throws Exception {
	CronTrigger trigger = new CronTrigger("11 * * * * *", timeZone);
	calendar.set(Calendar.SECOND, 10);
	Date date = calendar.getTime();
	calendar.add(Calendar.SECOND, 1);
	TriggerContext context = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context));
}