diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-15 09:42:33 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-03-15 09:42:33 +0000 |
commit | a8a9d448e97004dcd25c9ccb128e09bcb7690f6a (patch) | |
tree | 214d4e0cdccf19471194d03dd3172933336910f1 /jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | |
parent | 37f9fec54f50b2e0898ee2b61d058c4de879e38b (diff) | |
parent | ed4f365789d43b1961657195df223a19bf4ef20f (diff) |
Merge "Revert "JSR-166 update""
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java')
-rw-r--r-- | jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java b/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java index 918f45d67e..7ef8ea34b1 100644 --- a/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java +++ b/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java @@ -31,7 +31,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase { // main(suite(), args); // } // public static Test suite() { - // return new TestSuite(ReentrantReadWriteLockTest.class); + // return new TestSuite(...); // } /** @@ -160,26 +160,24 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase { enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil } /** - * Awaits condition "indefinitely" using the specified AwaitMethod. + * Awaits condition using the specified AwaitMethod. */ void await(Condition c, AwaitMethod awaitMethod) throws InterruptedException { - long timeoutMillis = 2 * LONG_DELAY_MS; switch (awaitMethod) { case await: c.await(); break; case awaitTimed: - assertTrue(c.await(timeoutMillis, MILLISECONDS)); + assertTrue(c.await(2 * LONG_DELAY_MS, MILLISECONDS)); break; case awaitNanos: - long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis); - long nanosRemaining = c.awaitNanos(timeoutNanos); - assertTrue(nanosRemaining > timeoutNanos / 2); - assertTrue(nanosRemaining <= timeoutNanos); + long nanosRemaining = c.awaitNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS)); + assertTrue(nanosRemaining > 0); break; case awaitUntil: - assertTrue(c.awaitUntil(delayedDate(timeoutMillis))); + java.util.Date d = new java.util.Date(); + assertTrue(c.awaitUntil(new java.util.Date(d.getTime() + 2 * LONG_DELAY_MS))); break; default: throw new AssertionError(); @@ -243,7 +241,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase { } for (int i = SIZE; i > 0; i--) { lock.writeLock().unlock(); - assertEquals(i - 1,lock.getWriteHoldCount()); + assertEquals(i-1,lock.getWriteHoldCount()); } } @@ -260,7 +258,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase { } for (int i = SIZE; i > 0; i--) { lock.writeLock().unlock(); - assertEquals(i - 1,lock.writeLock().getHoldCount()); + assertEquals(i-1,lock.writeLock().getHoldCount()); } } @@ -277,7 +275,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase { } for (int i = SIZE; i > 0; i--) { lock.readLock().unlock(); - assertEquals(i - 1,lock.getReadHoldCount()); + assertEquals(i-1,lock.getReadHoldCount()); } } @@ -974,11 +972,11 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase { new ReentrantReadWriteLock(fair); final Condition c = lock.writeLock().newCondition(); lock.writeLock().lock(); - // 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()); + 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); lock.writeLock().unlock(); } catch (InterruptedException fail) { threadUnexpectedException(fail); } } |