28 |
|
* exchange exchanges objects across two threads |
29 |
|
*/ |
30 |
|
public void testExchange() { |
31 |
< |
final Exchanger e = new Exchanger(); |
31 |
> |
final Exchanger<Item> e = new Exchanger<Item>(); |
32 |
|
Thread t1 = newStartedThread(new CheckedRunnable() { |
33 |
|
public void realRun() throws InterruptedException { |
34 |
|
assertSame(one, e.exchange(two)); |
48 |
|
* timed exchange exchanges objects across two threads |
49 |
|
*/ |
50 |
|
public void testTimedExchange() { |
51 |
< |
final Exchanger e = new Exchanger(); |
51 |
> |
final Exchanger<Item> e = new Exchanger<Item>(); |
52 |
|
Thread t1 = newStartedThread(new CheckedRunnable() { |
53 |
|
public void realRun() throws Exception { |
54 |
|
assertSame(one, e.exchange(two, LONG_DELAY_MS, MILLISECONDS)); |
65 |
|
} |
66 |
|
|
67 |
|
/** |
68 |
< |
* interrupt during wait for exchange throws IE |
68 |
> |
* interrupt during wait for exchange throws InterruptedException |
69 |
|
*/ |
70 |
|
public void testExchange_InterruptedException() { |
71 |
< |
final Exchanger e = new Exchanger(); |
71 |
> |
final Exchanger<Item> e = new Exchanger<Item>(); |
72 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
73 |
|
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
74 |
|
public void realRun() throws InterruptedException { |
82 |
|
} |
83 |
|
|
84 |
|
/** |
85 |
< |
* interrupt during wait for timed exchange throws IE |
85 |
> |
* interrupt during wait for timed exchange throws InterruptedException |
86 |
|
*/ |
87 |
|
public void testTimedExchange_InterruptedException() { |
88 |
< |
final Exchanger e = new Exchanger(); |
88 |
> |
final Exchanger<Item> e = new Exchanger<Item>(); |
89 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
90 |
|
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
91 |
|
public void realRun() throws Exception { |
102 |
|
* timeout during wait for timed exchange throws TimeoutException |
103 |
|
*/ |
104 |
|
public void testExchange_TimeoutException() { |
105 |
< |
final Exchanger e = new Exchanger(); |
105 |
> |
final Exchanger<Item> e = new Exchanger<Item>(); |
106 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
107 |
|
public void realRun() throws Exception { |
108 |
|
long startTime = System.nanoTime(); |
120 |
|
* If one exchanging thread is interrupted, another succeeds. |
121 |
|
*/ |
122 |
|
public void testReplacementAfterExchange() { |
123 |
< |
final Exchanger e = new Exchanger(); |
123 |
> |
final Exchanger<Item> e = new Exchanger<Item>(); |
124 |
|
final CountDownLatch exchanged = new CountDownLatch(2); |
125 |
|
final CountDownLatch interrupted = new CountDownLatch(1); |
126 |
|
Thread t1 = newStartedThread(new CheckedInterruptedRunnable() { |
133 |
|
public void realRun() throws InterruptedException { |
134 |
|
assertSame(one, e.exchange(two)); |
135 |
|
exchanged.countDown(); |
136 |
< |
interrupted.await(); |
136 |
> |
await(interrupted); |
137 |
|
assertSame(three, e.exchange(one)); |
138 |
|
}}); |
139 |
|
Thread t3 = newStartedThread(new CheckedRunnable() { |
140 |
|
public void realRun() throws InterruptedException { |
141 |
< |
interrupted.await(); |
141 |
> |
await(interrupted); |
142 |
|
assertSame(one, e.exchange(three)); |
143 |
|
}}); |
144 |
|
|