101 |
|
final Exchanger e = new Exchanger(); |
102 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
103 |
|
public void realRun() throws Exception { |
104 |
– |
long timeoutMillis = SHORT_DELAY_MS; |
104 |
|
long startTime = System.nanoTime(); |
105 |
|
try { |
106 |
< |
e.exchange(null, timeoutMillis, MILLISECONDS); |
106 |
> |
e.exchange(null, timeoutMillis(), MILLISECONDS); |
107 |
|
shouldThrow(); |
108 |
< |
} catch (TimeoutException success) { |
109 |
< |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
111 |
< |
} |
108 |
> |
} catch (TimeoutException success) {} |
109 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
110 |
|
}}); |
111 |
|
|
112 |
|
awaitTermination(t); |
115 |
|
/** |
116 |
|
* If one exchanging thread is interrupted, another succeeds. |
117 |
|
*/ |
118 |
< |
public void testReplacementAfterExchange() throws InterruptedException { |
118 |
> |
public void testReplacementAfterExchange() { |
119 |
|
final Exchanger e = new Exchanger(); |
120 |
|
final CountDownLatch exchanged = new CountDownLatch(2); |
121 |
|
final CountDownLatch interrupted = new CountDownLatch(1); |
140 |
|
|
141 |
|
await(exchanged); |
142 |
|
t1.interrupt(); |
145 |
– |
interrupted.countDown(); |
143 |
|
awaitTermination(t1); |
144 |
+ |
interrupted.countDown(); |
145 |
|
awaitTermination(t2); |
146 |
|
awaitTermination(t3); |
147 |
|
} |