14 |
|
|
15 |
|
public class SynchronousQueueTest extends JSR166TestCase { |
16 |
|
|
17 |
+ |
public static class Fair extends BlockingQueueTest { |
18 |
+ |
protected BlockingQueue emptyCollection() { |
19 |
+ |
return new SynchronousQueue(true); |
20 |
+ |
} |
21 |
+ |
} |
22 |
+ |
|
23 |
+ |
public static class NonFair extends BlockingQueueTest { |
24 |
+ |
protected BlockingQueue emptyCollection() { |
25 |
+ |
return new SynchronousQueue(false); |
26 |
+ |
} |
27 |
+ |
} |
28 |
+ |
|
29 |
|
public static void main(String[] args) { |
30 |
|
junit.textui.TestRunner.run(suite()); |
31 |
|
} |
32 |
|
|
33 |
|
public static Test suite() { |
34 |
< |
return new TestSuite(SynchronousQueueTest.class); |
34 |
> |
return newTestSuite(SynchronousQueueTest.class, |
35 |
> |
new Fair().testSuite(), |
36 |
> |
new NonFair().testSuite()); |
37 |
|
} |
38 |
|
|
39 |
|
/** |
352 |
|
t.interrupt(); |
353 |
|
t.join(); |
354 |
|
} |
341 |
– |
|
342 |
– |
/** |
343 |
– |
* timed poll before a delayed offer fails; after offer succeeds; |
344 |
– |
* on interruption throws |
345 |
– |
*/ |
346 |
– |
public void testTimedPollWithOffer() throws InterruptedException { |
347 |
– |
final SynchronousQueue q = new SynchronousQueue(); |
348 |
– |
Thread t = new Thread(new CheckedRunnable() { |
349 |
– |
public void realRun() throws InterruptedException { |
350 |
– |
try { |
351 |
– |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
352 |
– |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
353 |
– |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
354 |
– |
shouldThrow(); |
355 |
– |
} catch (InterruptedException success) {} |
356 |
– |
}}); |
357 |
– |
|
358 |
– |
t.start(); |
359 |
– |
Thread.sleep(SMALL_DELAY_MS); |
360 |
– |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
361 |
– |
t.interrupt(); |
362 |
– |
t.join(); |
363 |
– |
} |
355 |
|
|
356 |
|
/** |
357 |
|
* Interrupted timed poll throws InterruptedException instead of |