8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
authorweijun
Wed, 10 Aug 2016 11:21:01 +0800
changeset 40252 8f320a3f83b8
parent 40251 481b890e50a3
child 40253 08809866c0bc
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test Reviewed-by: chegar
jdk/test/sun/security/tools/jarsigner/TsacertOptionTest.java
--- a/jdk/test/sun/security/tools/jarsigner/TsacertOptionTest.java	Fri Jul 29 09:58:28 2016 -0700
+++ b/jdk/test/sun/security/tools/jarsigner/TsacertOptionTest.java	Wed Aug 10 11:21:01 2016 +0800
@@ -77,11 +77,6 @@
         Utils.createFiles(FILENAME);
         JarUtils.createJar(UNSIGNED_JARFILE, FILENAME);
 
-        // look for free network port for TSA service
-        int port = jdk.testlibrary.Utils.getFreePort();
-        String host = "127.0.0.1";
-        String tsaUrl = "http://" + host + ":" + port;
-
         // create key pair for jar signing
         ProcessTools.executeCommand(KEYTOOL,
                 "-genkey",
@@ -126,24 +121,30 @@
                 "-keypass", PASSWORD,
                 "-file", "cert").shouldHaveExitValue(0);
 
-        // create key pair for TSA service
-        // SubjectInfoAccess extension contains URL to TSA service
-        ProcessTools.executeCommand(KEYTOOL,
-                "-genkey",
-                "-v",
-                "-alias", TSA_KEY_ALIAS,
-                "-keyalg", KEY_ALG,
-                "-keysize", Integer.toString(KEY_SIZE),
-                "-keystore", KEYSTORE,
-                "-storepass", PASSWORD,
-                "-keypass", PASSWORD,
-                "-dname", "CN=TSA",
-                "-ext", "ExtendedkeyUsage:critical=timeStamping",
-                "-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl,
-                "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
+
+        try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(0,
+                KEYSTORE)) {
+
+            // look for free network port for TSA service
+            int port = tsa.getPort();
+            String host = "127.0.0.1";
+            String tsaUrl = "http://" + host + ":" + port;
 
-        try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(port,
-                KEYSTORE);) {
+            // create key pair for TSA service
+            // SubjectInfoAccess extension contains URL to TSA service
+            ProcessTools.executeCommand(KEYTOOL,
+                    "-genkey",
+                    "-v",
+                    "-alias", TSA_KEY_ALIAS,
+                    "-keyalg", KEY_ALG,
+                    "-keysize", Integer.toString(KEY_SIZE),
+                    "-keystore", KEYSTORE,
+                    "-storepass", PASSWORD,
+                    "-keypass", PASSWORD,
+                    "-dname", "CN=TSA",
+                    "-ext", "ExtendedkeyUsage:critical=timeStamping",
+                    "-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl,
+                    "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
 
             // start TSA
             tsa.start();