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.69 by jsr166, Mon Oct 5 23:06:12 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines