changeset 13813:75b933981e86

8150416: Miscellaneous changes imported from jsr166 CVS 2016-03 Reviewed-by: martin, psandoz
author dl
date Thu, 03 Mar 2016 10:46:22 -0800
parents a54ed9514075
children a603b1f1d9a1
files test/java/util/concurrent/tck/Collection8Test.java test/java/util/concurrent/tck/ThreadTest.java
diffstat 2 files changed, 23 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/util/concurrent/tck/Collection8Test.java	Thu Mar 03 10:43:07 2016 -0800
+++ b/test/java/util/concurrent/tck/Collection8Test.java	Thu Mar 03 10:46:22 2016 -0800
@@ -37,6 +37,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
@@ -98,26 +99,29 @@
     public void testForEachConcurrentStressTest() throws Throwable {
         if (!impl.isConcurrent()) return;
         final Collection c = impl.emptyCollection();
-        final long testDurationMillis = SHORT_DELAY_MS;
+        final long testDurationMillis = timeoutMillis();
         final AtomicBoolean done = new AtomicBoolean(false);
         final Object elt = impl.makeElement(1);
-        ExecutorService pool = Executors.newCachedThreadPool();
-        Runnable checkElt = () -> {
-            while (!done.get())
-                c.stream().forEach((x) -> { assertSame(x, elt); }); };
-        Runnable addRemove = () -> {
-            while (!done.get()) {
-                assertTrue(c.add(elt));
-                assertTrue(c.remove(elt));
-            }};
-        Future<?> f1 = pool.submit(checkElt);
-        Future<?> f2 = pool.submit(addRemove);
-        Thread.sleep(testDurationMillis);
-        done.set(true);
-        pool.shutdown();
-        assertTrue(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
-        assertNull(f1.get(LONG_DELAY_MS, MILLISECONDS));
-        assertNull(f2.get(LONG_DELAY_MS, MILLISECONDS));
+        final Future<?> f1, f2;
+        final ExecutorService pool = Executors.newCachedThreadPool();
+        try (PoolCleaner cleaner = cleaner(pool, done)) {
+            final CountDownLatch threadsStarted = new CountDownLatch(2);
+            Runnable checkElt = () -> {
+                threadsStarted.countDown();
+                while (!done.get())
+                    c.stream().forEach((x) -> { assertSame(x, elt); }); };
+            Runnable addRemove = () -> {
+                threadsStarted.countDown();
+                while (!done.get()) {
+                    assertTrue(c.add(elt));
+                    assertTrue(c.remove(elt));
+                }};
+            f1 = pool.submit(checkElt);
+            f2 = pool.submit(addRemove);
+            Thread.sleep(testDurationMillis);
+        }
+        assertNull(f1.get(0L, MILLISECONDS));
+        assertNull(f2.get(0L, MILLISECONDS));
     }
 
     // public void testCollection8DebugFail() { fail(); }
--- a/test/java/util/concurrent/tck/ThreadTest.java	Thu Mar 03 10:43:07 2016 -0800
+++ b/test/java/util/concurrent/tck/ThreadTest.java	Thu Mar 03 10:46:22 2016 -0800
@@ -77,7 +77,7 @@
      */
     public void testGetAndSetDefaultUncaughtExceptionHandler() {
         assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
-        // failure due to securityException is OK.
+        // failure due to SecurityException is OK.
         // Would be nice to explicitly test both ways, but cannot yet.
         Thread.UncaughtExceptionHandler defaultHandler
             = Thread.getDefaultUncaughtExceptionHandler();