--- jsr166/src/test/tck/LinkedTransferQueueTest.java 2010/11/04 01:04:54 1.38 +++ jsr166/src/test/tck/LinkedTransferQueueTest.java 2011/03/15 19:47:06 1.44 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ * Other contributors include John Vint */ @@ -40,33 +40,6 @@ public class LinkedTransferQueueTest ext new Generic().testSuite()); } - void checkEmpty(BlockingQueue q) { - try { - assertTrue(q.isEmpty()); - assertEquals(0, q.size()); - assertNull(q.peek()); - assertNull(q.poll()); - assertNull(q.poll(0, MILLISECONDS)); - assertEquals(q.toString(), "[]"); - assertTrue(Arrays.equals(q.toArray(), new Object[0])); - assertFalse(q.iterator().hasNext()); - try { - q.element(); - shouldThrow(); - } catch (NoSuchElementException success) {} - try { - q.iterator().next(); - shouldThrow(); - } catch (NoSuchElementException success) {} - try { - q.remove(); - shouldThrow(); - } catch (NoSuchElementException success) {} - } catch (InterruptedException ie) { - threadUnexpectedException(ie); - } - } - /** * Constructor builds new queue with size being zero and empty * being true @@ -448,12 +421,18 @@ public class LinkedTransferQueueTest ext */ public void testRemoveElement() throws InterruptedException { LinkedTransferQueue q = populatedQueue(SIZE); - for (int i = 1; i < SIZE; i += 2) { + for (int i = 1; i < SIZE; i+=2) { + assertTrue(q.contains(i)); assertTrue(q.remove(i)); + assertFalse(q.contains(i)); + assertTrue(q.contains(i-1)); } - for (int i = 0; i < SIZE; i += 2) { + for (int i = 0; i < SIZE; i+=2) { + assertTrue(q.contains(i)); assertTrue(q.remove(i)); - assertFalse(q.remove(i + 1)); + assertFalse(q.contains(i)); + assertFalse(q.remove(i+1)); + assertFalse(q.contains(i+1)); } checkEmpty(q); } @@ -566,7 +545,8 @@ public class LinkedTransferQueueTest ext public void testToArray2() { LinkedTransferQueue q = populatedQueue(SIZE); Integer[] ints = new Integer[SIZE]; - assertSame(ints, q.toArray(ints)); + Integer[] array = q.toArray(ints); + assertSame(ints, array); for (int i = 0; i < ints.length; i++) { assertSame(ints[i], q.poll()); } @@ -1071,12 +1051,13 @@ public class LinkedTransferQueueTest ext } /** - * tryTransfer waits the amount given if interrupted, and - * throws interrupted exception + * tryTransfer waits the amount given, and throws + * InterruptedException when interrupted. */ public void testTryTransfer5() throws InterruptedException { final LinkedTransferQueue q = new LinkedTransferQueue(); final CountDownLatch threadStarted = new CountDownLatch(1); + assertTrue(q.isEmpty()); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { @@ -1087,9 +1068,12 @@ public class LinkedTransferQueueTest ext shouldThrow(); } catch (InterruptedException success) {} assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS); + assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); }}); threadStarted.await(); + while (q.isEmpty()) + Thread.yield(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); awaitTermination(t, MEDIUM_DELAY_MS); @@ -1139,8 +1123,8 @@ public class LinkedTransferQueueTest ext } /** - * tryTransfer attempts to enqueue into the q and fails returning - * false not enqueueing and the successive poll is null + * tryTransfer attempts to enqueue into the queue and fails + * returning false not enqueueing and the successive poll is null */ public void testTryTransfer8() throws InterruptedException { final LinkedTransferQueue q = new LinkedTransferQueue();