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

Comparing jsr166/src/test/tck/LinkedBlockingQueueTest.java (file contents):
Revision 1.58 by jsr166, Sat Feb 28 19:59:23 2015 UTC vs.
Revision 1.62 by jsr166, Tue Oct 6 00:03:55 2015 UTC

# Line 37 | Line 37 | public class LinkedBlockingQueueTest ext
37      }
38  
39      public static void main(String[] args) {
40 <        junit.textui.TestRunner.run(suite());
40 >        main(suite(), args);
41      }
42  
43      public static Test suite() {
# Line 108 | Line 108 | public class LinkedBlockingQueueTest ext
108       */
109      public void testConstructor5() {
110          Integer[] ints = new Integer[SIZE];
111 <        for (int i = 0; i < SIZE-1; ++i)
111 >        for (int i = 0; i < SIZE - 1; ++i)
112              ints[i] = new Integer(i);
113          Collection<Integer> elements = Arrays.asList(ints);
114          try {
# Line 155 | Line 155 | public class LinkedBlockingQueueTest ext
155              assertEquals(i, q.remove());
156          }
157          for (int i = 0; i < SIZE; ++i) {
158 <            assertEquals(SIZE-i, q.remainingCapacity());
158 >            assertEquals(SIZE - i, q.remainingCapacity());
159              assertEquals(SIZE, q.size() + q.remainingCapacity());
160              assertTrue(q.add(i));
161          }
# Line 202 | Line 202 | public class LinkedBlockingQueueTest ext
202      public void testAddAll3() {
203          LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
204          Integer[] ints = new Integer[SIZE];
205 <        for (int i = 0; i < SIZE-1; ++i)
205 >        for (int i = 0; i < SIZE - 1; ++i)
206              ints[i] = new Integer(i);
207          Collection<Integer> elements = Arrays.asList(ints);
208          try {
# Line 440 | Line 440 | public class LinkedBlockingQueueTest ext
440          final CountDownLatch aboutToWait = new CountDownLatch(1);
441          Thread t = newStartedThread(new CheckedRunnable() {
442              public void realRun() throws InterruptedException {
443 +                long startTime = System.nanoTime();
444                  for (int i = 0; i < SIZE; ++i) {
444                    long t0 = System.nanoTime();
445                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
446                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
446                  }
448                long t0 = System.nanoTime();
447                  aboutToWait.countDown();
448                  try {
449 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
449 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
450                      shouldThrow();
451                  } catch (InterruptedException success) {
452 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
452 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
453                  }
454              }});
455  
456 <        aboutToWait.await();
457 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
456 >        await(aboutToWait);
457 >        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
458          t.interrupt();
459 <        awaitTermination(t, MEDIUM_DELAY_MS);
459 >        awaitTermination(t);
460          checkEmpty(q);
461      }
462  
# Line 574 | Line 572 | public class LinkedBlockingQueueTest ext
572                  assertTrue(changed);
573  
574              assertTrue(q.containsAll(p));
575 <            assertEquals(SIZE-i, q.size());
575 >            assertEquals(SIZE - i, q.size());
576              p.remove();
577          }
578      }
# Line 587 | Line 585 | public class LinkedBlockingQueueTest ext
585              LinkedBlockingQueue q = populatedQueue(SIZE);
586              LinkedBlockingQueue p = populatedQueue(i);
587              assertTrue(q.removeAll(p));
588 <            assertEquals(SIZE-i, q.size());
588 >            assertEquals(SIZE - i, q.size());
589              for (int j = 0; j < i; ++j) {
590                  Integer x = (Integer)(p.remove());
591                  assertFalse(q.contains(x));
# Line 722 | Line 720 | public class LinkedBlockingQueueTest ext
720          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
721          q.add(one);
722          q.add(two);
725        ExecutorService executor = Executors.newFixedThreadPool(2);
723          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
724 <        executor.execute(new CheckedRunnable() {
725 <            public void realRun() throws InterruptedException {
726 <                assertFalse(q.offer(three));
727 <                threadsStarted.await();
728 <                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
729 <                assertEquals(0, q.remainingCapacity());
730 <            }});
731 <
732 <        executor.execute(new CheckedRunnable() {
733 <            public void realRun() throws InterruptedException {
734 <                threadsStarted.await();
735 <                assertSame(one, q.take());
736 <            }});
737 <
738 <        joinPool(executor);
724 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
725 >        try (PoolCleaner cleaner = cleaner(executor)) {
726 >            executor.execute(new CheckedRunnable() {
727 >                public void realRun() throws InterruptedException {
728 >                    assertFalse(q.offer(three));
729 >                    threadsStarted.await();
730 >                    assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
731 >                    assertEquals(0, q.remainingCapacity());
732 >                }});
733 >
734 >            executor.execute(new CheckedRunnable() {
735 >                public void realRun() throws InterruptedException {
736 >                    threadsStarted.await();
737 >                    assertSame(one, q.take());
738 >                }});
739 >        }
740      }
741  
742      /**
# Line 747 | Line 745 | public class LinkedBlockingQueueTest ext
745      public void testPollInExecutor() {
746          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
747          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
748 <        ExecutorService executor = Executors.newFixedThreadPool(2);
749 <        executor.execute(new CheckedRunnable() {
750 <            public void realRun() throws InterruptedException {
751 <                assertNull(q.poll());
752 <                threadsStarted.await();
753 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
754 <                checkEmpty(q);
755 <            }});
756 <
757 <        executor.execute(new CheckedRunnable() {
758 <            public void realRun() throws InterruptedException {
759 <                threadsStarted.await();
760 <                q.put(one);
761 <            }});
762 <
763 <        joinPool(executor);
748 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
749 >        try (PoolCleaner cleaner = cleaner(executor)) {
750 >            executor.execute(new CheckedRunnable() {
751 >                public void realRun() throws InterruptedException {
752 >                    assertNull(q.poll());
753 >                    threadsStarted.await();
754 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
755 >                    checkEmpty(q);
756 >                }});
757 >
758 >            executor.execute(new CheckedRunnable() {
759 >                public void realRun() throws InterruptedException {
760 >                    threadsStarted.await();
761 >                    q.put(one);
762 >                }});
763 >        }
764      }
765  
766      /**
# Line 814 | Line 812 | public class LinkedBlockingQueueTest ext
812          final LinkedBlockingQueue q = populatedQueue(SIZE);
813          Thread t = new Thread(new CheckedRunnable() {
814              public void realRun() throws InterruptedException {
815 <                q.put(new Integer(SIZE+1));
815 >                q.put(new Integer(SIZE + 1));
816              }});
817  
818          t.start();
# Line 839 | Line 837 | public class LinkedBlockingQueueTest ext
837              q.drainTo(l, i);
838              int k = (i < SIZE) ? i : SIZE;
839              assertEquals(k, l.size());
840 <            assertEquals(SIZE-k, q.size());
840 >            assertEquals(SIZE - k, q.size());
841              for (int j = 0; j < k; ++j)
842                  assertEquals(l.get(j), new Integer(j));
843              do {} while (q.poll() != null);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines