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.5 by jsr166, Mon Sep 7 20:34:34 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 781 | Line 774 | public class SubmissionPublisherTest ext
774          assertTrue(calls.get() >= 4);
775      }
776  
784
777      /**
778 <     * Offer succeeds if drop handler forces request
778 >     * offer succeeds if drop handler forces request
779       */
780      public void testRecoveredHandledDroppedOffer() {
781          AtomicInteger calls = new AtomicInteger();
# Line 809 | Line 801 | public class SubmissionPublisherTest ext
801          assertTrue(calls.get() >= 2);
802      }
803  
812
804      /**
805 <     * TimedOffer to a publisher with no subscribers returns lag 0
805 >     * Timed offer to a publisher with no subscribers returns lag 0
806       */
807      public void testEmptyTimedOffer() {
808          SubmissionPublisher<Integer> p = basicPublisher();
809 <        assertEquals(p.offer(1, null), 0);
809 >        assertEquals(0, p.offer(1, LONG_DELAY_MS, MILLISECONDS, null));
810      }
811  
812      /**
813 <     * Timed Offer with null item or TimeUnit throws NPE
813 >     * Timed offer with null item or TimeUnit throws NPE
814       */
815      public void testNullTimedOffer() {
816          SubmissionPublisher<Integer> p = basicPublisher();
817          try {
818              p.offer(null, SHORT_DELAY_MS, MILLISECONDS, null);
819 <        } catch (NullPointerException success) {
820 <        }
819 >            shouldThrow();
820 >        } catch (NullPointerException success) {}
821          try {
822              p.offer(1, SHORT_DELAY_MS, null, null);
823 <        } catch (NullPointerException success) {
824 <        }
823 >            shouldThrow();
824 >        } catch (NullPointerException success) {}
825      }
826  
827      /**
828 <     * Timed Offer returns number of lagged items if not saturated
828 >     * Timed offer returns number of lagged items if not saturated
829       */
830      public void testLaggedTimedOffer() {
831          SubmissionPublisher<Integer> p = basicPublisher();
# Line 860 | Line 851 | public class SubmissionPublisherTest ext
851      }
852  
853      /**
854 <     * Timed Offer reports drops if saturated
854 >     * Timed offer reports drops if saturated
855       */
856      public void testDroppedTimedOffer() {
857          SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
# Line 888 | Line 879 | public class SubmissionPublisherTest ext
879      }
880  
881      /**
882 <     * Timed Offer invokes drop handler if saturated
882 >     * Timed offer invokes drop handler if saturated
883       */
884      public void testHandledDroppedTimedOffer() {
885          AtomicInteger calls = new AtomicInteger();
# Line 916 | Line 907 | public class SubmissionPublisherTest ext
907      }
908  
909      /**
910 <     * Timed Offer succeeds if drop handler forces request
910 >     * Timed offer succeeds if drop handler forces request
911       */
912      public void testRecoveredHandledDroppedTimedOffer() {
913          AtomicInteger calls = new AtomicInteger();
# Line 942 | Line 933 | public class SubmissionPublisherTest ext
933          assertTrue(calls.get() >= 2);
934      }
935  
945
936   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines