5

I have a method which I'm trying to test

@Retryable(value = {SocketTimeoutException.class},
             backoff = @Backoff(delay = 10000),
             maxAttempts = 4)
public String getNewString(String oldString) throws IOException{
   ...
}

I have created it's test case like so:

@SpringBootTest
@RunWith(SpringRunner.class)
public class TestStrings {
  @Test(expected = SocketTimeoutException.class)
  public void testGetNewString() throws IOException {
     ...
  }

Everything works great, the test case runs 4 times with a delay of 10sec. But I want to change the attributes of @Retryable, namely maxAttempts from 4 to 2 and delay from 10s to 0.5s for this specific test case. I want to do this so that when running the test cases it should not wait for a long time and the test case should end quickly meanwhile also testing the retry functionality.

Paras Thakur
  • 119
  • 1
  • 9

1 Answers1

5

Use

@Retryable(maxAttemptsExpression = "${max.attempts:4}", 
        backoff = @Backoff(delayExpression = "${delay:10000}"))

and set the properties in your test case.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I almost forgot I could do this. Was working along the lines of mocking RetryProperties with the specific properties. Thanks! – Paras Thakur Aug 06 '20 at 15:33