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() { |
498 |
|
final Condition c = lock.newCondition(); |
499 |
|
try { |
500 |
|
lock.lock(); |
501 |
< |
assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
501 |
> |
c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
502 |
|
lock.unlock(); |
503 |
|
} |
504 |
|
catch (Exception ex) { |
515 |
|
try { |
516 |
|
lock.lock(); |
517 |
|
java.util.Date d = new java.util.Date(); |
518 |
< |
assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + 10))); |
518 |
> |
c.awaitUntil(new java.util.Date(d.getTime() + 10)); |
519 |
|
lock.unlock(); |
520 |
|
} |
521 |
|
catch (Exception ex) { |
886 |
|
lock.lock(); |
887 |
|
c.signal(); |
888 |
|
lock.unlock(); |
889 |
< |
assert(t.isInterrupted()); |
889 |
> |
assertTrue(t.isInterrupted()); |
890 |
|
t.join(SHORT_DELAY_MS); |
891 |
|
assertFalse(t.isAlive()); |
892 |
|
} |