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.75 by jsr166, Sun May 14 04:14:09 2017 UTC vs.
Revision 1.79 by jsr166, Sun Aug 11 22:29:27 2019 UTC

# Line 59 | Line 59 | public class LinkedBlockingQueueTest ext
59       * Integers 0 ... n - 1.
60       */
61      private static LinkedBlockingQueue<Integer> populatedQueue(int n) {
62 <        LinkedBlockingQueue<Integer> q =
63 <            new LinkedBlockingQueue<Integer>(n);
62 >        LinkedBlockingQueue<Integer> q = new LinkedBlockingQueue<>(n);
63          assertTrue(q.isEmpty());
64          for (int i = 0; i < n; i++)
65              assertTrue(q.offer(new Integer(i)));
# Line 292 | Line 291 | public class LinkedBlockingQueueTest ext
291              }});
292  
293          await(pleaseInterrupt);
294 <        assertThreadBlocks(t, Thread.State.WAITING);
294 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
295          t.interrupt();
296          awaitTermination(t);
297          assertEquals(SIZE, q.size());
# Line 334 | Line 333 | public class LinkedBlockingQueueTest ext
333          assertEquals(0, q.take());
334  
335          await(pleaseInterrupt);
336 <        assertThreadBlocks(t, Thread.State.WAITING);
336 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
337          t.interrupt();
338          awaitTermination(t);
339          assertEquals(0, q.remainingCapacity());
# Line 350 | Line 349 | public class LinkedBlockingQueueTest ext
349              public void realRun() throws InterruptedException {
350                  q.put(new Object());
351                  q.put(new Object());
353
352                  long startTime = System.nanoTime();
353 +
354                  assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
355                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
356  
357                  Thread.currentThread().interrupt();
358                  try {
359 <                    q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
359 >                    q.offer(new Object(), randomTimeout(), randomTimeUnit());
360                      shouldThrow();
361                  } catch (InterruptedException success) {}
362                  assertFalse(Thread.interrupted());
363  
364                  pleaseInterrupt.countDown();
365                  try {
366 <                    q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
366 >                    q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
367                      shouldThrow();
368                  } catch (InterruptedException success) {}
369                  assertFalse(Thread.interrupted());
370 +
371 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
372              }});
373  
374          await(pleaseInterrupt);
375 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
375 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
376          t.interrupt();
377          awaitTermination(t);
378      }
# Line 412 | Line 413 | public class LinkedBlockingQueueTest ext
413              }});
414  
415          await(pleaseInterrupt);
416 <        assertThreadBlocks(t, Thread.State.WAITING);
416 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
417          t.interrupt();
418          awaitTermination(t);
419      }
# Line 470 | Line 471 | public class LinkedBlockingQueueTest ext
471  
472                  Thread.currentThread().interrupt();
473                  try {
474 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
474 >                    q.poll(randomTimeout(), randomTimeUnit());
475                      shouldThrow();
476                  } catch (InterruptedException success) {}
477                  assertFalse(Thread.interrupted());
# Line 486 | Line 487 | public class LinkedBlockingQueueTest ext
487              }});
488  
489          await(pleaseInterrupt);
490 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
490 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
491          t.interrupt();
492          awaitTermination(t);
493          checkEmpty(q);
# Line 630 | Line 631 | public class LinkedBlockingQueueTest ext
631       */
632      public void testToArray() {
633          LinkedBlockingQueue q = populatedQueue(SIZE);
634 <        Object[] o = q.toArray();
635 <        for (int i = 0; i < o.length; i++)
636 <            assertSame(o[i], q.poll());
634 >        Object[] a = q.toArray();
635 >        assertSame(Object[].class, a.getClass());
636 >        for (Object o : a)
637 >            assertSame(o, q.poll());
638 >        assertTrue(q.isEmpty());
639      }
640  
641      /**
# Line 643 | Line 646 | public class LinkedBlockingQueueTest ext
646          Integer[] ints = new Integer[SIZE];
647          Integer[] array = q.toArray(ints);
648          assertSame(ints, array);
649 <        for (int i = 0; i < ints.length; i++)
650 <            assertSame(ints[i], q.poll());
649 >        for (Integer o : ints)
650 >            assertSame(o, q.poll());
651 >        assertTrue(q.isEmpty());
652      }
653  
654      /**
# Line 796 | Line 800 | public class LinkedBlockingQueueTest ext
800      }
801  
802      /**
803 <     * A deserialized serialized queue has same elements in same order
803 >     * A deserialized/reserialized queue has same elements in same order
804       */
805      public void testSerialization() throws Exception {
806          Queue x = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines