A very simple HelloWorld Test
@Log4j2
@Service
@EnableRetry
@EnableScheduling
public class MyBeanImpl {
@Scheduled(cron = "0/2 * * * * ? ")
@Retryable(value = {RuntimeException.class}, maxAttempts = 4, backoff = @Backoff(delay = 10000))
public void sched() {
log.info("Foo sched a = {}", a++);
throw new RuntimeException("Foo");
}
}
@Recover
public void recover(RuntimeException e) {
//.....
}
// Junit Class is here , For Simple POC test, I dont use Interface class, just use Implementation class
@RunWith(SpringRunner.class)
@SpringBootTest
@Log4j2
@ContextConfiguration
public class MyBeanImplTest {
@Autowired
MyBeanImpl _myBean;
private String input = "HelloWorld";
@Test
public void sched() {
_myBean.sched();
}
Question :
I set maxAttempts = 1, it runs 1 time. why?
I set maxAttempts = 2, it always run 3 times. why?
I set maxAttempts = 4, however it runs 8 times. why?
I set maxAttempts = 6, it runs 11 times. why?