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.71 by jsr166, Sun May 14 00:48:20 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 314 | Line 313 | public class LinkedBlockingQueueTest ext
313                  pleaseTake.countDown();
314                  q.put(86);
315  
316 +                Thread.currentThread().interrupt();
317 +                try {
318 +                    q.put(99);
319 +                    shouldThrow();
320 +                } catch (InterruptedException success) {}
321 +                assertFalse(Thread.interrupted());
322 +
323                  pleaseInterrupt.countDown();
324                  try {
325                      q.put(99);
# Line 327 | 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 344 | Line 350 | public class LinkedBlockingQueueTest ext
350                  q.put(new Object());
351                  q.put(new Object());
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(), 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 395 | 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 448 | Line 466 | public class LinkedBlockingQueueTest ext
466          Thread t = newStartedThread(new CheckedRunnable() {
467              public void realRun() throws InterruptedException {
468                  long startTime = System.nanoTime();
469 <                for (int i = 0; i < SIZE; ++i) {
469 >                for (int i = 0; i < SIZE; i++)
470                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
471 <                }
471 >
472 >                Thread.currentThread().interrupt();
473 >                try {
474 >                    q.poll(randomTimeout(), randomTimeUnit());
475 >                    shouldThrow();
476 >                } catch (InterruptedException success) {}
477 >                assertFalse(Thread.interrupted());
478  
479                  pleaseInterrupt.countDown();
480                  try {
# Line 463 | 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 607 | 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 620 | 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 773 | 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