8031113: TEST_BUG: java/nio/channels/AsynchronousChannelGroup/Basic.java fails intermittently
authoralanb
Fri, 03 Jan 2014 15:59:54 +0000
changeset 22099 4ebb34ef007e
parent 22098 e0db672f080e
child 22100 b5238ea86488
8031113: TEST_BUG: java/nio/channels/AsynchronousChannelGroup/Basic.java fails intermittently Reviewed-by: chegar
jdk/test/java/nio/channels/AsynchronousChannelGroup/Basic.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/Restart.java
--- a/jdk/test/java/nio/channels/AsynchronousChannelGroup/Basic.java	Fri Jan 03 15:42:05 2014 +0000
+++ b/jdk/test/java/nio/channels/AsynchronousChannelGroup/Basic.java	Fri Jan 03 15:59:54 2014 +0000
@@ -24,8 +24,6 @@
 /* @test
  * @bug 4607272
  * @summary Unit test for AsynchronousChannelGroup
- * @build Basic
- * @run main/othervm -XX:-UseVMInterruptibleIO Basic
  */
 
 import java.nio.ByteBuffer;
@@ -37,12 +35,9 @@
 
 public class Basic {
     static final Random rand = new Random();
-    static final ThreadFactory threadFactory = new ThreadFactory() {
-        @Override
-        public Thread newThread(final Runnable r) {
-            return new Thread(r);
-        }};
-
+    static final ThreadFactory threadFactory = (Runnable r) -> {
+        return new Thread(r);
+    };
 
     public static void main(String[] args) throws Exception {
         shutdownTests();
@@ -51,6 +46,12 @@
         miscTests();
     }
 
+    static void awaitTermination(AsynchronousChannelGroup group) throws InterruptedException {
+        boolean terminated = group.awaitTermination(20, TimeUnit.SECONDS);
+        if (!terminated)
+            throw new RuntimeException("Group should have terminated");
+    }
+
     static void testShutdownWithNoChannels(ExecutorService pool,
                                            AsynchronousChannelGroup group)
         throws Exception
@@ -59,9 +60,7 @@
         if (!group.isShutdown())
             throw new RuntimeException("Group should be shutdown");
         // group should terminate quickly
-        boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS);
-        if (!terminated)
-            throw new RuntimeException("Group should have terminated");
+        awaitTermination(group);
         if (pool != null && !pool.isTerminated())
             throw new RuntimeException("Executor should have terminated");
     }
@@ -86,9 +85,7 @@
         ch.close();
 
         // group should terminate quickly
-        boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS);
-        if (!terminated)
-            throw new RuntimeException("Group should have terminated");
+        awaitTermination(group);
         if (pool != null && !pool.isTerminated())
             throw new RuntimeException("Executor should have terminated");
     }
@@ -153,9 +150,8 @@
         if (ch.isOpen())
             throw new RuntimeException("Channel should be closed");
 
-        boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS);
-        if (!terminated)
-            throw new RuntimeException("Group should have terminated");
+        awaitTermination(group);
+
         if (pool != null && !pool.isTerminated())
             throw new RuntimeException("Executor should have terminated");
     }
@@ -260,9 +256,7 @@
         // close channel; group should terminate quickly
         ch.close();
         listener.close();
-        terminated = group.awaitTermination(3, TimeUnit.SECONDS);
-        if (!terminated)
-            throw new RuntimeException("Group should have terminated");
+        awaitTermination(group);
     }
 
     static void miscTests() throws Exception {
--- a/jdk/test/java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java	Fri Jan 03 15:42:05 2014 +0000
+++ b/jdk/test/java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java	Fri Jan 03 15:59:54 2014 +0000
@@ -136,7 +136,7 @@
 
         // clean-up
         group.shutdown();
-        boolean terminated = group.awaitTermination(5, TimeUnit.SECONDS);
+        boolean terminated = group.awaitTermination(20, TimeUnit.SECONDS);
         if (!terminated)
             throw new RuntimeException("Group did not terminate");
 
--- a/jdk/test/java/nio/channels/AsynchronousChannelGroup/Restart.java	Fri Jan 03 15:42:05 2014 +0000
+++ b/jdk/test/java/nio/channels/AsynchronousChannelGroup/Restart.java	Fri Jan 03 15:59:54 2014 +0000
@@ -24,8 +24,6 @@
 /* @test
  * @bug 4607272 6842687
  * @summary Unit test for AsynchronousChannelGroup
- * @build Restart
- * @run main/othervm -XX:-UseVMInterruptibleIO Restart
  */
 
 import java.nio.channels.*;