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
diff --git a/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java b/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java
index 7ef8ea3..918f45d 100644
--- a/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java
+++ b/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java
@@ -31,7 +31,7 @@
// main(suite(), args);
// }
// public static Test suite() {
- // return new TestSuite(...);
+ // return new TestSuite(ReentrantReadWriteLockTest.class);
// }
/**
@@ -160,24 +160,26 @@
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 @@
}
for (int i = SIZE; i > 0; i--) {
lock.writeLock().unlock();
- assertEquals(i-1,lock.getWriteHoldCount());
+ assertEquals(i - 1,lock.getWriteHoldCount());
}
}
@@ -258,7 +260,7 @@
}
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 @@
}
for (int i = SIZE; i > 0; i--) {
lock.readLock().unlock();
- assertEquals(i-1,lock.getReadHoldCount());
+ assertEquals(i - 1,lock.getReadHoldCount());
}
}
@@ -972,11 +974,11 @@
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); }
}