22 |
|
|
23 |
|
public class ReentrantLockTest extends JSR166TestCase { |
24 |
|
public static void main(String[] args) { |
25 |
< |
junit.textui.TestRunner.run(suite()); |
25 |
> |
main(suite(), args); |
26 |
|
} |
27 |
|
public static Test suite() { |
28 |
|
return new TestSuite(ReentrantLockTest.class); |
146 |
|
enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil } |
147 |
|
|
148 |
|
/** |
149 |
< |
* Awaits condition using the specified AwaitMethod. |
149 |
> |
* Awaits condition "indefinitely" using the specified AwaitMethod. |
150 |
|
*/ |
151 |
|
void await(Condition c, AwaitMethod awaitMethod) |
152 |
|
throws InterruptedException { |
159 |
|
assertTrue(c.await(timeoutMillis, MILLISECONDS)); |
160 |
|
break; |
161 |
|
case awaitNanos: |
162 |
< |
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis); |
163 |
< |
long nanosRemaining = c.awaitNanos(nanosTimeout); |
164 |
< |
assertTrue(nanosRemaining > 0); |
162 |
> |
long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis); |
163 |
> |
long nanosRemaining = c.awaitNanos(timeoutNanos); |
164 |
> |
assertTrue(nanosRemaining > timeoutNanos / 2); |
165 |
> |
assertTrue(nanosRemaining <= timeoutNanos); |
166 |
|
break; |
167 |
|
case awaitUntil: |
168 |
|
assertTrue(c.awaitUntil(delayedDate(timeoutMillis))); |
425 |
|
} |
426 |
|
for (int i = SIZE; i > 0; i--) { |
427 |
|
lock.unlock(); |
428 |
< |
assertEquals(i-1, lock.getHoldCount()); |
428 |
> |
assertEquals(i - 1, lock.getHoldCount()); |
429 |
|
} |
430 |
|
} |
431 |
|
|
461 |
|
barrier.await(); |
462 |
|
awaitTermination(t); |
463 |
|
assertFalse(lock.isLocked()); |
464 |
< |
} catch (Exception e) { |
464 |
< |
threadUnexpectedException(e); |
465 |
< |
} |
464 |
> |
} catch (Exception fail) { threadUnexpectedException(fail); } |
465 |
|
} |
466 |
|
|
467 |
|
/** |
473 |
|
final PublicReentrantLock lock = new PublicReentrantLock(fair); |
474 |
|
try { |
475 |
|
lock.lockInterruptibly(); |
476 |
< |
} catch (InterruptedException ie) { |
478 |
< |
threadUnexpectedException(ie); |
479 |
< |
} |
476 |
> |
} catch (InterruptedException fail) { threadUnexpectedException(fail); } |
477 |
|
assertLockedByMoi(lock); |
478 |
|
Thread t = newStartedThread(new InterruptedLockRunnable(lock)); |
479 |
|
waitForQueuedThread(lock, t); |
534 |
|
assertTrue(nanosRemaining <= 0); |
535 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
536 |
|
lock.unlock(); |
537 |
< |
} catch (InterruptedException e) { |
541 |
< |
threadUnexpectedException(e); |
542 |
< |
} |
537 |
> |
} catch (InterruptedException fail) { threadUnexpectedException(fail); } |
538 |
|
} |
539 |
|
|
540 |
|
/** |
552 |
|
assertFalse(c.await(timeoutMillis, MILLISECONDS)); |
553 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
554 |
|
lock.unlock(); |
555 |
< |
} catch (InterruptedException e) { |
561 |
< |
threadUnexpectedException(e); |
562 |
< |
} |
555 |
> |
} catch (InterruptedException fail) { threadUnexpectedException(fail); } |
556 |
|
} |
557 |
|
|
558 |
|
/** |
571 |
|
assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis))); |
572 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
573 |
|
lock.unlock(); |
574 |
< |
} catch (InterruptedException e) { |
582 |
< |
threadUnexpectedException(e); |
583 |
< |
} |
574 |
> |
} catch (InterruptedException fail) { threadUnexpectedException(fail); } |
575 |
|
} |
576 |
|
|
577 |
|
/** |