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.1 by dl, Mon Sep 7 17:14:06 2015 UTC vs.
Revision 1.3 by jsr166, Mon Sep 7 20:28:47 2015 UTC

# Line 45 | Line 45 | public class SubmissionPublisherTest ext
45              return t;
46          }
47      }
48 <    
48 >
49      static final Executor basicExecutor =
50          (ForkJoinPool.getCommonPoolParallelism() > 0) ?
51          ForkJoinPool.commonPool() :
52          new ThreadPoolExecutor(1, 1, 60, SECONDS,
53                                 new LinkedBlockingQueue<Runnable>(),
54                                 new DaemonThreadFactory());
55 <        
55 >
56      static SubmissionPublisher<Integer> basicPublisher() {
57          return new SubmissionPublisher<Integer>(basicExecutor,
58                                                  Flow.defaultBufferSize());
59      }
60 <    
60 >
61      static class SPException extends RuntimeException {}
62  
63      class TestSubscriber implements Subscriber<Integer> {
# Line 193 | Line 193 | public class SubmissionPublisherTest ext
193       */
194      public void testConstructor3() {
195          try {
196 <            SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(null, 8);
196 >            new SubmissionPublisher<Integer>(null, 8);
197              shouldThrow();
198 <        } catch (NullPointerException success) {
199 <        }
198 >        } catch (NullPointerException success) {}
199      }
200  
201      /**
# Line 206 | Line 205 | public class SubmissionPublisherTest ext
205      public void testConstructor4() {
206          Executor e = Executors.newFixedThreadPool(1);
207          try {
208 <            SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(e, -1);
208 >            new SubmissionPublisher<Integer>(e, -1);
209              shouldThrow();
210 <        } catch (IllegalArgumentException success) {
212 <        }
210 >        } catch (IllegalArgumentException success) {}
211      }
212  
213      /**
# Line 226 | Line 224 | public class SubmissionPublisherTest ext
224          try {
225              p.submit(1);
226              shouldThrow();
227 <        }
230 <        catch(IllegalStateException success) {
231 <        }
227 >        } catch (IllegalStateException success) {}
228          Throwable ex = new SPException();
229          p.closeExceptionally(ex);
230          assertTrue(p.isClosed());
# Line 251 | Line 247 | public class SubmissionPublisherTest ext
247          try {
248              p.submit(1);
249              shouldThrow();
250 <        }
255 <        catch(IllegalStateException success) {
256 <        }
250 >        } catch (IllegalStateException success) {}
251          p.close();
252          assertTrue(p.isClosed());
253          assertSame(p.getClosedException(), ex);
# Line 358 | Line 352 | public class SubmissionPublisherTest ext
352          s.throwOnCall = true;
353          try {
354              p.subscribe(s);
355 <        } catch(Exception ok) {
362 <        }
355 >        } catch (Exception ok) {}
356          s.awaitError();
357          assertEquals(s.nexts, 0);
358          assertEquals(s.errors, 1);
# Line 373 | Line 366 | public class SubmissionPublisherTest ext
366          SubmissionPublisher<Integer> p = basicPublisher();
367          try {
368              p.subscribe(null);
369 <        } catch(NullPointerException success) {
370 <        }
369 >            shouldThrow();
370 >        } catch (NullPointerException success) {}
371          checkInitialState(p);
372      }
373  
# Line 598 | Line 591 | public class SubmissionPublisherTest ext
591      }
592  
593      /**
594 <     * Submit to a publisher with no subscribers returns lag 0
594 >     * submit to a publisher with no subscribers returns lag 0
595       */
596      public void testEmptySubmit() {
597          SubmissionPublisher<Integer> p = basicPublisher();
# Line 606 | Line 599 | public class SubmissionPublisherTest ext
599      }
600  
601      /**
602 <     * Submit(null) throws NPE
602 >     * submit(null) throws NPE
603       */
604      public void testNullSubmit() {
605          SubmissionPublisher<Integer> p = basicPublisher();
606          try {
607              p.submit(null);
608 <        } catch (NullPointerException success) {
609 <        }
608 >            shouldThrow();
609 >        } catch (NullPointerException success) {}
610      }
611  
612      /**
613 <     * Submit returns number of lagged items, compatible with result
613 >     * submit returns number of lagged items, compatible with result
614       * of estimateMaximumLag.
615       */
616      public void testLaggedSubmit() {
# Line 668 | Line 661 | public class SubmissionPublisherTest ext
661          assertEquals(s1.nexts, 20);
662          assertEquals(s1.completes, 1);
663      }
664 <    
664 >
665      static boolean noopHandle(AtomicInteger count) {
666          count.getAndIncrement();
667          return false;
# Line 681 | Line 674 | public class SubmissionPublisherTest ext
674      }
675  
676      /**
677 <     * Offer to a publisher with no subscribers returns lag 0
677 >     * offer to a publisher with no subscribers returns lag 0
678       */
679      public void testEmptyOffer() {
680          SubmissionPublisher<Integer> p = basicPublisher();
681 <        assertEquals(p.offer(1, null), 0);
681 >        assertEquals(0, p.offer(1, null));
682      }
683  
684      /**
685 <     * Offer(null) throws NPE
685 >     * offer(null) throws NPE
686       */
687      public void testNullOffer() {
688          SubmissionPublisher<Integer> p = basicPublisher();
689          try {
690              p.offer(null, null);
691 <        } catch (NullPointerException success) {
692 <        }
691 >            shouldThrow();
692 >        } catch (NullPointerException success) {}
693      }
694  
695      /**
696 <     * Offer returns number of lagged items if not saturated
696 >     * offer returns number of lagged items if not saturated
697       */
698      public void testLaggedOffer() {
699          SubmissionPublisher<Integer> p = basicPublisher();
# Line 726 | Line 719 | public class SubmissionPublisherTest ext
719      }
720  
721      /**
722 <     * Offer reports drops if saturated
722 >     * offer reports drops if saturated
723       */
724      public void testDroppedOffer() {
725          SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
# Line 754 | Line 747 | public class SubmissionPublisherTest ext
747      }
748  
749      /**
750 <     * Offer invokes drop handler if saturated
750 >     * offer invokes drop handler if saturated
751       */
752      public void testHandledDroppedOffer() {
753          AtomicInteger calls = new AtomicInteger();
# Line 783 | Line 776 | public class SubmissionPublisherTest ext
776  
777  
778      /**
779 <     * Offer succeeds if drop handler forces request
779 >     * offer succeeds if drop handler forces request
780       */
781      public void testRecoveredHandledDroppedOffer() {
782          AtomicInteger calls = new AtomicInteger();
# Line 819 | Line 812 | public class SubmissionPublisherTest ext
812      }
813  
814      /**
815 <     * Timed Offer with null item or TimeUnit throws NPE
815 >     * Timed offer with null item or TimeUnit throws NPE
816       */
817      public void testNullTimedOffer() {
818          SubmissionPublisher<Integer> p = basicPublisher();
819          try {
820              p.offer(null, SHORT_DELAY_MS, MILLISECONDS, null);
821 <        } catch (NullPointerException success) {
822 <        }
821 >            shouldThrow();
822 >        } catch (NullPointerException success) {}
823          try {
824              p.offer(1, SHORT_DELAY_MS, null, null);
825 <        } catch (NullPointerException success) {
826 <        }
825 >            shouldThrow();
826 >        } catch (NullPointerException success) {}
827      }
828  
829      /**
830 <     * Timed Offer returns number of lagged items if not saturated
830 >     * Timed offer returns number of lagged items if not saturated
831       */
832      public void testLaggedTimedOffer() {
833          SubmissionPublisher<Integer> p = basicPublisher();
# Line 860 | Line 853 | public class SubmissionPublisherTest ext
853      }
854  
855      /**
856 <     * Timed Offer reports drops if saturated
856 >     * Timed offer reports drops if saturated
857       */
858      public void testDroppedTimedOffer() {
859          SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
# Line 888 | Line 881 | public class SubmissionPublisherTest ext
881      }
882  
883      /**
884 <     * Timed Offer invokes drop handler if saturated
884 >     * Timed offer invokes drop handler if saturated
885       */
886      public void testHandledDroppedTimedOffer() {
887          AtomicInteger calls = new AtomicInteger();
# Line 916 | Line 909 | public class SubmissionPublisherTest ext
909      }
910  
911      /**
912 <     * Timed Offer succeeds if drop handler forces request
912 >     * Timed offer succeeds if drop handler forces request
913       */
914      public void testRecoveredHandledDroppedTimedOffer() {
915          AtomicInteger calls = new AtomicInteger();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines