MCPcopy Create free account
hub / github.com/traneio/future / PromiseTest

Class PromiseTest

future-java/src/test/java/io/trane/future/PromiseTest.java:22–1192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20import org.junit.Test;
21
22public class PromiseTest {
23
24 private <T> T get(Future<T> future) throws CheckedFutureException {
25 return future.get(Duration.ZERO);
26 }
27
28 private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
29 private final Exception ex = new TestException();
30
31 @After
32 public void shutdownScheduler() {
33 scheduler.shutdown();
34 }
35
36 /*** apply ***/
37
38 @Test
39 public void apply() throws CheckedFutureException {
40 Promise<Integer> p = Promise.apply();
41 p.setValue(1);
42 assertEquals(new Integer(1), get(p));
43 }
44
45 @Test
46 public void applyWithLocal() {
47 AtomicReference<Optional<Integer>> localValue = new AtomicReference<>();
48 Local<Integer> l = Local.apply();
49 l.update(1);
50 Promise<Integer> p = Promise.apply();
51 l.update(2);
52 p.ensure(() -> localValue.set(l.get()));
53 p.setValue(1);
54 assertEquals(Optional.of(1), localValue.get());
55 }
56
57 @Test
58 public void applyHandler() throws CheckedFutureException {
59 AtomicReference<Throwable> interrupt = new AtomicReference<Throwable>();
60 InterruptHandler handler = interrupt::set;
61 Promise<Integer> p = Promise.apply(handler);
62 p.raise(ex);
63 assertEquals(ex, interrupt.get());
64 }
65
66 @Test
67 public void applyHandlerWithLocal() {
68 AtomicReference<Optional<Integer>> localValue = new AtomicReference<>();
69 Local<Integer> l = Local.apply();
70 l.update(1);
71 Promise<Integer> p = Promise.apply((ex) -> {
72 });
73 l.update(2);
74 p.ensure(() -> localValue.set(l.get()));
75 p.setValue(1);
76 assertEquals(Optional.of(1), localValue.get());
77 }
78
79 @Test

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…