--- jsr166/src/test/tck/LinkedTransferQueueTest.java 2010/10/29 07:01:51 1.34 +++ jsr166/src/test/tck/LinkedTransferQueueTest.java 2010/11/18 20:21:53 1.42 @@ -354,13 +354,16 @@ public class LinkedTransferQueueTest ext for (int i = 0; i < SIZE; ++i) { long t0 = System.nanoTime(); assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); - assertTrue(millisElapsedSince(t0) < SHORT_DELAY_MS); + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); } + long t0 = System.nanoTime(); aboutToWait.countDown(); try { q.poll(MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); - } catch (InterruptedException success) {} + } catch (InterruptedException success) { + assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); + } }}); aboutToWait.await(); @@ -382,7 +385,7 @@ public class LinkedTransferQueueTest ext for (int i = 0; i < SIZE; ++i) { long t0 = System.nanoTime(); assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); - assertTrue(millisElapsedSince(t0) < SHORT_DELAY_MS); + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); } try { q.poll(MEDIUM_DELAY_MS, MILLISECONDS); @@ -445,12 +448,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); } @@ -547,46 +556,47 @@ public class LinkedTransferQueueTest ext } /** - * toArray() contains all elements + * toArray() contains all elements in FIFO order */ - public void testToArray() throws InterruptedException { + public void testToArray() { LinkedTransferQueue q = populatedQueue(SIZE); Object[] o = q.toArray(); for (int i = 0; i < o.length; i++) { - assertEquals(o[i], q.take()); + assertSame(o[i], q.poll()); } } /** - * toArray(a) contains all elements + * toArray(a) contains all elements in FIFO order */ - public void testToArray2() throws InterruptedException { + public void testToArray2() { LinkedTransferQueue q = populatedQueue(SIZE); Integer[] ints = new Integer[SIZE]; - ints = q.toArray(ints); + Integer[] array = q.toArray(ints); + assertSame(ints, array); for (int i = 0; i < ints.length; i++) { - assertEquals(ints[i], q.take()); + assertSame(ints[i], q.poll()); } } /** * toArray(null) throws NullPointerException */ - public void testToArray_BadArg() { + public void testToArray_NullArg() { LinkedTransferQueue q = populatedQueue(SIZE); try { - Object o[] = q.toArray(null); + q.toArray(null); shouldThrow(); } catch (NullPointerException success) {} } /** - * toArray(incompatible array type) throws CCE + * toArray(incompatible array type) throws ArrayStoreException */ public void testToArray1_BadArg() { LinkedTransferQueue q = populatedQueue(SIZE); try { - Object o[] = q.toArray(new String[10]); + q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} } @@ -1068,12 +1078,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 { @@ -1084,9 +1095,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); @@ -1136,8 +1150,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();