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.20 by jsr166, Sat Mar 18 20:42:20 2017 UTC vs.
Revision 1.28 by jsr166, Sun Jul 22 21:49:33 2018 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 331 | Line 334 | public class SubmissionPublisherTest ext
334          TestSubscriber s = new TestSubscriber();
335          SubmissionPublisher<Integer> p = basicPublisher();
336          s.throwOnCall = true;
337 <        try {
335 <            p.subscribe(s);
336 <        } catch (Exception ok) {}
337 >        p.subscribe(s);
338          s.awaitError();
339          assertEquals(0, s.nexts);
340          assertEquals(1, s.errors);
# Line 400 | Line 401 | public class SubmissionPublisherTest ext
401       * Cancelling a subscription eventually causes no more onNexts to be issued
402       */
403      public void testCancel() {
404 <        SubmissionPublisher<Integer> p = basicPublisher();
404 >        SubmissionPublisher<Integer> p =
405 >            new SubmissionPublisher<>(basicExecutor, 4); // must be < 20
406          TestSubscriber s1 = new TestSubscriber();
407          TestSubscriber s2 = new TestSubscriber();
408          p.subscribe(s1);
# Line 564 | Line 566 | public class SubmissionPublisherTest ext
566  
567      /**
568       * estimateMinimumDemand reports 0 until request, nonzero after
569 <     * request, and zero again after delivery
569 >     * request
570       */
571      public void testEstimateMinimumDemand() {
572          TestSubscriber s = new TestSubscriber();
# Line 575 | Line 577 | public class SubmissionPublisherTest ext
577          assertEquals(0, p.estimateMinimumDemand());
578          s.sn.request(1);
579          assertEquals(1, p.estimateMinimumDemand());
578        p.submit(1);
579        s.awaitNext(1);
580        assertEquals(0, p.estimateMinimumDemand());
580      }
581  
582      /**
# Line 640 | Line 639 | public class SubmissionPublisherTest ext
639          p.subscribe(s1);
640          p.subscribe(s2);
641          for (int i = 1; i <= 20; ++i) {
643            assertTrue(p.estimateMinimumDemand() <= 1);
642              assertTrue(p.submit(i) >= 0);
643          }
644          p.close();
# Line 979 | Line 977 | public class SubmissionPublisherTest ext
977          assertTrue(count.get() < n);
978      }
979  
980 +    /**
981 +     * Tests scenario for
982 +     * JDK-8187947: A race condition in SubmissionPublisher
983 +     * 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
984 +     */
985 +    public void testMissedSignal_8187947() throws Exception {
986 +        if (!atLeastJava9()) return; // backport to jdk8 too hard
987 +        final int N = expensiveTests ? (1 << 20) : (1 << 10);
988 +        final CountDownLatch finished = new CountDownLatch(1);
989 +        final SubmissionPublisher<Boolean> pub = new SubmissionPublisher<>();
990 +        class Sub implements Subscriber<Boolean> {
991 +            int received;
992 +            public void onSubscribe(Subscription s) {
993 +                s.request(N);
994 +            }
995 +            public void onNext(Boolean item) {
996 +                if (++received == N)
997 +                    finished.countDown();
998 +                else
999 +                    CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE));
1000 +            }
1001 +            public void onError(Throwable t) { throw new AssertionError(t); }
1002 +            public void onComplete() {}
1003 +        }
1004 +        pub.subscribe(new Sub());
1005 +        checkTimedGet(
1006 +            CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE)),
1007 +            null);
1008 +        await(finished);
1009 +    }
1010   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines