ImmediateRetryPolicy implements SchedulerRetryPolicy { public SchedulerRetryAction getRetryAction(ScheduledTask task) { if (task == null) { throw new IllegalArgumentException("task cannot be null"); } Throwable result = task.getLastFailure(); if (result == null) { throw new IllegalStateException("task's last failure " + "cannot be null"); } if ((result instanceof ExceptionRetryStatus) && (((ExceptionRetryStatus) result).shouldRetry())) { if (task.getTryCount() % retryWarningThreshold == 0) { logger.logThrow(Level.WARNING, task.getLastFailure(), "Task has been retried {0} times: {1}", task.getTryCount(), task); } return SchedulerRetryAction.RETRY_NOW; } else { if (logger.isLoggable(Level.FINE)) { if (task.isRecurring()) { logger.log(Level.FINE, "skipping a recurrence of a task because it " + "failed with a non-retryable exception: {0}", task); } else { logger.log(Level.FINE, "dropping a task because it failed with a " + "non-retryable exception: {0}", task); } } return SchedulerRetryAction.DROP; } } ImmediateRetryPolicy(Properties properties); SchedulerRetryAction getRetryAction(ScheduledTask task);  }
@Test(expected=IllegalArgumentException.class) public void testNullTask() { policy.getRetryAction(null); }
@Test(expected=IllegalStateException.class) public void testNullResult() { setupTask(null); replayMocks(); policy.getRetryAction(task); }
@Test public void testRetryableTrueResult() { setupTask(new RetryableException(true)); EasyMock.expect(task.getTryCount()).andStubReturn(1); replayMocks(); SchedulerRetryAction action = policy.getRetryAction(task); Assert.assertEquals(SchedulerRetryAction.RETRY_NOW, action); verifyMocks(); }
@Test public void testRetryableFalseResult() { setupTask(new RetryableException(false)); EasyMock.expect(task.isRecurring()).andStubReturn(true); replayMocks(); SchedulerRetryAction action = policy.getRetryAction(task); Assert.assertEquals(SchedulerRetryAction.DROP, action); verifyMocks(); }
@Test public void testNotRetryableExceptionAndRecurringTask() { setupTask(new Exception()); EasyMock.expect(task.isRecurring()).andStubReturn(true); replayMocks(); SchedulerRetryAction action = policy.getRetryAction(task); Assert.assertEquals(SchedulerRetryAction.DROP, action); verifyMocks(); }
@Test public void testNotRetryableExceptionAndNotRecurringTask() { setupTask(new Exception()); EasyMock.expect(task.isRecurring()).andStubReturn(false); replayMocks(); SchedulerRetryAction action = policy.getRetryAction(task); Assert.assertEquals(SchedulerRetryAction.DROP, action); verifyMocks(); }