forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1Test.java
More file actions
39 lines (30 loc) · 1.06 KB
/
P1Test.java
File metadata and controls
39 lines (30 loc) · 1.06 KB
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
package fj;
import org.junit.Test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public final class P1Test {
@Test
public void bug105() throws Exception {
final P1<String> p1 = P.weakMemo(() -> "Foo");
final AtomicInteger nullCounter = new AtomicInteger();
ExecutorService executorService = Executors.newCachedThreadPool();
for (int i = 0; i < 10000; i++) {
executorService.submit(() -> {
if (p1._1() == null) {
nullCounter.incrementAndGet();
}
});
}
executorService.shutdown();
executorService.awaitTermination(10, TimeUnit.DAYS);
org.junit.Assert.assertEquals("Race condition in P1.memo()", 0, nullCounter.get());
}
@Test
public void bug122() throws Exception {
final P1<Integer> p1a = P.lazy(() -> 1);
final P1<Integer> p1b = P.lazy(() -> 1);
org.junit.Assert.assertTrue(p1a + " and " + p1b + " should be equal by Object.equals", p1a.equals(p1b));
}
}