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:
parent
d996c5d95f
commit
5d404c26b1
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -489,69 +489,72 @@ public class Transfers {
|
|||||||
debug = verbose = true;
|
debug = verbose = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceFile = File.createTempFile("xfer.src.", "");
|
File testDir = new File(System.getProperty("test.dir", "."));
|
||||||
|
|
||||||
|
sourceFile = File.createTempFile("xfer.src.", "", testDir);
|
||||||
sourceFile.deleteOnExit();
|
sourceFile.deleteOnExit();
|
||||||
targetFile = File.createTempFile("xfer.tgt.", "");
|
targetFile = File.createTempFile("xfer.tgt.", "", testDir);
|
||||||
targetFile.deleteOnExit();
|
targetFile.deleteOnExit();
|
||||||
|
|
||||||
File fn = File.createTempFile("xfer.fch.", "");
|
File fn = File.createTempFile("xfer.fch.", "", testDir);
|
||||||
fn.deleteOnExit();
|
fn.deleteOnExit();
|
||||||
FileChannel fc = new RandomAccessFile(fn, "rw").getChannel();
|
|
||||||
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
int failures = 0;
|
int failures = 0;
|
||||||
|
|
||||||
for (boolean to = false;; to = true) {
|
try (FileChannel fc = new RandomAccessFile(fn, "rw").getChannel()) {
|
||||||
for (boolean user = false;; user = true) {
|
for (boolean to = false;; to = true) {
|
||||||
if (!verbose)
|
for (boolean user = false;; user = true) {
|
||||||
out.print((to ? "To " : "From ") +
|
if (!verbose)
|
||||||
(user ? "user channel" : "file channel")
|
out.print((to ? "To " : "From ") +
|
||||||
+ ":");
|
(user ? "user channel" : "file channel")
|
||||||
IntGenerator offGen = new IntGenerator(MAX_XFER_SIZE + 2);
|
+ ":");
|
||||||
while (offGen.hasNext()) {
|
IntGenerator offGen = new IntGenerator(MAX_XFER_SIZE + 2);
|
||||||
int off = offGen.next();
|
while (offGen.hasNext()) {
|
||||||
if (!verbose) out.print(" " + off);
|
int off = offGen.next();
|
||||||
IntGenerator lenGen = new IntGenerator(MAX_XFER_SIZE + 2);
|
if (!verbose) out.print(" " + off);
|
||||||
while (lenGen.hasNext()) {
|
IntGenerator lenGen = new IntGenerator(MAX_XFER_SIZE + 2);
|
||||||
int len = lenGen.next();
|
while (lenGen.hasNext()) {
|
||||||
long s = rnd.nextLong();
|
int len = lenGen.next();
|
||||||
String chName = null;
|
long s = rnd.nextLong();
|
||||||
try {
|
String chName = null;
|
||||||
if (to) {
|
try {
|
||||||
Target tgt;
|
if (to) {
|
||||||
if (user)
|
Target tgt;
|
||||||
tgt = new UserTarget(len, s);
|
if (user)
|
||||||
else
|
tgt = new UserTarget(len, s);
|
||||||
tgt = new FileTarget(len, s);
|
else
|
||||||
chName = tgt.name();
|
tgt = new FileTarget(len, s);
|
||||||
testTo(s, fc, off, len, tgt);
|
chName = tgt.name();
|
||||||
|
testTo(s, fc, off, len, tgt);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Source src;
|
||||||
|
if (user)
|
||||||
|
src = new UserSource(len, s);
|
||||||
|
else
|
||||||
|
src = new FileSource(len, s);
|
||||||
|
chName = src.name();
|
||||||
|
testFrom(s, src, fc, off, len);
|
||||||
|
}
|
||||||
|
} catch (Failure x) {
|
||||||
|
out.println();
|
||||||
|
out.println("FAILURE: " + chName
|
||||||
|
+ ", offset " + off
|
||||||
|
+ ", length " + len);
|
||||||
|
x.printStackTrace(out);
|
||||||
|
failures++;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Source src;
|
|
||||||
if (user)
|
|
||||||
src = new UserSource(len, s);
|
|
||||||
else
|
|
||||||
src = new FileSource(len, s);
|
|
||||||
chName = src.name();
|
|
||||||
testFrom(s, src, fc, off, len);
|
|
||||||
}
|
|
||||||
} catch (Failure x) {
|
|
||||||
out.println();
|
|
||||||
out.println("FAILURE: " + chName
|
|
||||||
+ ", offset " + off
|
|
||||||
+ ", length " + len);
|
|
||||||
x.printStackTrace(out);
|
|
||||||
failures++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!verbose)
|
||||||
|
out.println();
|
||||||
|
if (user)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!verbose)
|
if (to)
|
||||||
out.println();
|
|
||||||
if (user)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (to)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceFile.delete();
|
sourceFile.delete();
|
||||||
@ -563,6 +566,6 @@ public class Transfers {
|
|||||||
throw new RuntimeException("Some tests failed");
|
throw new RuntimeException("Some tests failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out.println("Test succeeded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user