354 |
|
for (int i = 0; i < SIZE; ++i) { |
355 |
|
long t0 = System.nanoTime(); |
356 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
357 |
< |
assertTrue(millisElapsedSince(t0) < SHORT_DELAY_MS); |
357 |
> |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
358 |
|
} |
359 |
+ |
long t0 = System.nanoTime(); |
360 |
|
aboutToWait.countDown(); |
361 |
|
try { |
362 |
|
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
363 |
|
shouldThrow(); |
364 |
< |
} catch (InterruptedException success) {} |
364 |
> |
} catch (InterruptedException success) { |
365 |
> |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
366 |
> |
} |
367 |
|
}}); |
368 |
|
|
369 |
|
aboutToWait.await(); |
385 |
|
for (int i = 0; i < SIZE; ++i) { |
386 |
|
long t0 = System.nanoTime(); |
387 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
388 |
< |
assertTrue(millisElapsedSince(t0) < SHORT_DELAY_MS); |
388 |
> |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
389 |
|
} |
390 |
|
try { |
391 |
|
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
550 |
|
} |
551 |
|
|
552 |
|
/** |
553 |
< |
* toArray() contains all elements |
553 |
> |
* toArray() contains all elements in FIFO order |
554 |
|
*/ |
555 |
< |
public void testToArray() throws InterruptedException { |
555 |
> |
public void testToArray() { |
556 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
557 |
|
Object[] o = q.toArray(); |
558 |
|
for (int i = 0; i < o.length; i++) { |
559 |
< |
assertEquals(o[i], q.take()); |
559 |
> |
assertSame(o[i], q.poll()); |
560 |
|
} |
561 |
|
} |
562 |
|
|
563 |
|
/** |
564 |
< |
* toArray(a) contains all elements |
564 |
> |
* toArray(a) contains all elements in FIFO order |
565 |
|
*/ |
566 |
< |
public void testToArray2() throws InterruptedException { |
566 |
> |
public void testToArray2() { |
567 |
|
LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
568 |
|
Integer[] ints = new Integer[SIZE]; |
569 |
< |
ints = q.toArray(ints); |
569 |
> |
assertSame(ints, q.toArray(ints)); |
570 |
|
for (int i = 0; i < ints.length; i++) { |
571 |
< |
assertEquals(ints[i], q.take()); |
571 |
> |
assertSame(ints[i], q.poll()); |
572 |
|
} |
573 |
|
} |
574 |
|
|
575 |
|
/** |
576 |
|
* toArray(null) throws NullPointerException |
577 |
|
*/ |
578 |
< |
public void testToArray_BadArg() { |
578 |
> |
public void testToArray_NullArg() { |
579 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
580 |
|
try { |
581 |
< |
Object o[] = q.toArray(null); |
581 |
> |
q.toArray(null); |
582 |
|
shouldThrow(); |
583 |
|
} catch (NullPointerException success) {} |
584 |
|
} |
585 |
|
|
586 |
|
/** |
587 |
< |
* toArray(incompatible array type) throws CCE |
587 |
> |
* toArray(incompatible array type) throws ArrayStoreException |
588 |
|
*/ |
589 |
|
public void testToArray1_BadArg() { |
590 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
591 |
|
try { |
592 |
< |
Object o[] = q.toArray(new String[10]); |
592 |
> |
q.toArray(new String[10]); |
593 |
|
shouldThrow(); |
594 |
|
} catch (ArrayStoreException success) {} |
595 |
|
} |
913 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
914 |
|
public void realRun() throws InterruptedException { |
915 |
|
threadStarted.countDown(); |
916 |
< |
q.transfer(SIZE); |
916 |
> |
q.transfer(five); |
917 |
|
checkEmpty(q); |
918 |
|
}}); |
919 |
|
|
920 |
|
threadStarted.await(); |
921 |
|
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
919 |
– |
assertTrue(t.isAlive()); |
922 |
|
assertEquals(1, q.size()); |
923 |
< |
assertEquals(SIZE, (int) q.poll()); |
923 |
> |
assertSame(five, q.poll()); |
924 |
|
checkEmpty(q); |
925 |
|
awaitTermination(t, MEDIUM_DELAY_MS); |
926 |
|
} |
1097 |
|
} |
1098 |
|
|
1099 |
|
/** |
1100 |
< |
* tryTransfer gives up after the timeout and return false |
1100 |
> |
* tryTransfer gives up after the timeout and returns false |
1101 |
|
*/ |
1102 |
|
public void testTryTransfer6() throws InterruptedException { |
1103 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |