|
15 | 15 |
|
16 | 16 | public class Issue363Test { |
17 | 17 |
|
18 | | - //@Test |
19 | | - public void quartzNextExecutionTime() { |
| 18 | + @Test |
| 19 | + public void everySecondOfMinute01Test() { |
| 20 | + // every second of the first minute of every hour/day/year |
20 | 21 | String cronExpression = "* 1 * * * ?"; |
| 22 | + CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)); |
| 23 | + ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(cronExpression)); |
| 24 | + |
| 25 | + ZonedDateTime now = ZonedDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); |
| 26 | + Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(now); |
| 27 | + |
| 28 | + assertTrue(nextExecution.isPresent()); |
| 29 | + // First match should be 2019-01-01T00:01:00Z |
| 30 | + ZonedDateTime expectedTime = ZonedDateTime.of(2019, 1, 1, 0, 1, 0, 0, ZoneOffset.UTC); |
| 31 | + assertEquals(expectedTime, nextExecution.get()); |
| 32 | + |
| 33 | + // Should also match the next 59 seconds |
| 34 | + for (int i = 1; i <= 59; i++) { |
| 35 | + nextExecution = executionTime.nextExecution(nextExecution.get()); |
| 36 | + assertTrue(nextExecution.isPresent()); |
| 37 | + assertEquals(expectedTime.plusSeconds(i), nextExecution.get()); |
| 38 | + } |
| 39 | + |
| 40 | + // After the every second of 00:01, it the next execution should be at 01:01:00Z |
| 41 | + nextExecution = executionTime.nextExecution(ZonedDateTime.of(2019, 1, 1, 0, 1, 59, 0, ZoneOffset.UTC)); |
| 42 | + assertTrue(nextExecution.isPresent()); |
| 43 | + expectedTime = ZonedDateTime.of(2019, 1, 1, 1, 1, 0, 0, ZoneOffset.UTC); |
| 44 | + assertEquals(expectedTime, nextExecution.get()); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void everyMinute01Test() { |
| 49 | + // every minute 1 of every hour/day/year |
| 50 | + String cronExpression = "0 1 * * * ?"; |
21 | 51 | ZonedDateTime now = ZonedDateTime.of(2019, 1, 1, 0, 1, 0, 0, ZoneOffset.UTC); |
22 | 52 | CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)); |
23 | 53 |
|
|
0 commit comments