/
Issue298Test.java
45 lines (35 loc) · 1.15 KB
/
Issue298Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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());
}
}