changeset 48713:efdb1f63c30d

8186009: tools launcher test AddExportsAndOpensInManifest.java fails intermittently: AccessDeniedException Summary: unique jar file names for every test case Reviewed-by: alanb
author anazarov
date Fri, 26 Jan 2018 12:16:08 -0800
parents e2a7856edfba
children f8188cc0d01d
files test/jdk/tools/launcher/modules/addexports/manifest/AddExportsAndOpensInManifest.java
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/tools/launcher/modules/addexports/manifest/AddExportsAndOpensInManifest.java	Fri Jan 26 14:15:09 2018 +0000
+++ b/test/jdk/tools/launcher/modules/addexports/manifest/AddExportsAndOpensInManifest.java	Fri Jan 26 12:16:08 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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
@@ -32,6 +32,7 @@
  *          manifest of a main application JAR
  */
 
+import java.lang.reflect.Method;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -41,6 +42,7 @@
 import jdk.testlibrary.OutputAnalyzer;
 import jdk.testlibrary.ProcessTools;
 
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import static org.testng.Assert.*;
 
@@ -48,6 +50,15 @@
 @Test
 public class AddExportsAndOpensInManifest {
 
+    private String testName;
+    private int testCaseNum;
+
+    @BeforeMethod
+    public void getTestName(Method m){
+        testName = m.getName();
+        testCaseNum = 0;
+    }
+
     /**
      * Package Test1 and Test2 into a JAR file with the given attributes
      * in the JAR manifest, then execute the JAR file with `java -jar`.
@@ -67,7 +78,7 @@
         }
 
         // create the JAR file with Test1 and Test2
-        Path jarfile = Paths.get("test.jar");
+        Path jarfile = Paths.get(String.format("%s-%s.jar", testName, ++testCaseNum));
         Files.deleteIfExists(jarfile);
 
         Path classes = Paths.get(System.getProperty("test.classes", ""));
@@ -172,5 +183,4 @@
         attrs = "Main-Class=Test1,Add-Opens=java.base/jdk.internal.DoesNotExit";
         runExpectingFail(attrs, "IllegalAccessError");
     }
-
 }