提交 0e018af9 编写于 作者: A alanb

6993267: TEST_BUG: java/nio/file/Path/InterruptCopy.java fails intermittently (win)

Reviewed-by: forax
上级 b806e118
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/* @test /* @test
* @bug 4313887 * @bug 4313887 6993267
* @summary Unit test for Sun-specific ExtendedCopyOption.INTERRUPTIBLE option * @summary Unit test for Sun-specific ExtendedCopyOption.INTERRUPTIBLE option
* @library .. * @library ..
* @run main/othervm -XX:-UseVMInterruptibleIO InterruptCopy * @run main/othervm -XX:-UseVMInterruptibleIO InterruptCopy
...@@ -36,8 +36,9 @@ import com.sun.nio.file.ExtendedCopyOption; ...@@ -36,8 +36,9 @@ import com.sun.nio.file.ExtendedCopyOption;
public class InterruptCopy { public class InterruptCopy {
private static final long FILE_SIZE_TO_COPY = 512 * 1024 * 1024; private static final long FILE_SIZE_TO_COPY = 512L * 1024L * 1024L;
private static final int DELAY_IN_MS = 500; private static final int DELAY_IN_MS = 500;
private static final int DURATION_MAX_IN_MS = 5000;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Path dir = TestUtil.createTemporaryDirectory(); Path dir = TestUtil.createTemporaryDirectory();
...@@ -81,20 +82,27 @@ public class InterruptCopy { ...@@ -81,20 +82,27 @@ public class InterruptCopy {
try { try {
// copy source to target in main thread, interrupting it after a delay // copy source to target in main thread, interrupting it after a delay
final Thread me = Thread.currentThread(); final Thread me = Thread.currentThread();
pool.schedule(new Runnable() { Future<?> wakeup = pool.schedule(new Runnable() {
public void run() { public void run() {
me.interrupt(); me.interrupt();
}}, DELAY_IN_MS, TimeUnit.MILLISECONDS); }}, DELAY_IN_MS, TimeUnit.MILLISECONDS);
System.out.println("Copying file..."); System.out.println("Copying file...");
try { try {
long start = System.currentTimeMillis();
source.copyTo(target, ExtendedCopyOption.INTERRUPTIBLE); source.copyTo(target, ExtendedCopyOption.INTERRUPTIBLE);
throw new RuntimeException("Copy completed (this is not expected)"); long duration = System.currentTimeMillis() - start;
if (duration > DURATION_MAX_IN_MS)
throw new RuntimeException("Copy was not interrupted");
} catch (IOException e) { } catch (IOException e) {
boolean interrupted = Thread.interrupted(); boolean interrupted = Thread.interrupted();
if (!interrupted) if (!interrupted)
throw new RuntimeException("Interrupt status was not set"); throw new RuntimeException("Interrupt status was not set");
System.out.println("Copy failed (this is expected)"); System.out.println("Copy failed (this is expected)");
} }
try {
wakeup.get();
} catch (InterruptedException ignore) { }
Thread.interrupted();
// copy source to target via task in thread pool, interrupting it after // copy source to target via task in thread pool, interrupting it after
// a delay using cancel(true) // a delay using cancel(true)
...@@ -113,7 +121,6 @@ public class InterruptCopy { ...@@ -113,7 +121,6 @@ public class InterruptCopy {
System.out.println("Copy cancelled."); System.out.println("Copy cancelled.");
} finally { } finally {
pool.shutdown(); pool.shutdown();
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册