ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/SubmissionPublisherTest.java
(Generate patch)

Comparing jsr166/src/test/tck/SubmissionPublisherTest.java (file contents):
Revision 1.23 by dl, Sun Nov 26 21:37:56 2017 UTC vs.
Revision 1.25 by jsr166, Mon Dec 11 00:16:40 2017 UTC

# Line 6 | Line 6
6   */
7  
8   import java.util.concurrent.CompletableFuture;
9 + import java.util.concurrent.CountDownLatch;
10   import java.util.concurrent.Executor;
11   import java.util.concurrent.Executors;
12   import java.util.concurrent.Flow;
# Line 978 | Line 979 | public class SubmissionPublisherTest ext
979          assertTrue(count.get() < n);
980      }
981  
982 +    /**
983 +     * Tests scenario for
984 +     * JDK-8187947: A race condition in SubmissionPublisher
985 +     * cvs update -D '2017-11-25' src/main/java/util/concurrent/SubmissionPublisher.java && ant -Djsr166.expensiveTests=true -Djsr166.tckTestClass=SubmissionPublisherTest -Djsr166.methodFilter=testMissedSignal tck; cvs update -A src/main/java/util/concurrent/SubmissionPublisher.java
986 +     */
987 +    public void testMissedSignal_8187947() throws Exception {
988 +        if (!atLeastJava9()) return; // backport to jdk8 too hard
989 +        final int N = expensiveTests ? (1 << 20) : (1 << 10);
990 +        final CountDownLatch finished = new CountDownLatch(1);
991 +        final SubmissionPublisher<Boolean> pub = new SubmissionPublisher<>();
992 +        class Sub implements Subscriber<Boolean> {
993 +            int received;
994 +            public void onSubscribe(Subscription s) {
995 +                s.request(N);
996 +            }
997 +            public void onNext(Boolean item) {
998 +                if (++received == N)
999 +                    finished.countDown();
1000 +                else
1001 +                    CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE));
1002 +            }
1003 +            public void onError(Throwable t) { throw new AssertionError(t); }
1004 +            public void onComplete() {}
1005 +        }
1006 +        pub.subscribe(new Sub());
1007 +        CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE));
1008 +        await(finished);
1009 +    }
1010   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines