205 |
|
} |
206 |
|
|
207 |
|
/** |
208 |
+ |
* hasQueuedThread(null) throws NPE |
209 |
+ |
*/ |
210 |
+ |
public void testHasQueuedThreadNPE() { |
211 |
+ |
final ReentrantLock sync = new ReentrantLock(); |
212 |
+ |
try { |
213 |
+ |
sync.hasQueuedThread(null); |
214 |
+ |
shouldThrow(); |
215 |
+ |
} catch (NullPointerException success) { |
216 |
+ |
} |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
/** |
220 |
+ |
* hasQueuedThread reports whether a thread is queued. |
221 |
+ |
*/ |
222 |
+ |
public void testHasQueuedThread() { |
223 |
+ |
final ReentrantLock sync = new ReentrantLock(); |
224 |
+ |
Thread t1 = new Thread(new InterruptedLockRunnable(sync)); |
225 |
+ |
Thread t2 = new Thread(new InterruptibleLockRunnable(sync)); |
226 |
+ |
try { |
227 |
+ |
assertFalse(sync.hasQueuedThread(t1)); |
228 |
+ |
assertFalse(sync.hasQueuedThread(t2)); |
229 |
+ |
sync.lock(); |
230 |
+ |
t1.start(); |
231 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
232 |
+ |
assertTrue(sync.hasQueuedThread(t1)); |
233 |
+ |
t2.start(); |
234 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
235 |
+ |
assertTrue(sync.hasQueuedThread(t1)); |
236 |
+ |
assertTrue(sync.hasQueuedThread(t2)); |
237 |
+ |
t1.interrupt(); |
238 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
239 |
+ |
assertFalse(sync.hasQueuedThread(t1)); |
240 |
+ |
assertTrue(sync.hasQueuedThread(t2)); |
241 |
+ |
sync.unlock(); |
242 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
243 |
+ |
assertFalse(sync.hasQueuedThread(t1)); |
244 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
245 |
+ |
assertFalse(sync.hasQueuedThread(t2)); |
246 |
+ |
t1.join(); |
247 |
+ |
t2.join(); |
248 |
+ |
} catch(Exception e){ |
249 |
+ |
unexpectedException(); |
250 |
+ |
} |
251 |
+ |
} |
252 |
+ |
|
253 |
+ |
|
254 |
+ |
/** |
255 |
|
* getQueuedThreads includes waiting threads |
256 |
|
*/ |
257 |
|
public void testGetQueuedThreads() { |