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.78 by jsr166, Sun Nov 6 03:49:39 2016 UTC vs.
Revision 1.86 by jsr166, Sun May 14 00:48:20 2017 UTC

# Line 269 | Line 269 | public class ArrayBlockingQueueTest exte
269       * addAll throws ISE if not enough room
270       */
271      public void testAddAll_insufficientSpace() {
272 <        int size = ThreadLocalRandom.current().nextInt(SIZE);
272 >        int size = ThreadLocalRandom.current().nextInt(1, SIZE);
273          ArrayBlockingQueue q = populatedQueue(0, size, size, false);
274          // Just fits:
275          q.addAll(populatedQueue(size, size, 2 * size, false));
# Line 340 | Line 340 | public class ArrayBlockingQueueTest exte
340              }});
341  
342          await(pleaseInterrupt);
343 <        assertThreadStaysAlive(t);
343 >        assertThreadBlocks(t, Thread.State.WAITING);
344          t.interrupt();
345          awaitTermination(t);
346          assertEquals(SIZE, q.size());
# Line 375 | Line 375 | public class ArrayBlockingQueueTest exte
375          assertEquals(0, q.take());
376  
377          await(pleaseInterrupt);
378 <        assertThreadStaysAlive(t);
378 >        assertThreadBlocks(t, Thread.State.WAITING);
379          t.interrupt();
380          awaitTermination(t);
381          assertEquals(0, q.remainingCapacity());
# Line 402 | Line 402 | public class ArrayBlockingQueueTest exte
402              }});
403  
404          await(pleaseInterrupt);
405 <        assertThreadStaysAlive(t);
405 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
406          t.interrupt();
407          awaitTermination(t);
408      }
# Line 425 | Line 425 | public class ArrayBlockingQueueTest exte
425          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
426          Thread t = newStartedThread(new CheckedRunnable() {
427              public void realRun() throws InterruptedException {
428 <                for (int i = 0; i < SIZE; ++i) {
429 <                    assertEquals(i, q.take());
430 <                }
428 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.take());
429  
430                  Thread.currentThread().interrupt();
431                  try {
# Line 445 | Line 443 | public class ArrayBlockingQueueTest exte
443              }});
444  
445          await(pleaseInterrupt);
446 <        assertThreadStaysAlive(t);
446 >        assertThreadBlocks(t, Thread.State.WAITING);
447          t.interrupt();
448          awaitTermination(t);
449      }
# Line 495 | Line 493 | public class ArrayBlockingQueueTest exte
493       */
494      public void testInterruptedTimedPoll() throws InterruptedException {
495          final BlockingQueue<Integer> q = populatedQueue(SIZE);
496 <        final CountDownLatch aboutToWait = new CountDownLatch(1);
496 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
497          Thread t = newStartedThread(new CheckedRunnable() {
498              public void realRun() throws InterruptedException {
499                  long startTime = System.nanoTime();
500                  for (int i = 0; i < SIZE; ++i) {
501                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
502                  }
503 <                aboutToWait.countDown();
503 >
504 >                pleaseInterrupt.countDown();
505                  try {
506                      q.poll(LONG_DELAY_MS, MILLISECONDS);
507                      shouldThrow();
508 <                } catch (InterruptedException success) {
509 <                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
510 <                }
508 >                } catch (InterruptedException success) {}
509 >                assertFalse(Thread.interrupted());
510 >
511 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
512              }});
513  
514 <        await(aboutToWait);
515 <        waitForThreadToEnterWaitState(t);
514 >        await(pleaseInterrupt);
515 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
516          t.interrupt();
517          awaitTermination(t);
518          checkEmpty(q);
# Line 565 | Line 565 | public class ArrayBlockingQueueTest exte
565       * contains(x) reports true when elements added but not yet removed
566       */
567      public void testContains() {
568 <        ArrayBlockingQueue q = populatedQueue(SIZE);
569 <        for (int i = 0; i < SIZE; ++i) {
568 >        int size = ThreadLocalRandom.current().nextInt(1, SIZE);
569 >        ArrayBlockingQueue q = populatedQueue(size, size, 2 * size, false);
570 >        assertFalse(q.contains(null));
571 >        for (int i = 0; i < size; ++i) {
572              assertTrue(q.contains(new Integer(i)));
573              assertEquals(i, q.poll());
574              assertFalse(q.contains(new Integer(i)));
# Line 577 | Line 579 | public class ArrayBlockingQueueTest exte
579       * clear removes all elements
580       */
581      public void testClear() {
582 <        ArrayBlockingQueue q = populatedQueue(SIZE);
582 >        int size = ThreadLocalRandom.current().nextInt(1, 5);
583 >        ArrayBlockingQueue q = populatedQueue(size, size, 2 * size, false);
584 >        int capacity = size + q.remainingCapacity();
585          q.clear();
586          assertTrue(q.isEmpty());
587          assertEquals(0, q.size());
588 <        assertEquals(SIZE, q.remainingCapacity());
588 >        assertEquals(capacity, q.remainingCapacity());
589          q.add(one);
590          assertFalse(q.isEmpty());
591          assertTrue(q.contains(one));
# Line 935 | Line 939 | public class ArrayBlockingQueueTest exte
939       */
940      public void testNeverContainsNull() {
941          Collection<?>[] qs = {
942 <            new ArrayBlockingQueue<Object>(10),
943 <            populatedQueue(2),
942 >            populatedQueue(0, 1, 10, false),
943 >            populatedQueue(2, 2, 10, true),
944          };
945  
946          for (Collection<?> q : qs) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines