8160221: jdk/test/java/nio/channels/FileChannel/Transfers.java leaving files behind

Create temporary files in the test scratch directory instead of in the default temporary file directory.

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2016-07-12 07:58:40 -07:00
parent d996c5d95f
commit 5d404c26b1

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2016, 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
@ -489,18 +489,20 @@ public class Transfers {
debug = verbose = true;
}
sourceFile = File.createTempFile("xfer.src.", "");
File testDir = new File(System.getProperty("test.dir", "."));
sourceFile = File.createTempFile("xfer.src.", "", testDir);
sourceFile.deleteOnExit();
targetFile = File.createTempFile("xfer.tgt.", "");
targetFile = File.createTempFile("xfer.tgt.", "", testDir);
targetFile.deleteOnExit();
File fn = File.createTempFile("xfer.fch.", "");
File fn = File.createTempFile("xfer.fch.", "", testDir);
fn.deleteOnExit();
FileChannel fc = new RandomAccessFile(fn, "rw").getChannel();
Random rnd = new Random();
int failures = 0;
try (FileChannel fc = new RandomAccessFile(fn, "rw").getChannel()) {
for (boolean to = false;; to = true) {
for (boolean user = false;; user = true) {
if (!verbose)
@ -553,6 +555,7 @@ public class Transfers {
if (to)
break;
}
}
sourceFile.delete();
targetFile.delete();
@ -563,6 +566,6 @@ public class Transfers {
throw new RuntimeException("Some tests failed");
}
out.println("Test succeeded.");
}
}