18 |
|
import java.util.NoSuchElementException; |
19 |
|
import java.util.concurrent.*; |
20 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
21 |
+ |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
22 |
|
import junit.framework.Test; |
23 |
|
import junit.framework.TestSuite; |
24 |
|
|
808 |
|
} |
809 |
|
|
810 |
|
/** |
811 |
< |
* drainTo(c, n) empties first max {n, size} elements of queue into c |
811 |
> |
* drainTo(c, n) empties first min(n, size) elements of queue into c |
812 |
|
*/ |
813 |
|
public void testDrainToN() { |
814 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
1054 |
|
|
1055 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1056 |
|
public void realRun() throws InterruptedException { |
1057 |
+ |
long t0 = System.nanoTime(); |
1058 |
|
assertFalse(q.tryTransfer(new Object(), |
1059 |
|
SHORT_DELAY_MS, MILLISECONDS)); |
1060 |
+ |
long elapsed = NANOSECONDS.toMillis(System.nanoTime() - t0); |
1061 |
+ |
assertTrue(elapsed >= SHORT_DELAY_MS); |
1062 |
|
}}); |
1063 |
|
|
1060 |
– |
Thread.sleep(SMALL_DELAY_MS); |
1064 |
|
checkEmpty(q); |
1065 |
< |
t.join(); |
1065 |
> |
awaitTermination(t, MEDIUM_DELAY_MS); |
1066 |
> |
checkEmpty(q); |
1067 |
|
} |
1068 |
|
|
1069 |
|
/** |