org.springframework.scheduling.TriggerContext Java Examples
The following examples show how to use
org.springframework.scheduling.TriggerContext.
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 File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 #2
Source File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 #5
Source File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 #6
Source File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #8
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #9
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #10
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #11
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #12
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #13
Source File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 #14
Source File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 #15
Source File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 #17
Source File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 #18
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #19
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #20
Source File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 #21
Source File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 #22
Source File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 #23
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #24
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #25
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 6 votes |
@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 #26
Source File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 File: CronTriggerTests.java From spring-analysis-note with MIT License | 6 votes |
@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 #29
Source File: CronTriggerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testIncrementDayOfMonthByOne() throws Exception { CronTrigger trigger = new CronTrigger("* * * 10 * *", timeZone); calendar.set(Calendar.DAY_OF_MONTH, 9); Date date = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); TriggerContext context = getTriggerContext(date); assertEquals(calendar.getTime(), trigger.nextExecutionTime(context)); }
Example #30
Source File: CronTriggerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testMonthlyTriggerInLongMonth() throws Exception { 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(); calendar.set(Calendar.DAY_OF_MONTH, 31); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); TriggerContext context = getTriggerContext(date); assertEquals(calendar.getTime(), trigger.nextExecutionTime(context)); }