41 |
|
} |
42 |
|
|
43 |
|
public static Test suite() { |
44 |
+ |
class Implementation implements CollectionImplementation { |
45 |
+ |
public Class<?> klazz() { return ArrayBlockingQueue.class; } |
46 |
+ |
public Collection emptyCollection() { return new ArrayBlockingQueue(SIZE, false); } |
47 |
+ |
public Object makeElement(int i) { return i; } |
48 |
+ |
public boolean isConcurrent() { return true; } |
49 |
+ |
public boolean permitsNulls() { return false; } |
50 |
+ |
} |
51 |
|
return newTestSuite(ArrayBlockingQueueTest.class, |
52 |
|
new Fair().testSuite(), |
53 |
< |
new NonFair().testSuite()); |
53 |
> |
new NonFair().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 ArrayBlockingQueue<Integer> populatedQueue(int n) { |
62 |
|
ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<Integer>(n); |
66 |
|
assertFalse(q.isEmpty()); |
67 |
|
assertEquals(0, q.remainingCapacity()); |
68 |
|
assertEquals(n, q.size()); |
69 |
+ |
assertEquals((Integer) 0, q.peek()); |
70 |
|
return q; |
71 |
|
} |
72 |
|
|
460 |
|
final CountDownLatch aboutToWait = new CountDownLatch(1); |
461 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
462 |
|
public void realRun() throws InterruptedException { |
463 |
+ |
long startTime = System.nanoTime(); |
464 |
|
for (int i = 0; i < SIZE; ++i) { |
455 |
– |
long t0 = System.nanoTime(); |
465 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
457 |
– |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
466 |
|
} |
459 |
– |
long t0 = System.nanoTime(); |
467 |
|
aboutToWait.countDown(); |
468 |
|
try { |
469 |
< |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
469 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
470 |
|
shouldThrow(); |
471 |
|
} catch (InterruptedException success) { |
472 |
< |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
472 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
473 |
|
} |
474 |
|
}}); |
475 |
|
|
476 |
< |
aboutToWait.await(); |
477 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
476 |
> |
await(aboutToWait); |
477 |
> |
waitForThreadToEnterWaitState(t); |
478 |
|
t.interrupt(); |
479 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
479 |
> |
awaitTermination(t); |
480 |
|
checkEmpty(q); |
481 |
|
} |
482 |
|
|