summaryrefslogtreecommitdiff
path: root/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java
diff options
context:
space:
mode:
authorPrzemyslaw Szczepaniak <pszczepaniak@google.com>2016-03-11 15:59:10 +0000
committerPrzemyslaw Szczepaniak <pszczepaniak@google.com>2016-03-15 10:42:51 +0000
commitb8b75116273ecfdb8ffdd1869b1c0dd04570a95e (patch)
tree1622f7420704b7ca6520ba3db150bbc6ab918503 /jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java
parenta8a9d448e97004dcd25c9ccb128e09bcb7690f6a (diff)
JSR-166 update without java 1.9 method/classes
Second attempt, in frist one I've submitted some code from openJdk 1.9 that shouldn't be here, orignial change can be found at 5328e07d282bef36ac8b757bbee16a761415b2c4 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 This time with hidden/removed "@since 9" methods and classes Bug: 27426599 Change-Id: Ibd8d26e13cba091bfd983c73d005e4f8d8f5946d
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java')
-rw-r--r--jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java32
1 files changed, 17 insertions, 15 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java b/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java
index 7ef8ea34b1..918f45d67e 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(...);
+ // return new TestSuite(ReentrantReadWriteLockTest.class);
// }
/**
@@ -160,24 +160,26 @@ public class ReentrantReadWriteLockTest 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 {
+ long timeoutMillis = 2 * LONG_DELAY_MS;
switch (awaitMethod) {
case await:
c.await();
break;
case awaitTimed:
- assertTrue(c.await(2 * LONG_DELAY_MS, MILLISECONDS));
+ assertTrue(c.await(timeoutMillis, MILLISECONDS));
break;
case awaitNanos:
- long nanosRemaining = c.awaitNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
- assertTrue(nanosRemaining > 0);
+ long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
+ long nanosRemaining = c.awaitNanos(timeoutNanos);
+ assertTrue(nanosRemaining > timeoutNanos / 2);
+ assertTrue(nanosRemaining <= timeoutNanos);
break;
case awaitUntil:
- java.util.Date d = new java.util.Date();
- assertTrue(c.awaitUntil(new java.util.Date(d.getTime() + 2 * LONG_DELAY_MS)));
+ assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
break;
default:
throw new AssertionError();
@@ -241,7 +243,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());
}
}
@@ -258,7 +260,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());
}
}
@@ -275,7 +277,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());
}
}
@@ -972,11 +974,11 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
new ReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
lock.writeLock().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.writeLock().unlock();
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
}