Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Failed attempt listener not always called on completion. Re: issue #36.
- Loading branch information
1 parent
21d862a
commit 424f2b3
Showing
3 changed files
with
68 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package net.jodah.failsafe.issues; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import net.jodah.failsafe.Failsafe; | ||
import net.jodah.failsafe.RetryPolicy; | ||
|
||
/** | ||
* https://github.com/jhalterman/failsafe/issues/36 | ||
*/ | ||
@Test | ||
@SuppressWarnings("unchecked") | ||
public class Issue36 { | ||
RetryPolicy retryPolicy = new RetryPolicy().retryWhen(false).retryOn(Exception.class).withMaxRetries(3); | ||
AtomicInteger calls; | ||
AtomicInteger failedAttempts; | ||
AtomicInteger retries; | ||
|
||
@BeforeMethod | ||
protected void beforeMethod() { | ||
calls = new AtomicInteger(); | ||
failedAttempts = new AtomicInteger(); | ||
retries = new AtomicInteger(); | ||
} | ||
|
||
public void test() { | ||
Failsafe.with(retryPolicy) | ||
.onFailedAttempt(e -> failedAttempts.incrementAndGet()) | ||
.onRetry(e -> retries.incrementAndGet()) | ||
.get(() -> { | ||
calls.incrementAndGet(); | ||
return false; | ||
}); | ||
|
||
// Then | ||
assertCounters(); | ||
} | ||
|
||
void assertCounters() { | ||
assertEquals(calls.get(), 4); | ||
assertEquals(failedAttempts.get(), 4); | ||
assertEquals(retries.get(), 3); | ||
} | ||
} |