/
Issue75Test.java
28 lines (24 loc) · 986 Bytes
/
Issue75Test.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
package net.jodah.failsafe.issues;
import net.jodah.failsafe.CircuitBreaker;
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.Fallback;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class Issue75Test {
@Test
public void testThatFailSafeIsBrokenWithFallback() throws Exception {
CircuitBreaker<Integer> breaker = new CircuitBreaker<Integer>().withFailureThreshold(10, 100).withSuccessThreshold(2).withDelay(100,
TimeUnit.MILLISECONDS);
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
int result = Failsafe.with(breaker)
.with(service)
.with(Fallback.of((a, b) -> 999))
.futureAsync(() -> CompletableFuture.completedFuture(223))
.get();
Assert.assertEquals(result, 223);
}
}