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.80 by jsr166, Thu Sep 5 20:54:24 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(), LONGER_DELAY_MS, MILLISECONDS);
367                      shouldThrow();
368                  } catch (InterruptedException success) {}
369                  assertFalse(Thread.interrupted());
370              }});
371  
372          await(pleaseInterrupt);
373 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
373 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
374          t.interrupt();
375          awaitTermination(t);
376      }
# Line 412 | Line 411 | public class LinkedBlockingQueueTest ext
411              }});
412  
413          await(pleaseInterrupt);
414 <        assertThreadBlocks(t, Thread.State.WAITING);
414 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
415          t.interrupt();
416          awaitTermination(t);
417      }
# Line 470 | Line 469 | public class LinkedBlockingQueueTest ext
469  
470                  Thread.currentThread().interrupt();
471                  try {
472 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
472 >                    q.poll(randomTimeout(), randomTimeUnit());
473                      shouldThrow();
474                  } catch (InterruptedException success) {}
475                  assertFalse(Thread.interrupted());
# Line 486 | Line 485 | public class LinkedBlockingQueueTest ext
485              }});
486  
487          await(pleaseInterrupt);
488 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
488 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
489          t.interrupt();
490          awaitTermination(t);
491          checkEmpty(q);
# Line 630 | Line 629 | public class LinkedBlockingQueueTest ext
629       */
630      public void testToArray() {
631          LinkedBlockingQueue q = populatedQueue(SIZE);
632 <        Object[] o = q.toArray();
633 <        for (int i = 0; i < o.length; i++)
634 <            assertSame(o[i], q.poll());
632 >        Object[] a = q.toArray();
633 >        assertSame(Object[].class, a.getClass());
634 >        for (Object o : a)
635 >            assertSame(o, q.poll());
636 >        assertTrue(q.isEmpty());
637      }
638  
639      /**
# Line 643 | Line 644 | public class LinkedBlockingQueueTest ext
644          Integer[] ints = new Integer[SIZE];
645          Integer[] array = q.toArray(ints);
646          assertSame(ints, array);
647 <        for (int i = 0; i < ints.length; i++)
648 <            assertSame(ints[i], q.poll());
647 >        for (Integer o : ints)
648 >            assertSame(o, q.poll());
649 >        assertTrue(q.isEmpty());
650      }
651  
652      /**
# Line 796 | Line 798 | public class LinkedBlockingQueueTest ext
798      }
799  
800      /**
801 <     * A deserialized serialized queue has same elements in same order
801 >     * A deserialized/reserialized queue has same elements in same order
802       */
803      public void testSerialization() throws Exception {
804          Queue x = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines