8144806: sun/security/tools/keytool/standard.sh fails intermittently at deleting x.jks
authorvtewari
Wed, 25 Apr 2018 12:29:48 +0530
changeset 49882 a02abc7e5536
parent 49881 29419b836244
child 49883 d7fe9d3e7bf3
8144806: sun/security/tools/keytool/standard.sh fails intermittently at deleting x.jks Reviewed-by: weijun Contributed-by: bhanu.prakash.gopularam@oracle.com
test/jdk/sun/security/tools/keytool/KeyToolTest.java
test/jdk/sun/security/tools/keytool/autotest.sh
test/jdk/sun/security/tools/keytool/standard.sh
--- a/test/jdk/sun/security/tools/keytool/KeyToolTest.java	Tue Apr 24 21:40:10 2018 -0700
+++ b/test/jdk/sun/security/tools/keytool/KeyToolTest.java	Wed Apr 25 12:29:48 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, 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
@@ -65,6 +65,7 @@
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.security.cert.X509Certificate;
+import jdk.test.lib.util.FileUtils;
 import sun.security.util.ObjectIdentifier;
 
 public class KeyToolTest {
@@ -118,9 +119,10 @@
         if (debug) {
             System.err.println("Removing " + filename);
         }
-        new File(filename).delete();
-        if (new File(filename).exists()) {
-            throw new RuntimeException("Error deleting " + filename);
+        try{
+            FileUtils.deleteFileIfExistsWithRetry(Paths.get(filename));
+        }catch(IOException e) {
+            throw new RuntimeException("Error deleting " + filename, e);
         }
     }
 
--- a/test/jdk/sun/security/tools/keytool/autotest.sh	Tue Apr 24 21:40:10 2018 -0700
+++ b/test/jdk/sun/security/tools/keytool/autotest.sh	Wed Apr 25 12:29:48 2018 +0530
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2006, 2018, 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
@@ -24,7 +24,9 @@
 # @test
 # @summary (almost) all keytool behaviors
 # @author Weijun Wang
-#
+# @library /test/lib
+# @build jdk.test.lib.util.FileUtils
+# @run shell/timeout=600 autotest.sh
 # This test is only executed on several platforms
 #
 # set a few environment variables so that the shell-script can run stand-alone
@@ -92,6 +94,14 @@
     exit 0;
     ;;
 esac
+case "$OS" in
+  Windows_* | CYGWIN* )
+    PS=";"
+    ;;
+  * )
+    PS=":"
+    ;;
+esac
 
 if [ "$LIBNAME" = "" ]; then
   echo "Cannot find libsoftokn3.so"
@@ -103,8 +113,7 @@
 EXTRAOPTS="--add-exports java.base/sun.security.tools.keytool=ALL-UNNAMED \
  --add-exports java.base/sun.security.util=ALL-UNNAMED \
  --add-exports java.base/sun.security.x509=ALL-UNNAMED"
-
-${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ${EXTRAOPTS} -d . -XDignore.symbol.file \
+${COMPILEJAVA}${FS}bin${FS}javac -classpath ${TESTCLASSPATH} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ${EXTRAOPTS} -d . -XDignore.symbol.file \
         ${TESTSRC}${FS}KeyToolTest.java || exit 10
 
 NSS=${TESTSRC}${FS}..${FS}..${FS}pkcs11${FS}nss
@@ -116,8 +125,7 @@
 
 chmod u+w key3.db
 chmod u+w cert8.db
-
-echo | ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${EXTRAOPTS} -Dnss \
+echo | ${TESTJAVA}${FS}bin${FS}java -classpath .${PS}${TESTCLASSPATH} ${TESTVMOPTS} ${EXTRAOPTS} -Dnss \
    -Dnss.lib=${LIBNAME} \
    KeyToolTest
 status=$?
--- a/test/jdk/sun/security/tools/keytool/standard.sh	Tue Apr 24 21:40:10 2018 -0700
+++ b/test/jdk/sun/security/tools/keytool/standard.sh	Wed Apr 25 12:29:48 2018 +0530
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2018, 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
@@ -24,6 +24,8 @@
 # @test
 # @summary (almost) all keytool behaviors
 # @author Weijun Wang
+# @library /test/lib
+# @build jdk.test.lib.util.FileUtils
 # @run shell/timeout=600 standard.sh
 # @key intermittent
 
@@ -57,14 +59,22 @@
     exit 1;
     ;;
 esac
+case "$OS" in
+  Windows_* | CYGWIN* )
+    PS=";"
+    ;;
+  * )
+    PS=":"
+    ;;
+esac
 
 EXTRAOPTS="--add-exports java.base/sun.security.tools.keytool=ALL-UNNAMED \
  --add-exports java.base/sun.security.util=ALL-UNNAMED \
  --add-exports java.base/sun.security.x509=ALL-UNNAMED"
 
-${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ${EXTRAOPTS} -d . -XDignore.symbol.file ${TESTSRC}${FS}KeyToolTest.java || exit 10
+${COMPILEJAVA}${FS}bin${FS}javac -classpath ${TESTCLASSPATH} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ${EXTRAOPTS} -d . -XDignore.symbol.file ${TESTSRC}${FS}KeyToolTest.java || exit 10
 
-echo | ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${EXTRAOPTS} -Dfile KeyToolTest
+echo | ${TESTJAVA}${FS}bin${FS}java -classpath .${PS}${TESTCLASSPATH} ${TESTVMOPTS} ${EXTRAOPTS} -Dfile KeyToolTest
 status=$?
 
 exit $status