Fixes retrials without Thread.sleep when thread gets interrupted#627
Conversation
|
This makes lots of sense to me, I just wonder if we can have a test somehow. |
|
Might I suggest a test: @Test
public void failsOnInterruptedException() {
Default retryer = new Retryer.Default();
Thread.currentThread().interrupt();
RetryableException expected = new RetryableException(null, null, new Date(System.currentTimeMillis() + 5000));
try {
retryer.continueOrPropagate(expected);
Thread.interrupted(); // reset interrupted flag in case it wasn't
Assert.fail("Retryer continued despite interruption");
} catch (RetryableException e) {
Assert.assertTrue("Interrupted status not reset", Thread.interrupted());
Assert.assertEquals("Retry attempt not registered as expected", 2, retryer.attempt);
Assert.assertEquals("Unexpected exception found", expected, e);
}
} |
|
|
|
What do you think about running retryer in other thread? |
|
You're right. Since the Just add (in the catch block): Assert.assertTrue(Thread.interrupted());[EDIT: I updated the code block with some additional assertions and an interrupted flag reset] |
|
PS - I think that if you run it in another thread, you need to check that thread for assertion states. It's probably easier to just do it in the current thread and just The test should fail if you revert your |
| assertThatThrowsExceptionAndThreadIsInterrupted(RetryableException.class, | ||
| () -> retryer.continueOrPropagate(new RetryableException(null, null)))); | ||
| thread.start(); | ||
| thread.interrupt(); |
There was a problem hiding this comment.
How can this test ever fail with no assertions while swallowing all exceptions in another thread?
… exception when thread is interrupted
|
Ok, I added test suggested by you. |
* Fixes retrials without Thread.sleep when thread gets interrupted * Added test to verify if default retryer propagates RetryableException exception when thread is interrupted
* Fixes retrials without Thread.sleep when thread gets interrupted * Added test to verify if default retryer propagates RetryableException exception when thread is interrupted
This PR aims to avoid flood of retries when thread, in which retryer is running, gets interrupted. Default retryer will rethrow FeignException in case of interrupted state.
Fixes #624
Fixes #643