-
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.
Allow null fallback values to be passed through
Fixes #267
- Loading branch information
1 parent
c93bf35
commit fe88715
Showing
2 changed files
with
44 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.jodah.failsafe.issues; | ||
|
||
import net.jodah.failsafe.Failsafe; | ||
import net.jodah.failsafe.Fallback; | ||
import net.jodah.failsafe.Timeout; | ||
import net.jodah.failsafe.event.ExecutionAttemptedEvent; | ||
import org.testng.annotations.Test; | ||
|
||
import java.net.ConnectException; | ||
import java.time.Duration; | ||
|
||
import static org.testng.Assert.assertNull; | ||
|
||
@Test | ||
public class Issue267 { | ||
public void test() { | ||
Timeout<Object> timeout = Timeout.of(Duration.ofMillis(1000L)); | ||
Fallback<Object> notFoundFallback = Fallback.of(this::handleNotFound).handleIf(this::causedBy404); | ||
Fallback<Object> failureHandling = Fallback.ofException(this::handleException); | ||
|
||
Integer result = Failsafe.with(failureHandling, notFoundFallback, timeout).get(this::connect); | ||
assertNull(result); | ||
} | ||
|
||
private Integer connect() throws ConnectException { | ||
throw new ConnectException(); | ||
} | ||
|
||
private boolean causedBy404(Object o, Throwable throwable) { | ||
return throwable instanceof ConnectException; | ||
} | ||
|
||
private Object handleNotFound(ExecutionAttemptedEvent<?> event) { | ||
return null; | ||
} | ||
|
||
private Exception handleException(ExecutionAttemptedEvent<?> event) { | ||
return new IllegalArgumentException(); | ||
} | ||
} |