Fixed - validation of cron expression parameter of RScheduledExecutorService.schedule method #1494

pull/1547/head
Nikita 7 years ago
parent d090994d07
commit d06e1b5680

@ -850,6 +850,9 @@ public class RedissonExecutorService implements RScheduledExecutorService {
byte[] classBody = getClassBody(task); byte[] classBody = getClassBody(task);
byte[] state = encode(task); byte[] state = encode(task);
final Date startDate = cronSchedule.getExpression().getNextValidTimeAfter(new Date()); final Date startDate = cronSchedule.getExpression().getNextValidTimeAfter(new Date());
if (startDate == null) {
throw new IllegalArgumentException("Wrong cron expression! Unable to calculate start date");
}
long startTime = startDate.getTime(); long startTime = startDate.getTime();
RemotePromise<Void> result = (RemotePromise<Void>) asyncScheduledServiceAtFixed.schedule(task.getClass().getName(), classBody, state, startTime, cronSchedule.getExpression().getCronExpression(), executorId, null); RemotePromise<Void> result = (RemotePromise<Void>) asyncScheduledServiceAtFixed.schedule(task.getClass().getName(), classBody, state, startTime, cronSchedule.getExpression().getCronExpression(), executorId, null);
addListener(result); addListener(result);

@ -138,6 +138,12 @@ public class RedissonScheduledExecutorServiceTest extends BaseTest {
assertThat(redisson.getAtomicLong("executed").get()).isEqualTo(2); assertThat(redisson.getAtomicLong("executed").get()).isEqualTo(2);
} }
@Test(expected = IllegalArgumentException.class)
public void testWrongCronExpression() throws InterruptedException, ExecutionException {
RScheduledExecutorService executor = redisson.getExecutorService("test");
executor.schedule(new ScheduledRunnableTask("executed"), CronSchedule.of("0 44 12 19 JUN ? 2018"));
}
@Test @Test
public void testCronExpressionMultipleTasks() throws InterruptedException, ExecutionException { public void testCronExpressionMultipleTasks() throws InterruptedException, ExecutionException {
RScheduledExecutorService executor = redisson.getExecutorService("test"); RScheduledExecutorService executor = redisson.getExecutorService("test");

Loading…
Cancel
Save