8027881: test/java/net/URLPermission/nstest/LookupTest.java failing intermittently, output insufficient
authormichaelm
Thu, 07 Nov 2013 10:22:11 +0000
changeset 21621 3101c2e7e705
parent 21620 5f7f2b541560
child 21622 643cd3c6f72d
8027881: test/java/net/URLPermission/nstest/LookupTest.java failing intermittently, output insufficient Reviewed-by: chegar
jdk/test/java/net/URLPermission/URLPermissionTest.java
jdk/test/java/net/URLPermission/nstest/LookupTest.java
jdk/test/java/net/URLPermission/nstest/lookup.sh
jdk/test/java/net/URLPermission/nstest/policy
--- a/jdk/test/java/net/URLPermission/URLPermissionTest.java	Thu Nov 07 08:23:00 2013 +0000
+++ b/jdk/test/java/net/URLPermission/URLPermissionTest.java	Thu Nov 07 10:22:11 2013 +0000
@@ -26,7 +26,7 @@
 
 /**
  * @test
- * @bug 8010464 8027570
+ * @bug 8010464 8027570 8027687
  */
 
 public class URLPermissionTest {
--- a/jdk/test/java/net/URLPermission/nstest/LookupTest.java	Thu Nov 07 08:23:00 2013 +0000
+++ b/jdk/test/java/net/URLPermission/nstest/LookupTest.java	Thu Nov 07 10:22:11 2013 +0000
@@ -21,12 +21,6 @@
  * questions.
  */
 
-/* @test
- * @compile -XDignore.symbol.file=true SimpleNameService.java
- *                                     SimpleNameServiceDescriptor.java
- * @run main/othervm/timeout=200 -Dsun.net.spi.nameservice.provider.1=simple,sun LookupTest
- */
-
 /**
  * This is a simple smoke test of the HttpURLPermission mechanism, which
  * checks for either IOException (due to unknown host) or SecurityException
@@ -35,6 +29,7 @@
 
 import java.net.*;
 import java.io.*;
+import jdk.testlibrary.Utils;
 
 public class LookupTest {
 
@@ -48,12 +43,12 @@
             InputStream is = urlc.getInputStream();
         } catch (SecurityException e) {
             if (!throwsSecException) {
-                throw new RuntimeException ("(1) was not expecting " + e);
+                throw new RuntimeException ("(1) was not expecting ", e);
             }
             return;
         } catch (IOException ioe) {
             if (!throwsIOException) {
-                throw new RuntimeException ("(2) was not expecting " + ioe);
+                throw new RuntimeException ("(2) was not expecting ", ioe);
             }
             return;
         }
@@ -64,31 +59,41 @@
         }
     }
 
-    public static void main(String args[]) throws Exception {
-        SimpleNameService.put("allowedAndFound.com", "127.0.0.1");
-        SimpleNameService.put("notAllowedButFound.com", "99.99.99.99");
-        // name "notAllowedAndNotFound.com" is not in map
-        // name "allowedButNotfound.com" is not in map
-        startServer();
-
-        String policyFileName = "file://" + System.getProperty("test.src", ".") + "/policy";
-        System.err.println ("policy = " + policyFileName);
+    static int port;
+    static ServerSocket serverSocket;
 
-        System.setProperty("java.security.policy", policyFileName);
-
-        System.setSecurityManager(new SecurityManager());
-
-        test("http://allowedAndFound.com:50100/foo", false, false);
+    public static void main(String args[]) throws Exception {
+        String cmd = args[0];
+        if (cmd.equals("-getport")) {
+            port = Utils.getFreePort();
+            System.out.println(port);
+        } else if (cmd.equals("-runtest")) {
+            port = Integer.parseInt(args[1]);
+            SimpleNameService.put("allowedAndFound.com", "127.0.0.1");
+            SimpleNameService.put("notAllowedButFound.com", "99.99.99.99");
+            // name "notAllowedAndNotFound.com" is not in map
+            // name "allowedButNotfound.com" is not in map
+            try {
+                startServer();
 
-        test("http://notAllowedButFound.com:50100/foo", true, false);
+                System.setSecurityManager(new SecurityManager());
+
+                test("http://allowedAndFound.com:" + port + "/foo", false, false);
+
+                test("http://notAllowedButFound.com:" + port + "/foo", true, false);
+
+                test("http://allowedButNotfound.com:" + port + "/foo", false, true);
 
-        test("http://allowedButNotfound.com:50100/foo", false, true);
-
-        test("http://notAllowedAndNotFound.com:50100/foo", true, false);
+                test("http://notAllowedAndNotFound.com:" + port + "/foo", true, false);
+            } finally {
+                serverSocket.close();
+            }
+        } else {
+            throw new RuntimeException("Bad invocation: " + cmd);
+        }
     }
 
     static Thread server;
-    static ServerSocket serverSocket;
 
     static class Server extends Thread {
         public void run() {
@@ -112,11 +117,11 @@
 
     static void startServer() {
         try {
-            serverSocket = new ServerSocket(50100);
+            serverSocket = new ServerSocket(port);
             server = new Server();
             server.start();
         } catch (Exception e) {
-            throw new RuntimeException ("Test failed to initialize");
+            throw new RuntimeException ("Test failed to initialize", e);
         }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/net/URLPermission/nstest/lookup.sh	Thu Nov 07 10:22:11 2013 +0000
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2013, 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
+# @library /lib/testlibrary
+# @compile -XDignore.symbol.file=true SimpleNameService.java
+#            LookupTest.java SimpleNameServiceDescriptor.java
+# @run shell/timeout=50 lookup.sh
+#
+DIR=`pwd`
+
+port=`${TESTJAVA}/bin/java -cp ${TESTCLASSES} LookupTest -getport`
+
+cat << POLICY > policy
+grant {
+    permission java.net.URLPermission "http://allowedAndFound.com:${port}/-", "*:*";
+    permission java.net.URLPermission "http://allowedButNotfound.com:${port}/-", "*:*";
+    permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
+    permission java.util.PropertyPermission "java.io.tmpdir", "read";
+
+    // needed for HttpServer
+    permission "java.net.SocketPermission" "localhost:1024-", "resolve,accept";
+};
+POLICY
+
+${TESTJAVA}/bin/java -Djava.security.policy=file://${DIR}/policy -Dsun.net.spi.nameservice.provider.1=simple,sun -cp ${TESTCLASSES}:${TESTSRC} LookupTest -runtest $port
--- a/jdk/test/java/net/URLPermission/nstest/policy	Thu Nov 07 08:23:00 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-//
-// Copyright (c) 2013, 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.
-//
-
-grant {
-    permission java.net.URLPermission "http://allowedAndFound.com:50100/-", "*:*";
-    permission java.net.URLPermission "http://allowedButNotfound.com:50100/-", "*:*";
-
-    // needed for HttpServer
-    permission "java.net.SocketPermission" "localhost:1024-", "resolve,accept";
-};
-
-// Normal permissions that aren't granted when run under jtreg
-
-grant codeBase "file:${{java.ext.dirs}}/*" {
-        permission java.security.AllPermission;
-};
-
-grant codeBase "file:${{java.home}}/jre/lib/rt.jar" {
-        permission java.security.AllPermission;
-};
-