41 |
|
} |
42 |
|
|
43 |
|
public static Test suite() { |
44 |
+ |
class Implementation implements CollectionImplementation { |
45 |
+ |
public Class<?> klazz() { return LinkedBlockingQueue.class; } |
46 |
+ |
public Collection emptyCollection() { return new LinkedBlockingQueue(); } |
47 |
+ |
public Object makeElement(int i) { return i; } |
48 |
+ |
public boolean isConcurrent() { return true; } |
49 |
+ |
public boolean permitsNulls() { return false; } |
50 |
+ |
} |
51 |
|
return newTestSuite(LinkedBlockingQueueTest.class, |
52 |
|
new Unbounded().testSuite(), |
53 |
< |
new Bounded().testSuite()); |
53 |
> |
new Bounded().testSuite(), |
54 |
> |
CollectionTest.testSuite(new Implementation())); |
55 |
|
} |
56 |
|
|
57 |
|
/** |
58 |
|
* Returns a new queue of given size containing consecutive |
59 |
< |
* Integers 0 ... n. |
59 |
> |
* Integers 0 ... n - 1. |
60 |
|
*/ |
61 |
|
private LinkedBlockingQueue<Integer> populatedQueue(int n) { |
62 |
|
LinkedBlockingQueue<Integer> q = |
67 |
|
assertFalse(q.isEmpty()); |
68 |
|
assertEquals(0, q.remainingCapacity()); |
69 |
|
assertEquals(n, q.size()); |
70 |
+ |
assertEquals((Integer) 0, q.peek()); |
71 |
|
return q; |
72 |
|
} |
73 |
|
|
449 |
|
final CountDownLatch aboutToWait = new CountDownLatch(1); |
450 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
451 |
|
public void realRun() throws InterruptedException { |
452 |
+ |
long startTime = System.nanoTime(); |
453 |
|
for (int i = 0; i < SIZE; ++i) { |
444 |
– |
long t0 = System.nanoTime(); |
454 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
446 |
– |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
455 |
|
} |
448 |
– |
long t0 = System.nanoTime(); |
456 |
|
aboutToWait.countDown(); |
457 |
|
try { |
458 |
< |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
458 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
459 |
|
shouldThrow(); |
460 |
|
} catch (InterruptedException success) { |
461 |
< |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
461 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
462 |
|
} |
463 |
|
}}); |
464 |
|
|
465 |
< |
aboutToWait.await(); |
466 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
465 |
> |
await(aboutToWait); |
466 |
> |
waitForThreadToEnterWaitState(t); |
467 |
|
t.interrupt(); |
468 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
468 |
> |
awaitTermination(t); |
469 |
|
checkEmpty(q); |
470 |
|
} |
471 |
|
|