diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-11 15:59:10 +0000 |
---|---|---|
committer | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-14 15:40:14 +0000 |
commit | 5328e07d282bef36ac8b757bbee16a761415b2c4 (patch) | |
tree | d7fd9980442e0d647e1454f54f3d037f4b2280e7 /jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | |
parent | 8d28fc1d531b4b39def9598de89311aff112f955 (diff) |
JSR-166 update
Adapted from sources taken from CVS using:
cvs -d ':pserver:anonymous@gee.cs.oswego.edu/home/jsr166/jsr166' checkout -D "03/03/2016 10:00:00 GMT" jsr166
Bug: 27426599
Change-Id: Ic9ba278929f8747d58b69e7d67ec325064588bff
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java')
-rw-r--r-- | jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java b/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java index 17eaf76506..0024ff3bc9 100644 --- a/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java +++ b/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java @@ -30,8 +30,9 @@ public class ReentrantLockTest extends JSR166TestCase { // main(suite(), args); // } // public static Test suite() { - // return new TestSuite(...); + // return new TestSuite(ReentrantLockTest.class); // } + /** * A checked runnable calling lockInterruptibly */ @@ -150,7 +151,7 @@ public class ReentrantLockTest extends JSR166TestCase { enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil } /** - * Awaits condition using the specified AwaitMethod. + * Awaits condition "indefinitely" using the specified AwaitMethod. */ void await(Condition c, AwaitMethod awaitMethod) throws InterruptedException { @@ -163,9 +164,10 @@ public class ReentrantLockTest extends JSR166TestCase { assertTrue(c.await(timeoutMillis, MILLISECONDS)); break; case awaitNanos: - long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis); - long nanosRemaining = c.awaitNanos(nanosTimeout); - assertTrue(nanosRemaining > 0); + long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis); + long nanosRemaining = c.awaitNanos(timeoutNanos); + assertTrue(nanosRemaining > timeoutNanos / 2); + assertTrue(nanosRemaining <= timeoutNanos); break; case awaitUntil: assertTrue(c.awaitUntil(delayedDate(timeoutMillis))); @@ -428,7 +430,7 @@ public class ReentrantLockTest extends JSR166TestCase { } for (int i = SIZE; i > 0; i--) { lock.unlock(); - assertEquals(i-1, lock.getHoldCount()); + assertEquals(i - 1, lock.getHoldCount()); } } @@ -568,11 +570,11 @@ public class ReentrantLockTest extends JSR166TestCase { final ReentrantLock lock = new ReentrantLock(fair); final Condition c = lock.newCondition(); lock.lock(); - long startTime = System.nanoTime(); - long timeoutMillis = 10; - java.util.Date d = new java.util.Date(); - assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis))); - assertTrue(millisElapsedSince(startTime) >= timeoutMillis); + // We shouldn't assume that nanoTime and currentTimeMillis + // use the same time source, so don't use nanoTime here. + java.util.Date delayedDate = delayedDate(timeoutMillis()); + assertFalse(c.awaitUntil(delayedDate)); + assertTrue(new java.util.Date().getTime() >= delayedDate.getTime()); lock.unlock(); } catch (InterruptedException fail) { threadUnexpectedException(fail); } } |