提交 998275e6 编写于 作者: K ksrini

8004042: Arrrghs.java test failed on windows with access error.

Reviewed-by: smarks, jjh, ksrini
Contributed-by: david.dehaven@oracle.com
上级 f2c99688
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* 6894719 6968053 7151434 7146424 * 6894719 6968053 7151434 7146424
* @summary Argument parsing validation. * @summary Argument parsing validation.
* @compile -XDignore.symbol.file Arrrghs.java * @compile -XDignore.symbol.file Arrrghs.java
* @run main Arrrghs * @run main/othervm Arrrghs
*/ */
import java.io.BufferedReader; import java.io.BufferedReader;
...@@ -204,8 +204,7 @@ public class Arrrghs extends TestHelper { ...@@ -204,8 +204,7 @@ public class Arrrghs extends TestHelper {
// exiting the process prematurely can terminate the stderr. // exiting the process prematurely can terminate the stderr.
scratchpad.add(javaCmd + " -version " + inArgs); scratchpad.add(javaCmd + " -version " + inArgs);
File batFile = new File("atest.bat"); File batFile = new File("atest.bat");
java.nio.file.Files.deleteIfExists(batFile.toPath()); createAFile(batFile, scratchpad);
createFile(batFile, scratchpad);
TestResult tr = doExec(batFile.getName()); TestResult tr = doExec(batFile.getName());
......
...@@ -358,6 +358,51 @@ public class TestHelper { ...@@ -358,6 +358,51 @@ public class TestHelper {
Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING); Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING);
} }
/**
* Attempt to create a file at the given location. If an IOException
* occurs then back off for a moment and try again. When a number of
* attempts fail, give up and throw an exception.
*/
void createAFile(File aFile, List<String> contents) throws IOException {
IOException cause = null;
for (int attempts = 0; attempts < 10; attempts++) {
try {
Files.write(aFile.getAbsoluteFile().toPath(), contents,
Charset.defaultCharset(), CREATE, TRUNCATE_EXISTING, WRITE);
if (cause != null) {
/*
* report attempts and errors that were encountered
* for diagnostic purposes
*/
System.err.println("Created batch file " +
aFile + " in " + (attempts + 1) +
" attempts");
System.err.println("Errors encountered: " + cause);
cause.printStackTrace();
}
return;
} catch (IOException ioe) {
if (cause != null) {
// chain the exceptions so they all get reported for diagnostics
cause.addSuppressed(ioe);
} else {
cause = ioe;
}
}
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
if (cause != null) {
// cause should alway be non-null here
ie.addSuppressed(cause);
}
throw new RuntimeException("Interrupted while creating batch file", ie);
}
}
throw new RuntimeException("Unable to create batch file", cause);
}
static void createFile(File outFile, List<String> content) throws IOException { static void createFile(File outFile, List<String> content) throws IOException {
Files.write(outFile.getAbsoluteFile().toPath(), content, Files.write(outFile.getAbsoluteFile().toPath(), content,
Charset.defaultCharset(), CREATE_NEW); Charset.defaultCharset(), CREATE_NEW);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册