Update JSR166 tck tests.
The following tests have been omitted because they are
unsupported :
- Atomic8Test.java
- CompletableFutureTest.java
- ConcurrentHashMap8Test.java
- DoubleAccumulatorTest.java
- DoubleAdderTest.java
- ForkJoinPool8Test.java
- ForkJoinTask8Test.java
- LongAccumulatorTest.java
- LongAdderTest.java
- SplittableRandomTest.java
- StampedLockTest.java
- ThreadLocalRandom8Test.java
- ThreadPoolExecutor9Test.java
A package declaration has been added to all files (package jsr166;)
and the base-class JSR166Test has been changed not to rely on features
that aren't available on android / junit in the android environment.
We also avoid using junit4 style TestSuite declarations. While the CTS
test runner handles them properly usually, it trips over itself when it
encounters a failure and tries to run each test in an invidual process
and fails each test for no good reason (needs investigation on the CTS
side of things)
bug: 20628776
(cherry picked from commit 5da8b2b3cac51f0f592a5e1941bd84eade9648cd)
Change-Id: If35be0881ad8da4c604ce6683149b15c1a85f289
diff --git a/jsr166-tests/src/test/java/jsr166/AbstractQueuedLongSynchronizerTest.java b/jsr166-tests/src/test/java/jsr166/AbstractQueuedLongSynchronizerTest.java
index d957e61..8604d86 100644
--- a/jsr166-tests/src/test/java/jsr166/AbstractQueuedLongSynchronizerTest.java
+++ b/jsr166-tests/src/test/java/jsr166/AbstractQueuedLongSynchronizerTest.java
@@ -8,13 +8,29 @@
package jsr166;
-import junit.framework.*;
-import java.util.*;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject;
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
public class AbstractQueuedLongSynchronizerTest extends JSR166TestCase {
+ // android-note: Removed because the CTS runner does a bad job of
+ // retrying tests that have suite() declarations.
+ //
+ // public static void main(String[] args) {
+ // main(suite(), args);
+ // }
+ // public static Test suite() {
+ // return new TestSuite(...);
+ // }
/**
* A simple mutex class, adapted from the class javadoc. Exclusive
@@ -83,7 +99,7 @@
}
public boolean tryReleaseShared(long ignore) {
- setState(1 << 62);
+ setState(1L << 62);
return true;
}
}
@@ -191,7 +207,7 @@
new HashSet<Thread>(Arrays.asList(threads)));
}
- enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil };
+ enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil }
/**
* Awaits condition using the specified AwaitMethod.
@@ -214,6 +230,8 @@
case awaitUntil:
assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
break;
+ default:
+ throw new AssertionError();
}
}
@@ -1184,7 +1202,6 @@
public void testTryAcquireSharedNanos_Timeout() {
final BooleanLatch l = new BooleanLatch();
final BooleanLatch observedQueued = new BooleanLatch();
- final long timeoutMillis = timeoutMillis();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
assertFalse(l.isSignalled());
@@ -1206,4 +1223,28 @@
assertFalse(l.isSignalled());
}
+ /**
+ * awaitNanos/timed await with 0 wait times out immediately
+ */
+ public void testAwait_Zero() throws InterruptedException {
+ final Mutex sync = new Mutex();
+ final ConditionObject c = sync.newCondition();
+ sync.acquire();
+ assertTrue(c.awaitNanos(0L) <= 0);
+ assertFalse(c.await(0L, NANOSECONDS));
+ sync.release();
+ }
+
+ /**
+ * awaitNanos/timed await with maximum negative wait times does not underflow
+ */
+ public void testAwait_NegativeInfinity() throws InterruptedException {
+ final Mutex sync = new Mutex();
+ final ConditionObject c = sync.newCondition();
+ sync.acquire();
+ assertTrue(c.awaitNanos(Long.MIN_VALUE) <= 0);
+ assertFalse(c.await(Long.MIN_VALUE, NANOSECONDS));
+ sync.release();
+ }
+
}