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.19 by dl, Thu Mar 9 00:11:16 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 169 | Line 170 | public class SubmissionPublisherTest ext
170      }
171  
172      /**
173 <     * A null Executor argument to SubmissionPublisher constructor throws NPE
173 >     * A null Executor argument to SubmissionPublisher constructor
174 >     * throws NullPointerException
175       */
176      public void testConstructor3() {
177          try {
# Line 180 | Line 182 | public class SubmissionPublisherTest ext
182  
183      /**
184       * A negative capacity argument to SubmissionPublisher constructor
185 <     * throws IAE
185 >     * throws IllegalArgumentException
186       */
187      public void testConstructor4() {
188          Executor e = Executors.newFixedThreadPool(1);
# Line 192 | Line 194 | public class SubmissionPublisherTest ext
194  
195      /**
196       * A closed publisher reports isClosed with no closedException and
197 <     * throws ISE upon attempted submission; a subsequent close or
198 <     * closeExceptionally has no additional effect.
197 >     * throws IllegalStateException upon attempted submission; a
198 >     * subsequent close or closeExceptionally has no additional
199 >     * effect.
200       */
201      public void testClose() {
202          SubmissionPublisher<Integer> p = basicPublisher();
# Line 213 | Line 216 | public class SubmissionPublisherTest ext
216  
217      /**
218       * A publisher closedExceptionally reports isClosed with the
219 <     * closedException and throws ISE upon attempted submission; a
220 <     * subsequent close or closeExceptionally has no additional
221 <     * effect.
219 >     * closedException and throws IllegalStateException upon attempted
220 >     * submission; a subsequent close or closeExceptionally has no
221 >     * additional effect.
222       */
223      public void testCloseExceptionally() {
224          SubmissionPublisher<Integer> p = basicPublisher();
# Line 400 | Line 403 | public class SubmissionPublisherTest ext
403       * Cancelling a subscription eventually causes no more onNexts to be issued
404       */
405      public void testCancel() {
406 <        SubmissionPublisher<Integer> p = basicPublisher();
406 >        SubmissionPublisher<Integer> p =
407 >            new SubmissionPublisher<Integer>(basicExecutor, 4); // must be < 20
408          TestSubscriber s1 = new TestSubscriber();
409          TestSubscriber s2 = new TestSubscriber();
410          p.subscribe(s1);
# Line 492 | Line 496 | public class SubmissionPublisherTest ext
496          s1.request = false;
497          p.subscribe(s1);
498          s1.awaitSubscribe();
499 <        assertTrue(p.estimateMinimumDemand() == 0);
499 >        assertEquals(0, p.estimateMinimumDemand());
500          TestSubscriber s2 = new TestSubscriber();
501          p.subscribe(s2);
502          p.submit(1);
# Line 564 | Line 568 | public class SubmissionPublisherTest ext
568  
569      /**
570       * estimateMinimumDemand reports 0 until request, nonzero after
571 <     * request, and zero again after delivery
571 >     * request
572       */
573      public void testEstimateMinimumDemand() {
574          TestSubscriber s = new TestSubscriber();
# Line 575 | Line 579 | public class SubmissionPublisherTest ext
579          assertEquals(0, p.estimateMinimumDemand());
580          s.sn.request(1);
581          assertEquals(1, p.estimateMinimumDemand());
578        p.submit(1);
579        s.awaitNext(1);
580        assertEquals(0, p.estimateMinimumDemand());
582      }
583  
584      /**
# Line 640 | Line 641 | public class SubmissionPublisherTest ext
641          p.subscribe(s1);
642          p.subscribe(s2);
643          for (int i = 1; i <= 20; ++i) {
643            assertTrue(p.estimateMinimumDemand() <= 1);
644              assertTrue(p.submit(i) >= 0);
645          }
646          p.close();
# Line 979 | 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