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

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.66 by jsr166, Sat May 23 00:53:08 2015 UTC vs.
Revision 1.71 by jsr166, Sat Aug 6 17:02:49 2016 UTC

# Line 451 | Line 451 | public class ArrayBlockingQueueTest exte
451          final CountDownLatch aboutToWait = new CountDownLatch(1);
452          Thread t = newStartedThread(new CheckedRunnable() {
453              public void realRun() throws InterruptedException {
454 +                long startTime = System.nanoTime();
455                  for (int i = 0; i < SIZE; ++i) {
455                    long t0 = System.nanoTime();
456                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
457                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
457                  }
459                long t0 = System.nanoTime();
458                  aboutToWait.countDown();
459                  try {
460 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
460 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
461                      shouldThrow();
462                  } catch (InterruptedException success) {
463 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
463 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
464                  }
465              }});
466  
467 <        aboutToWait.await();
468 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
467 >        await(aboutToWait);
468 >        waitForThreadToEnterWaitState(t);
469          t.interrupt();
470 <        awaitTermination(t, MEDIUM_DELAY_MS);
470 >        awaitTermination(t);
471          checkEmpty(q);
472      }
473  
# Line 629 | Line 627 | public class ArrayBlockingQueueTest exte
627  
628      void checkToArray2(ArrayBlockingQueue q) {
629          int size = q.size();
630 <        Integer[] a1 = size == 0 ? null : new Integer[size-1];
630 >        Integer[] a1 = (size == 0) ? null : new Integer[size - 1];
631          Integer[] a2 = new Integer[size];
632 <        Integer[] a3 = new Integer[size+2];
632 >        Integer[] a3 = new Integer[size + 2];
633          if (size > 0) Arrays.fill(a1, 42);
634          Arrays.fill(a2, 42);
635          Arrays.fill(a3, 42);
636 <        Integer[] b1 = size == 0 ? null : (Integer[]) q.toArray(a1);
636 >        Integer[] b1 = (size == 0) ? null : (Integer[]) q.toArray(a1);
637          Integer[] b2 = (Integer[]) q.toArray(a2);
638          Integer[] b3 = (Integer[]) q.toArray(a3);
639          assertSame(a2, b2);
# Line 649 | Line 647 | public class ArrayBlockingQueueTest exte
647              assertSame(b3[i], x);
648          }
649          assertNull(a3[size]);
650 <        assertEquals(42, (int) a3[size+1]);
650 >        assertEquals(42, (int) a3[size + 1]);
651          if (size > 0) {
652              assertNotSame(a1, b1);
653              assertEquals(size, b1.length);
# Line 788 | Line 786 | public class ArrayBlockingQueueTest exte
786          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
787          q.add(one);
788          q.add(two);
791        ExecutorService executor = Executors.newFixedThreadPool(2);
789          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
790 <        executor.execute(new CheckedRunnable() {
791 <            public void realRun() throws InterruptedException {
792 <                assertFalse(q.offer(three));
793 <                threadsStarted.await();
794 <                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
795 <                assertEquals(0, q.remainingCapacity());
796 <            }});
797 <
798 <        executor.execute(new CheckedRunnable() {
799 <            public void realRun() throws InterruptedException {
800 <                threadsStarted.await();
801 <                assertEquals(0, q.remainingCapacity());
802 <                assertSame(one, q.take());
803 <            }});
804 <
805 <        joinPool(executor);
790 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
791 >        try (PoolCleaner cleaner = cleaner(executor)) {
792 >            executor.execute(new CheckedRunnable() {
793 >                public void realRun() throws InterruptedException {
794 >                    assertFalse(q.offer(three));
795 >                    threadsStarted.await();
796 >                    assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
797 >                    assertEquals(0, q.remainingCapacity());
798 >                }});
799 >
800 >            executor.execute(new CheckedRunnable() {
801 >                public void realRun() throws InterruptedException {
802 >                    threadsStarted.await();
803 >                    assertEquals(0, q.remainingCapacity());
804 >                    assertSame(one, q.take());
805 >                }});
806 >        }
807      }
808  
809      /**
# Line 814 | Line 812 | public class ArrayBlockingQueueTest exte
812      public void testPollInExecutor() {
813          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
814          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
815 <        ExecutorService executor = Executors.newFixedThreadPool(2);
816 <        executor.execute(new CheckedRunnable() {
817 <            public void realRun() throws InterruptedException {
818 <                assertNull(q.poll());
819 <                threadsStarted.await();
820 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
821 <                checkEmpty(q);
822 <            }});
823 <
824 <        executor.execute(new CheckedRunnable() {
825 <            public void realRun() throws InterruptedException {
826 <                threadsStarted.await();
827 <                q.put(one);
828 <            }});
829 <
830 <        joinPool(executor);
815 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
816 >        try (PoolCleaner cleaner = cleaner(executor)) {
817 >            executor.execute(new CheckedRunnable() {
818 >                public void realRun() throws InterruptedException {
819 >                    assertNull(q.poll());
820 >                    threadsStarted.await();
821 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
822 >                    checkEmpty(q);
823 >                }});
824 >
825 >            executor.execute(new CheckedRunnable() {
826 >                public void realRun() throws InterruptedException {
827 >                    threadsStarted.await();
828 >                    q.put(one);
829 >                }});
830 >        }
831      }
832  
833      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines