changeset 51951:1239bfca87f8

8207003: Miscellaneous changes imported from jsr166 CVS 2018-09 Reviewed-by: martin, chegar
author dl
date Fri, 28 Sep 2018 08:45:46 -0700
parents a1c24d06e2b5
children e374b0383035
files test/jdk/java/util/Collections/EmptyNavigableSet.java test/jdk/java/util/PriorityQueue/AddNonComparable.java test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java test/jdk/java/util/concurrent/tck/CountedCompleterTest.java test/jdk/java/util/concurrent/tck/DelayQueueTest.java test/jdk/java/util/concurrent/tck/ForkJoinPool8Test.java test/jdk/java/util/concurrent/tck/ForkJoinTask8Test.java test/jdk/java/util/concurrent/tck/ForkJoinTaskTest.java test/jdk/java/util/concurrent/tck/FutureTaskTest.java test/jdk/java/util/concurrent/tck/JSR166TestCase.java test/jdk/java/util/concurrent/tck/RecursiveActionTest.java test/jdk/java/util/concurrent/tck/RecursiveTaskTest.java test/jdk/java/util/concurrent/tck/ReentrantLockTest.java test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java
diffstat 14 files changed, 94 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/util/Collections/EmptyNavigableSet.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/Collections/EmptyNavigableSet.java	Fri Sep 28 08:45:46 2018 -0700
@@ -45,6 +45,7 @@
 import java.util.TreeSet;
 
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
@@ -369,7 +370,7 @@
 
         assertSame(emptyNavigableSetArray, result);
 
-        assertTrue(result[0] == null);
+        assertNull(result[0]);
     }
 
     @DataProvider(name = "NavigableSet<?>", parallel = true)
--- a/test/jdk/java/util/PriorityQueue/AddNonComparable.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/PriorityQueue/AddNonComparable.java	Fri Sep 28 08:45:46 2018 -0700
@@ -42,6 +42,7 @@
 import java.util.function.Supplier;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
 public class AddNonComparable {
@@ -64,7 +65,7 @@
         test(new PriorityQueue<>(), AComparable::new,
              (q, e) -> {
                  assertEquals(q.size(), 1);
-                 assertTrue(e == null);
+                 assertNull(e);
              });
 
         test(new PriorityBlockingQueue<>(), NonComparable::new,
@@ -75,7 +76,7 @@
         test(new PriorityBlockingQueue<>(), AComparable::new,
              (q, e) -> {
                  assertEquals(q.size(), 1);
-                 assertTrue(e == null);
+                 assertNull(e);
              });
     }
 
@@ -98,7 +99,7 @@
         test(new TreeSet<>(), AComparable::new,
              (s, e) -> {
                  assertEquals(s.size(), 1);
-                 assertTrue(e == null);
+                 assertNull(e);
              });
 
         test(new ConcurrentSkipListSet<>(), NonComparable::new,
@@ -109,7 +110,7 @@
         test(new ConcurrentSkipListSet<>(), AComparable::new,
              (s, e) -> {
                  assertEquals(s.size(), 1);
-                 assertTrue(e == null);
+                 assertNull(e);
              });
     }
 
@@ -131,7 +132,7 @@
         test(new TreeMap<>(), AComparable::new,
              (m, e) -> {
                  assertEquals(m.size(), 1);
-                 assertTrue(e == null);
+                 assertNull(e);
              });
 
         test(new ConcurrentSkipListMap<>(), NonComparable::new,
@@ -142,7 +143,7 @@
         test(new ConcurrentSkipListMap<>(), AComparable::new,
              (s, e) -> {
                  assertEquals(s.size(), 1);
-                 assertTrue(e == null);
+                 assertNull(e);
              });
     }
 
--- a/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -1310,7 +1310,7 @@
             try {
                 s.acquireInterruptibly(1);
                 shouldThrow();
-            } catch (InterruptedException expected) {}
+            } catch (InterruptedException success) {}
         };
         for (int i = 0; i < 2; i++) {
             Thread thread = new Thread(failedAcquire);
--- a/test/jdk/java/util/concurrent/tck/CountedCompleterTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/CountedCompleterTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -135,10 +135,14 @@
 
         assertFalse(a.cancel(false));
         assertFalse(a.cancel(true));
+
+        Object v1 = null, v2 = null;
         try {
-            assertNull(a.get());
-            assertNull(a.get(randomTimeout(), randomTimeUnit()));
+            v1 = a.get();
+            v2 = a.get(randomTimeout(), randomTimeUnit());
         } catch (Throwable fail) { threadUnexpectedException(fail); }
+        assertNull(v1);
+        assertNull(v2);
     }
 
     void checkCancelled(CountedCompleter a) {
--- a/test/jdk/java/util/concurrent/tck/DelayQueueTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/DelayQueueTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -96,7 +96,7 @@
         // suppress [overrides] javac warning
         public int hashCode() { return pseudodelay; }
         public long getDelay(TimeUnit ignore) {
-            return Integer.MIN_VALUE + pseudodelay;
+            return (long) Integer.MIN_VALUE + pseudodelay;
         }
         public String toString() {
             return String.valueOf(pseudodelay);
--- a/test/jdk/java/util/concurrent/tck/ForkJoinPool8Test.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ForkJoinPool8Test.java	Fri Sep 28 08:45:46 2018 -0700
@@ -133,10 +133,14 @@
         assertNull(a.join());
         assertFalse(a.cancel(false));
         assertFalse(a.cancel(true));
+
+        Object v1 = null, v2 = null;
         try {
-            assertNull(a.get());
-            assertNull(a.get(randomTimeout(), randomTimeUnit()));
+            v1 = a.get();
+            v2 = a.get(randomTimeout(), randomTimeUnit());
         } catch (Throwable fail) { threadUnexpectedException(fail); }
+        assertNull(v1);
+        assertNull(v2);
     }
 
     void checkCancelled(ForkJoinTask a) {
--- a/test/jdk/java/util/concurrent/tck/ForkJoinTask8Test.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ForkJoinTask8Test.java	Fri Sep 28 08:45:46 2018 -0700
@@ -140,13 +140,13 @@
         checkCompletedNormally(a, null);
     }
 
-    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
+    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expectedValue) {
         assertTrue(a.isDone());
         assertFalse(a.isCancelled());
         assertTrue(a.isCompletedNormally());
         assertFalse(a.isCompletedAbnormally());
         assertNull(a.getException());
-        assertSame(expected, a.getRawResult());
+        assertSame(expectedValue, a.getRawResult());
         if (a instanceof BinaryAsyncAction)
             assertEquals(COMPLETE_STATE,
                          ((BinaryAsyncAction)a).getForkJoinTaskTag());
@@ -154,7 +154,7 @@
         {
             Thread.currentThread().interrupt();
             long startTime = System.nanoTime();
-            assertSame(expected, a.join());
+            assertSame(expectedValue, a.join());
             assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
             Thread.interrupted();
         }
@@ -169,10 +169,14 @@
 
         assertFalse(a.cancel(false));
         assertFalse(a.cancel(true));
+
+        T v1 = null, v2 = null;
         try {
-            assertSame(expected, a.get());
-            assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
+            v1 = a.get();
+            v2 = a.get(randomTimeout(), randomTimeUnit());
         } catch (Throwable fail) { threadUnexpectedException(fail); }
+        assertSame(expectedValue, v1);
+        assertSame(expectedValue, v2);
     }
 
     void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
--- a/test/jdk/java/util/concurrent/tck/ForkJoinTaskTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ForkJoinTaskTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -114,18 +114,18 @@
         checkCompletedNormally(a, null);
     }
 
-    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
+    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expectedValue) {
         assertTrue(a.isDone());
         assertFalse(a.isCancelled());
         assertTrue(a.isCompletedNormally());
         assertFalse(a.isCompletedAbnormally());
         assertNull(a.getException());
-        assertSame(expected, a.getRawResult());
+        assertSame(expectedValue, a.getRawResult());
 
         {
             Thread.currentThread().interrupt();
             long startTime = System.nanoTime();
-            assertSame(expected, a.join());
+            assertSame(expectedValue, a.join());
             assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
             Thread.interrupted();
         }
@@ -140,10 +140,14 @@
 
         assertFalse(a.cancel(false));
         assertFalse(a.cancel(true));
+
+        T v1 = null, v2 = null;
         try {
-            assertSame(expected, a.get());
-            assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
+            v1 = a.get();
+            v2 = a.get(randomTimeout(), randomTimeUnit());
         } catch (Throwable fail) { threadUnexpectedException(fail); }
+        assertSame(expectedValue, v1);
+        assertSame(expectedValue, v2);
     }
 
     void checkCancelled(ForkJoinTask a) {
--- a/test/jdk/java/util/concurrent/tck/FutureTaskTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/FutureTaskTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -87,8 +87,9 @@
             pf.run();
             pf.runAndReset();
             assertEquals(savedRunCount, pf.runCount());
+            Object r2 = null;
             try {
-                assertSame(r, f.get());
+                r2 = f.get();
             } catch (CancellationException t) {
                 assertSame(exInfo, CancellationException.class);
             } catch (ExecutionException t) {
@@ -96,6 +97,8 @@
             } catch (Throwable t) {
                 threadUnexpectedException(t);
             }
+            if (exInfo == null)
+                assertSame(r, r2);
             assertTrue(f.isDone());
         }
     }
@@ -128,14 +131,17 @@
         }
     }
 
-    <T> void checkCompletedNormally(Future<T> f, T expected) {
+    <T> void checkCompletedNormally(Future<T> f, T expectedValue) {
         checkIsDone(f);
         assertFalse(f.isCancelled());
 
+        T v1 = null, v2 = null;
         try {
-            assertSame(expected, f.get());
-            assertSame(expected, f.get(randomTimeout(), randomTimeUnit()));
+            v1 = f.get();
+            v2 = f.get(randomTimeout(), randomTimeUnit());
         } catch (Throwable fail) { threadUnexpectedException(fail); }
+        assertSame(expectedValue, v1);
+        assertSame(expectedValue, v2);
     }
 
     void checkCancelled(Future<?> f) {
@@ -485,7 +491,7 @@
         try {
             task.cancel(true);
             shouldThrow();
-        } catch (SecurityException expected) {}
+        } catch (SecurityException success) {}
 
         // We failed to deliver the interrupt, but the world retains
         // its sanity, as if we had done task.cancel(false)
--- a/test/jdk/java/util/concurrent/tck/JSR166TestCase.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/JSR166TestCase.java	Fri Sep 28 08:45:46 2018 -0700
@@ -1415,9 +1415,11 @@
      */
     <T> void checkTimedGet(Future<T> f, T expectedValue, long timeoutMillis) {
         long startTime = System.nanoTime();
+        T actual = null;
         try {
-            assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS));
+            actual = f.get(timeoutMillis, MILLISECONDS);
         } catch (Throwable fail) { threadUnexpectedException(fail); }
+        assertEquals(expectedValue, actual);
         if (millisElapsedSince(startTime) > timeoutMillis/2)
             throw new AssertionError("timed get did not return promptly");
     }
@@ -1596,13 +1598,15 @@
     }
 
     public void await(CountDownLatch latch, long timeoutMillis) {
+        boolean timedOut = false;
         try {
-            if (!latch.await(timeoutMillis, MILLISECONDS))
-                fail("timed out waiting for CountDownLatch for "
-                     + (timeoutMillis/1000) + " sec");
+            timedOut = !latch.await(timeoutMillis, MILLISECONDS);
         } catch (Throwable fail) {
             threadUnexpectedException(fail);
         }
+        if (timedOut)
+            fail("timed out waiting for CountDownLatch for "
+                 + (timeoutMillis/1000) + " sec");
     }
 
     public void await(CountDownLatch latch) {
@@ -1610,13 +1614,15 @@
     }
 
     public void await(Semaphore semaphore) {
+        boolean timedOut = false;
         try {
-            if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS))
-                fail("timed out waiting for Semaphore for "
-                     + (LONG_DELAY_MS/1000) + " sec");
+            timedOut = !semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS);
         } catch (Throwable fail) {
             threadUnexpectedException(fail);
         }
+        if (timedOut)
+            fail("timed out waiting for Semaphore for "
+                 + (LONG_DELAY_MS/1000) + " sec");
     }
 
     public void await(CyclicBarrier barrier) {
@@ -1802,17 +1808,17 @@
 
     @SuppressWarnings("unchecked")
     <T> T serialClone(T o) {
+        T clone = null;
         try {
             ObjectInputStream ois = new ObjectInputStream
                 (new ByteArrayInputStream(serialBytes(o)));
-            T clone = (T) ois.readObject();
-            if (o == clone) assertImmutable(o);
-            assertSame(o.getClass(), clone.getClass());
-            return clone;
+            clone = (T) ois.readObject();
         } catch (Throwable fail) {
             threadUnexpectedException(fail);
-            return null;
         }
+        if (o == clone) assertImmutable(o);
+        else assertSame(o.getClass(), clone.getClass());
+        return clone;
     }
 
     /**
@@ -1831,7 +1837,7 @@
             (new ByteArrayInputStream(bos.toByteArray()));
         T clone = (T) ois.readObject();
         if (o == clone) assertImmutable(o);
-        assertSame(o.getClass(), clone.getClass());
+        else assertSame(o.getClass(), clone.getClass());
         return clone;
     }
 
--- a/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -123,10 +123,14 @@
         assertNull(a.join());
         assertFalse(a.cancel(false));
         assertFalse(a.cancel(true));
+
+        Object v1 = null, v2 = null;
         try {
-            assertNull(a.get());
-            assertNull(a.get(randomTimeout(), randomTimeUnit()));
+            v1 = a.get();
+            v2 = a.get(randomTimeout(), randomTimeUnit());
         } catch (Throwable fail) { threadUnexpectedException(fail); }
+        assertNull(v1);
+        assertNull(v2);
     }
 
     void checkCancelled(RecursiveAction a) {
--- a/test/jdk/java/util/concurrent/tck/RecursiveTaskTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/RecursiveTaskTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -109,29 +109,33 @@
         } catch (Throwable fail) { threadUnexpectedException(fail); }
     }
 
-    <T> void checkCompletedNormally(RecursiveTask<T> a, T expected) {
+    <T> void checkCompletedNormally(RecursiveTask<T> a, T expectedValue) {
         assertTrue(a.isDone());
         assertFalse(a.isCancelled());
         assertTrue(a.isCompletedNormally());
         assertFalse(a.isCompletedAbnormally());
         assertNull(a.getException());
-        assertSame(expected, a.getRawResult());
-        assertSame(expected, a.join());
+        assertSame(expectedValue, a.getRawResult());
+        assertSame(expectedValue, a.join());
         assertFalse(a.cancel(false));
         assertFalse(a.cancel(true));
+
+        T v1 = null, v2 = null;
         try {
-            assertSame(expected, a.get());
-            assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
+            v1 = a.get();
+            v2 = a.get(randomTimeout(), randomTimeUnit());
         } catch (Throwable fail) { threadUnexpectedException(fail); }
+        assertSame(expectedValue, v1);
+        assertSame(expectedValue, v2);
     }
 
     /**
      * Waits for the task to complete, and checks that when it does,
      * it will have an Integer result equals to the given int.
      */
-    void checkCompletesNormally(RecursiveTask<Integer> a, int expected) {
+    void checkCompletesNormally(RecursiveTask<Integer> a, int expectedValue) {
         Integer r = a.join();
-        assertEquals(expected, (int) r);
+        assertEquals(expectedValue, (int) r);
         checkCompletedNormally(a, r);
     }
 
@@ -139,9 +143,9 @@
      * Like checkCompletesNormally, but verifies that the task has
      * already completed.
      */
-    void checkCompletedNormally(RecursiveTask<Integer> a, int expected) {
+    void checkCompletedNormally(RecursiveTask<Integer> a, int expectedValue) {
         Integer r = a.getRawResult();
-        assertEquals(expected, (int) r);
+        assertEquals(expectedValue, (int) r);
         checkCompletedNormally(a, r);
     }
 
--- a/test/jdk/java/util/concurrent/tck/ReentrantLockTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ReentrantLockTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -1187,7 +1187,7 @@
                     await(cond, awaitMethod);
                     throw new AssertionError("should throw");
                 }
-                catch (IllegalMonitorStateException expected) {}
+                catch (IllegalMonitorStateException success) {}
                 catch (Throwable fail) { threadUnexpectedException(fail); }}};
         Thread rogueThread = new Thread(rogue, "rogue");
         threads.add(rogueThread);
--- a/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java	Fri Sep 28 08:45:46 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java	Fri Sep 28 08:45:46 2018 -0700
@@ -1029,7 +1029,9 @@
             public void onComplete() {}
         }
         pub.subscribe(new Sub());
-        CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE));
+        checkTimedGet(
+            CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE)),
+            null);
         await(finished);
     }
 }