Skip to content

Commit

Permalink
8294519: (fs) java/nio/file/Files/CopyProcFile.java fails intermitten…
Browse files Browse the repository at this point in the history
…ly due to unstable /proc/cpuinfo output

Reviewed-by: alanb, shade, lancea
  • Loading branch information
Brian Burkhalter committed Sep 29, 2022
1 parent 88062ee commit a07975b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 0 additions & 2 deletions test/jdk/ProblemList.txt
Expand Up @@ -561,8 +561,6 @@ java/nio/channels/AsynchronousSocketChannel/StressLoopback.java 8211851 aix-ppc6

java/nio/channels/DatagramChannel/ManySourcesAndTargets.java 8264385 macosx-aarch64

java/nio/file/Files/CopyProcFile.java 8294519 linux-all

############################################################################

# jdk_rmi
Expand Down
22 changes: 12 additions & 10 deletions test/jdk/java/nio/file/Files/CopyProcFile.java
Expand Up @@ -49,7 +49,7 @@
* @run testng/othervm CopyProcFile
*/
public class CopyProcFile {
static final String SOURCE = "/proc/cpuinfo";
static final String SOURCE = "/proc/version";
static final String BUFFERED_COPY = "bufferedCopy";
static final String TARGET = "target";

Expand All @@ -58,7 +58,7 @@ public class CopyProcFile {
static long theSize;

// copy src to dst via Java buffers
static long bufferedCopy(String src, String dst) {
static long bufferedCopy(String src, String dst) throws IOException {
try (InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst)) {
byte[] b = new byte[BUF_SIZE];
Expand All @@ -69,8 +69,6 @@ static long bufferedCopy(String src, String dst) {
total += n;
}
return total;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

Expand Down Expand Up @@ -115,17 +113,19 @@ static long transferFrom(String src, String dst) {
}

@BeforeTest(alwaysRun=true)
public void createBufferedCopy() {
public void createBufferedCopy() throws IOException {
System.out.printf("Using source file \"%s\"%n", SOURCE);
try {
theSize = bufferedCopy(SOURCE, BUFFERED_COPY);
System.out.printf("Copied %d bytes from %s%n", theSize, SOURCE);
if (Files.mismatch(Path.of(BUFFERED_COPY), Path.of(SOURCE)) != -1)
throw new RuntimeException("Copy does not match source");
} catch (Exception e) {
} catch (IOException e) {
try {
Files.delete(Path.of(BUFFERED_COPY));
} catch (IOException ignore) {}
throw e;
}
if (Files.mismatch(Path.of(BUFFERED_COPY), Path.of(SOURCE)) != -1) {
throw new RuntimeException("Copy does not match source");
}
}

Expand Down Expand Up @@ -162,13 +162,15 @@ static Object[][] functions() throws IOException {
public static void testCopyAndTransfer(FHolder f) throws IOException {
try {
long size = f.apply(SOURCE, TARGET);
if (size != theSize)
if (size != theSize) {
throw new RuntimeException("Size: expected " + theSize +
"; actual: " + size);
}
long mismatch = Files.mismatch(Path.of(BUFFERED_COPY),
Path.of(TARGET));
if (mismatch != -1)
if (mismatch != -1) {
throw new RuntimeException("Target does not match copy");
}
} finally {
try {
Files.delete(Path.of(TARGET));
Expand Down

1 comment on commit a07975b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.