8181393: Refactor shell test Selector/lots_of_updates.sh and SocketChannel/Open.sh to java
authoramlu
Mon, 05 Jun 2017 14:07:07 +0800
changeset 45387 179605f4d367
parent 45386 eda2fa9ba27e
child 45388 6406324c5b40
8181393: Refactor shell test Selector/lots_of_updates.sh and SocketChannel/Open.sh to java Reviewed-by: psandoz
jdk/test/java/nio/channels/Selector/LotsOfUpdates.java
jdk/test/java/nio/channels/Selector/LotsOfUpdatesTest.java
jdk/test/java/nio/channels/Selector/lots_of_updates.sh
jdk/test/java/nio/channels/SocketChannel/Open.java
jdk/test/java/nio/channels/SocketChannel/Open.sh
jdk/test/java/nio/channels/SocketChannel/OpenSocketChannelTest.java
--- a/jdk/test/java/nio/channels/Selector/LotsOfUpdates.java	Sun Jun 04 18:42:42 2017 -0700
+++ b/jdk/test/java/nio/channels/Selector/LotsOfUpdates.java	Mon Jun 05 14:07:07 2017 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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,8 +21,10 @@
  * questions.
  */
 
-import java.nio.channels.*;
 import java.io.IOException;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
 
 public class LotsOfUpdates {
     public static void main(String[] args) throws IOException {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/nio/channels/Selector/LotsOfUpdatesTest.java	Mon Jun 05 14:07:07 2017 +0800
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 6824477
+ * @summary Selector.select can fail with IOException "Invalid argument" on
+ *     Solaris if maximum number of file descriptors is less than 10000
+ * @requires (os.family != "windows")
+ * @library /test/lib
+ * @build LotsOfUpdates
+ * @run main LotsOfUpdatesTest
+ */
+
+import jdk.test.lib.process.ProcessTools;
+
+public class LotsOfUpdatesTest {
+
+    //hard limit needs to be less than 10000 for this bug
+    private static final String ULIMIT_SET_CMD = "ulimit -n 2048";
+
+    private static final String JAVA_CMD = ProcessTools.getCommandLine(
+            ProcessTools.createJavaProcessBuilder(LotsOfUpdates.class.getName()));
+
+    public static void main(String[] args) throws Throwable {
+        ProcessTools.executeCommand("sh", "-c", ULIMIT_SET_CMD + " && " + JAVA_CMD)
+                    .shouldHaveExitValue(0);
+    }
+}
--- a/jdk/test/java/nio/channels/Selector/lots_of_updates.sh	Sun Jun 04 18:42:42 2017 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-#
-# Copyright (c) 2009, 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 6824477
-# @summary Selector.select can fail with IOException "Invalid argument" on
-#     Solaris if maximum number of file descriptors is less than 10000
-# @build LotsOfUpdates
-# @run shell lots_of_updates.sh
-
-OS=`uname -s`
-case "$OS" in
-    Windows_* | CYGWIN* )
-        echo "ulimit not on Windows"
-        exit 0
-        ;;
-    * )
-        CLASSPATH=${TESTCLASSES}:${TESTSRC}
-        ;;
-esac
-export CLASSPATH
-
-# hard limit needs to be less than 10000 for this bug
-NOFILES=`ulimit -n -H`
-if [ "$NOFILES" = "unlimited" ] || [ $NOFILES -ge 10000 ]; then
-    ulimit -n 2048
-fi
-
-${TESTJAVA}/bin/java ${TESTVMOPTS} LotsOfUpdates
--- a/jdk/test/java/nio/channels/SocketChannel/Open.java	Sun Jun 04 18:42:42 2017 -0700
+++ b/jdk/test/java/nio/channels/SocketChannel/Open.java	Mon Jun 05 14:07:07 2017 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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,16 +21,11 @@
  * questions.
  */
 
-/* @test
- * @bug 4614065
- * @summary Test SocketChannel gc after running out of fds
- * @build Open
- * @run shell Open.sh
- */
-
-import java.net.*;
-import java.nio.*;
-import java.nio.channels.*;
+import java.net.SocketException;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.Pipe;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
 import java.nio.channels.spi.SelectorProvider;
 
 public class Open {
--- a/jdk/test/java/nio/channels/SocketChannel/Open.sh	Sun Jun 04 18:42:42 2017 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-#! /bin/sh
-
-#
-# Copyright (c) 2002, 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.
-#
-
-#
-
-    OS=`uname -s`
-    case "$OS" in
-        SunOS )
-            ulimit -n 100
-            $TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES Open ;;
-        * )
-            echo "unrecognized system: $OS" ;;
-    esac
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/nio/channels/SocketChannel/OpenSocketChannelTest.java	Mon Jun 05 14:07:07 2017 +0800
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 4614065
+ * @summary Test SocketChannel gc after running out of fds
+ * @requires (os.family == "solaris")
+ * @library /test/lib
+ * @build Open
+ * @run main OpenSocketChannelTest
+ */
+
+import jdk.test.lib.process.ProcessTools;
+
+public class OpenSocketChannelTest {
+
+    //hard limit needs to be small for this bug
+    private static final String ULIMIT_SET_CMD = "ulimit -n 100";
+
+    private static final String JAVA_CMD = ProcessTools.getCommandLine(
+            ProcessTools.createJavaProcessBuilder(Open.class.getName()));
+
+    public static void main(String[] args) throws Throwable {
+        ProcessTools.executeCommand("sh", "-c", ULIMIT_SET_CMD + " && " + JAVA_CMD)
+                    .shouldHaveExitValue(0);
+    }
+}