8181301: Refactor shell test AsynchronousChannelGroup/run_any_task.sh to java
authoramlu
Thu, 01 Jun 2017 11:10:22 +0800
changeset 45296 ae7b350fabcb
parent 45295 c2764290902a
child 45297 df90da0c10aa
8181301: Refactor shell test AsynchronousChannelGroup/run_any_task.sh to java Reviewed-by: alanb
jdk/test/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/Attack.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/PrivilegedThreadFactory.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/SetupJar.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/bootlib/Attack.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/bootlib/PrivilegedThreadFactory.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/run_any_task.sh
--- a/jdk/test/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java	Wed May 31 20:01:33 2017 -0700
+++ b/jdk/test/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java	Thu Jun 01 11:10:22 2017 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,12 +21,21 @@
  * questions.
  */
 
-import java.nio.channels.AsynchronousChannelGroup;
-import java.util.concurrent.*;
+/*
+ * @test
+ * @bug 4607272
+ * @summary tests tasks can be submitted to a channel group's thread pool.
+ * @library /lib/testlibrary bootlib
+ * @build JarUtils PrivilegedThreadFactory Attack
+ * @run driver SetupJar
+ * @run main/othervm -Xbootclasspath/a:privileged.jar AsExecutor
+ */
 
-/**
- * Test that arbitrary tasks can be submitted to a channel group's thread pool.
- */
+import java.nio.channels.AsynchronousChannelGroup;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
 
 public class AsExecutor {
 
--- a/jdk/test/java/nio/channels/AsynchronousChannelGroup/Attack.java	Wed May 31 20:01:33 2017 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.net.*;
-import java.io.IOException;
-import java.util.concurrent.CountDownLatch;
-
-/**
- * A task that attempts to attack the current host.
- */
-
-public class Attack implements Runnable {
-    private final CountDownLatch latch = new CountDownLatch(1);
-    private volatile boolean failedDueToSecurityException;
-
-    public void Attack() {
-        // check class is on boot class path
-        if (Attack.class.getClassLoader() != null)
-            throw new RuntimeException("Attack class not on boot class path");
-    }
-
-    @Override
-    public void run() {
-        try {
-            new Socket("127.0.0.1", 9999).close();
-            throw new RuntimeException("Connected (not expected)");
-        } catch (IOException e) {
-            throw new RuntimeException("IOException (not expected)");
-        } catch (SecurityException e) {
-            failedDueToSecurityException = true;
-        } finally {
-            latch.countDown();
-        }
-    }
-
-    public void waitUntilDone() throws InterruptedException {
-        latch.await();
-    }
-
-    public boolean failedDueToSecurityException() {
-        return failedDueToSecurityException;
-    }
-}
--- a/jdk/test/java/nio/channels/AsynchronousChannelGroup/PrivilegedThreadFactory.java	Wed May 31 20:01:33 2017 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.util.concurrent.ThreadFactory;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * The "privileged" ThreadFactory used by the AsExecutor test.
- */
-
-public class PrivilegedThreadFactory implements ThreadFactory {
-    public void PrivilegedThreadPoolFactory() {
-        // check class is on boot class path
-        if (PrivilegedThreadFactory.class.getClassLoader() != null)
-            throw new RuntimeException("PrivilegedThreadFactory class not on boot class path");
-    }
-
-    @Override
-    public Thread newThread(final Runnable r) {
-        return AccessController.doPrivileged(new PrivilegedAction<Thread>() {
-            @Override
-            public Thread run() {
-                Thread t = new Thread(r);
-                t.setDaemon(true);
-                return t;
-            }
-        });
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/nio/channels/AsynchronousChannelGroup/SetupJar.java	Thu Jun 01 11:10:22 2017 +0800
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class SetupJar {
+
+    public static void main(String args[]) throws Exception {
+        Path classes = Paths.get(System.getProperty("test.classes", ""));
+        JarUtils.createJarFile(Paths.get("privileged.jar"),
+                               classes.resolve("bootlib"));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/nio/channels/AsynchronousChannelGroup/bootlib/Attack.java	Thu Jun 01 11:10:22 2017 +0800
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.IOException;
+import java.net.Socket;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * A task that attempts to attack the current host.
+ */
+
+public class Attack implements Runnable {
+    private final CountDownLatch latch = new CountDownLatch(1);
+    private volatile boolean failedDueToSecurityException;
+
+    public void Attack() {
+        // check class is on boot class path
+        if (Attack.class.getClassLoader() != null)
+            throw new RuntimeException("Attack class not on boot class path");
+    }
+
+    @Override
+    public void run() {
+        try {
+            new Socket("127.0.0.1", 9999).close();
+            throw new RuntimeException("Connected (not expected)");
+        } catch (IOException e) {
+            throw new RuntimeException("IOException (not expected)");
+        } catch (SecurityException e) {
+            failedDueToSecurityException = true;
+        } finally {
+            latch.countDown();
+        }
+    }
+
+    public void waitUntilDone() throws InterruptedException {
+        latch.await();
+    }
+
+    public boolean failedDueToSecurityException() {
+        return failedDueToSecurityException;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/nio/channels/AsynchronousChannelGroup/bootlib/PrivilegedThreadFactory.java	Thu Jun 01 11:10:22 2017 +0800
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.concurrent.ThreadFactory;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * The "privileged" ThreadFactory used by the AsExecutor test.
+ */
+
+public class PrivilegedThreadFactory implements ThreadFactory {
+    public void PrivilegedThreadPoolFactory() {
+        // check class is on boot class path
+        if (PrivilegedThreadFactory.class.getClassLoader() != null)
+            throw new RuntimeException("PrivilegedThreadFactory class not on boot class path");
+    }
+
+    @Override
+    public Thread newThread(final Runnable r) {
+        return AccessController.doPrivileged(new PrivilegedAction<Thread>() {
+            @Override
+            public Thread run() {
+                Thread t = new Thread(r);
+                t.setDaemon(true);
+                return t;
+            }
+        });
+    }
+}
--- a/jdk/test/java/nio/channels/AsynchronousChannelGroup/run_any_task.sh	Wed May 31 20:01:33 2017 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-#
-# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4607272
-# @summary Unit test for AsynchronousChannelGrou#execute
-# @build AsExecutor PrivilegedThreadFactory Attack
-# @run shell run_any_task.sh
-
-# if TESTJAVA isn't set then we assume an interactive run.
-
-if [ -z "$TESTJAVA" ]; then
-    TESTSRC=.
-    TESTCLASSES=.
-    JAVA=java
-    JAR=jar
-else
-    JAVA="${TESTJAVA}/bin/java"
-    JAR="${TESTJAVA}/bin/jar"
-fi
-
-echo "Creating JAR file ..."
-$JAR -cf "${TESTCLASSES}/Privileged.jar" \
-    -C "${TESTCLASSES}" PrivilegedThreadFactory.class \
-    -C "${TESTCLASSES}" PrivilegedThreadFactory\$1.class \
-    -C "${TESTCLASSES}" Attack.class
-
-echo "Running test ..."
-$JAVA ${TESTVMOPTS} \
-      -Xbootclasspath/a:"${TESTCLASSES}/Privileged.jar" \
-      -classpath "${TESTCLASSES}" \
-      AsExecutor