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

Comparing jsr166/src/test/tck/LinkedTransferQueueTest.java (file contents):
Revision 1.38 by jsr166, Thu Nov 4 01:04:54 2010 UTC vs.
Revision 1.44 by jsr166, Tue Mar 15 19:47:06 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include John Vint
6   */
7  
# Line 40 | Line 40 | public class LinkedTransferQueueTest ext
40                              new Generic().testSuite());
41      }
42  
43    void checkEmpty(BlockingQueue q) {
44        try {
45            assertTrue(q.isEmpty());
46            assertEquals(0, q.size());
47            assertNull(q.peek());
48            assertNull(q.poll());
49            assertNull(q.poll(0, MILLISECONDS));
50            assertEquals(q.toString(), "[]");
51            assertTrue(Arrays.equals(q.toArray(), new Object[0]));
52            assertFalse(q.iterator().hasNext());
53            try {
54                q.element();
55                shouldThrow();
56            } catch (NoSuchElementException success) {}
57            try {
58                q.iterator().next();
59                shouldThrow();
60            } catch (NoSuchElementException success) {}
61            try {
62                q.remove();
63                shouldThrow();
64            } catch (NoSuchElementException success) {}
65        } catch (InterruptedException ie) {
66            threadUnexpectedException(ie);
67        }
68    }
69
43      /**
44       * Constructor builds new queue with size being zero and empty
45       * being true
# Line 448 | Line 421 | public class LinkedTransferQueueTest ext
421       */
422      public void testRemoveElement() throws InterruptedException {
423          LinkedTransferQueue q = populatedQueue(SIZE);
424 <        for (int i = 1; i < SIZE; i += 2) {
424 >        for (int i = 1; i < SIZE; i+=2) {
425 >            assertTrue(q.contains(i));
426              assertTrue(q.remove(i));
427 +            assertFalse(q.contains(i));
428 +            assertTrue(q.contains(i-1));
429          }
430 <        for (int i = 0; i < SIZE; i += 2) {
430 >        for (int i = 0; i < SIZE; i+=2) {
431 >            assertTrue(q.contains(i));
432              assertTrue(q.remove(i));
433 <            assertFalse(q.remove(i + 1));
433 >            assertFalse(q.contains(i));
434 >            assertFalse(q.remove(i+1));
435 >            assertFalse(q.contains(i+1));
436          }
437          checkEmpty(q);
438      }
# Line 566 | Line 545 | public class LinkedTransferQueueTest ext
545      public void testToArray2() {
546          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
547          Integer[] ints = new Integer[SIZE];
548 <        assertSame(ints, q.toArray(ints));
548 >        Integer[] array = q.toArray(ints);
549 >        assertSame(ints, array);
550          for (int i = 0; i < ints.length; i++) {
551              assertSame(ints[i], q.poll());
552          }
# Line 1071 | Line 1051 | public class LinkedTransferQueueTest ext
1051      }
1052  
1053      /**
1054 <     * tryTransfer waits the amount given if interrupted, and
1055 <     * throws interrupted exception
1054 >     * tryTransfer waits the amount given, and throws
1055 >     * InterruptedException when interrupted.
1056       */
1057      public void testTryTransfer5() throws InterruptedException {
1058          final LinkedTransferQueue q = new LinkedTransferQueue();
1059          final CountDownLatch threadStarted = new CountDownLatch(1);
1060 +        assertTrue(q.isEmpty());
1061  
1062          Thread t = newStartedThread(new CheckedRunnable() {
1063              public void realRun() throws InterruptedException {
# Line 1087 | Line 1068 | public class LinkedTransferQueueTest ext
1068                      shouldThrow();
1069                  } catch (InterruptedException success) {}
1070                  assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1071 +                assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
1072              }});
1073  
1074          threadStarted.await();
1075 +        while (q.isEmpty())
1076 +            Thread.yield();
1077          Thread.sleep(SHORT_DELAY_MS);
1078          t.interrupt();
1079          awaitTermination(t, MEDIUM_DELAY_MS);
# Line 1139 | Line 1123 | public class LinkedTransferQueueTest ext
1123      }
1124  
1125      /**
1126 <     * tryTransfer attempts to enqueue into the q and fails returning
1127 <     * false not enqueueing and the successive poll is null
1126 >     * tryTransfer attempts to enqueue into the queue and fails
1127 >     * returning false not enqueueing and the successive poll is null
1128       */
1129      public void testTryTransfer8() throws InterruptedException {
1130          final LinkedTransferQueue q = new LinkedTransferQueue();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines