Skip to content

Spring-Retry @Retryable not working with Spring-data Repositories #214

@jopuneet

Description

@jopuneet

I was trying @retryable with Spring-data and testing it out using Mockito @MockBean but the retry for the repository is not working and it was always called only once.

@Repository
public interface TestRepository extends CrudRepository<Test, String> {

  @Retryable(value = { Exception.class }, maxAttempts = 4, backoff = @Backoff(delay = 2000))
  List<Test> findAll();
}
when(testRepository.findAll())
            .thenThrow(new RecoverableDataAccessException("test RecoverableDataAccessException 1"))
            .thenThrow(new RecoverableDataAccessException("test RecoverableDataAccessException 2"))
            .thenReturn(Lists.newArrayList(test));
verify(testRepository, times(3)).findAll(any());
org.mockito.exceptions.verification.TooFewActualInvocations: 
testRepository bean.findAll(<any string>);
Wanted 3 times:
-> at com.*.findAllTest(TestIT.java:10)
But was 1 time:

Referring to this Stackoverflow answer

Spring-boot: 2.3.0.RELEASE
Spring-Retry: 1.2.5.RELEASE
Spring-data: 2.3.0.RELEASE

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions