-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
59 additions
and
12 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
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,45 @@ | ||
package net.jodah.failsafe.issues; | ||
|
||
import net.jodah.failsafe.Failsafe; | ||
import net.jodah.failsafe.Fallback; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
@Test | ||
public class Issue298Test { | ||
AtomicBoolean failedAttemptCalled = new AtomicBoolean(); | ||
AtomicBoolean failureCalled = new AtomicBoolean(); | ||
|
||
Fallback<String> fallback = Fallback.<String>of(e -> "success") | ||
.onFailedAttempt(e -> failedAttemptCalled.set(true)) | ||
.onFailure(e -> failureCalled.set(true)); | ||
|
||
@BeforeMethod | ||
protected void beforeMethod() { | ||
failedAttemptCalled.set(false); | ||
failureCalled.set(false); | ||
} | ||
|
||
public void testSync() { | ||
Failsafe.with(fallback).get(() -> { | ||
throw new Exception(); | ||
}); | ||
|
||
assertTrue(failedAttemptCalled.get()); | ||
assertFalse(failureCalled.get()); | ||
} | ||
|
||
public void testAsync() throws Throwable { | ||
Failsafe.with(fallback).getAsync(() -> { | ||
throw new Exception(); | ||
}).get(); | ||
|
||
assertTrue(failedAttemptCalled.get()); | ||
assertFalse(failureCalled.get()); | ||
} | ||
} |