I am working on writing an integration test using JUNIT. Due to @Retryable been used in one of the methods called in the test, I am getting
org.springframework.retry.backoff.BackOffInterruptedException when running the test. How to write an Integration Test when the methods involved are @Async or @Retryable ?
Here is the code for the test class and service class respectively-
public class TestEndpointIT {
@Autowired
EndpointService endpoint
@Test
void testMethod() throws DatatypeConfigurationException, ParseException {
ResponseMessage response = endpoint.testService(sm);
assertTrue(response.getResponse().getAckNakResponse() == ResponseType.ACK);
};
class EndpointService {
@Async
@Retryable(value = RuntimeException.class, maxAttempts = 3, backoff = @Backoff(delay = 30000))
@Override
public void testMethod() {
// Code
}
}...
Following is the stack trace for the same-
``` 2021-08-02 14:49:22.621 ERROR 121348 --- [ task-1] .a.i.SimpleAsyncUncaughtExceptionHandler : Unexpected exception occurred invoking async method: public void com.att.dtss.playlistadapter.service.ScheduleServiceImpl.processSchedule(com.att.dtss.playlistadapter.dto.ScheduleDto) throws javax.xml.datatype.DatatypeConfigurationException,java.text.ParseException
org.springframework.retry.backoff.BackOffInterruptedException: Thread interrupted while sleeping; nested exception is java.lang.InterruptedException: sleep interrupted
at org.springframework.retry.backoff.FixedBackOffPolicy.doBackOff(FixedBackOffPolicy.java:85) ~[spring-retry-1.3.1.jar:?]
at org.springframework.retry.backoff.StatelessBackOffPolicy.backOff(StatelessBackOffPolicy.java:36) ~[spring-retry-1.3.1.jar:?]
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:347) ~[spring-retry-1.3.1.jar:?]
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:209) ~[spring-retry-1.3.1.jar:?]
at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:119) ~[spring-retry-1.3.1.jar:?]
at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:163) ~[spring-retry-1.3.1.jar:?]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.8.jar:5.3.8]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar:5.3.8]
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115) ~[spring-aop-5.3.8.jar:5.3.8]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_291]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_291]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_291]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_291]
Caused by: java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method) ~[?:1.8.0_291]
at org.springframework.retry.backoff.ThreadWaitSleeper.sleep(ThreadWaitSleeper.java:31) ~[spring-retry-1.3.1.jar:?]
at org.springframework.retry.backoff.FixedBackOffPolicy.doBackOff(FixedBackOffPolicy.java:82) ~[spring-retry-1.3.1.jar:?]
... 12 more```