changeset 16875:e6ae37815239

8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write Summary: Change tests to improve odds of passing on slow file systems. Reviewed-by: clanger, rriggs
author bpb
date Thu, 16 Mar 2017 08:58:31 -0700
parents 7b8e364b2faf
children a89d57a24005 9158f22042bb
files test/java/io/FileInputStream/LargeFileAvailable.java test/java/nio/channels/FileChannel/LoopingTruncate.java test/java/nio/channels/FileChannel/Transfer.java test/java/nio/channels/FileChannel/Transfers.java
diffstat 4 files changed, 37 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/io/FileInputStream/LargeFileAvailable.java	Thu Mar 16 15:30:54 2017 +0000
+++ b/test/java/io/FileInputStream/LargeFileAvailable.java	Thu Mar 16 08:58:31 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2017, 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
@@ -27,6 +27,7 @@
  * @key intermittent
  * @summary Test if available returns correct value when reading
  *          a large file.
+ * @run main/timeout=300 LargeFileAvailable
  */
 
 import java.io.*;
@@ -34,6 +35,7 @@
 import java.nio.channels.*;
 import java.nio.file.Files;
 import static java.nio.file.StandardOpenOption.*;
+import java.util.concurrent.TimeUnit;
 
 public class LargeFileAvailable {
     public static void main(String args[]) throws Exception {
@@ -110,7 +112,12 @@
                               CREATE_NEW, WRITE, SPARSE)) {
             ByteBuffer bb = ByteBuffer.allocate(1).put((byte)1);
             bb.rewind();
+            System.out.println("  Writing large file...");
+            long t0 = System.nanoTime();
             int rc = fc.write(bb, filesize - 1);
+            long t1 = System.nanoTime();
+            System.out.printf("  Wrote large file in %d ns (%d ms) %n",
+                t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
 
             if (rc != 1) {
                 throw new RuntimeException("Failed to write 1 byte"
--- a/test/java/nio/channels/FileChannel/LoopingTruncate.java	Thu Mar 16 15:30:54 2017 +0000
+++ b/test/java/nio/channels/FileChannel/LoopingTruncate.java	Thu Mar 16 08:58:31 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -28,7 +28,7 @@
  * @summary (fc) Infinite loop FileChannel.truncate
  * @library /lib/testlibrary
  * @build jdk.testlibrary.Utils
- * @run main/othervm LoopingTruncate
+ * @run main/othervm/timeout=300 LoopingTruncate
  */
 
 import java.nio.ByteBuffer;
@@ -37,6 +37,7 @@
 import java.nio.file.Files;
 import java.nio.file.Path;
 import static java.nio.file.StandardOpenOption.*;
+import java.util.concurrent.TimeUnit;
 import static jdk.testlibrary.Utils.adjustTimeout;
 
 public class LoopingTruncate {
@@ -51,11 +52,21 @@
         Path path = Files.createTempFile("LoopingTruncate.tmp", null);
         try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) {
             fc.position(FATEFUL_SIZE + 1L);
+            System.out.println("  Writing large file...");
+            long t0 = System.nanoTime();
             fc.write(ByteBuffer.wrap(new byte[] {0}));
+            long t1 = System.nanoTime();
+            System.out.printf("  Wrote large file in %d ns (%d ms) %n",
+                t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
 
             Thread th = new Thread(() -> {
                 try {
+                    System.out.println("  Truncating large file...");
+                    long t2 = System.nanoTime();
                     fc.truncate(FATEFUL_SIZE);
+                    long t3 = System.nanoTime();
+                    System.out.printf("  Truncated large file in %d ns (%d ms) %n",
+                        t3 - t2, TimeUnit.NANOSECONDS.toMillis(t3 - t2));
                 } catch (ClosedByInterruptException ignore) {
                 } catch (Exception e) {
                     throw new RuntimeException(e);
--- a/test/java/nio/channels/FileChannel/Transfer.java	Thu Mar 16 15:30:54 2017 +0000
+++ b/test/java/nio/channels/FileChannel/Transfer.java	Thu Mar 16 08:58:31 2017 -0700
@@ -29,7 +29,7 @@
  * @library ..
  * @library /lib/testlibrary/
  * @build jdk.testlibrary.*
- * @run testng Transfer
+ * @run testng/timeout=300 Transfer
  * @key randomness
  */
 
@@ -256,7 +256,13 @@
         initTestFile(source, 10);
         RandomAccessFile raf = new RandomAccessFile(source, "rw");
         FileChannel fc = raf.getChannel();
+        out.println("  Writing large file...");
+        long t0 = System.nanoTime();
         fc.write(ByteBuffer.wrap("Use the source!".getBytes()), testSize - 40);
+        long t1 = System.nanoTime();
+        out.printf("  Wrote large file in %d ns (%d ms) %n",
+            t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
+
         fc.close();
         raf.close();
 
@@ -310,8 +316,13 @@
 
         long testSize = ((long)Integer.MAX_VALUE) * 2;
         try {
+            out.println("  Writing large file...");
+            long t0 = System.nanoTime();
             fc.write(ByteBuffer.wrap("Use the source!".getBytes()),
                      testSize - 40);
+            long t1 = System.nanoTime();
+            out.printf("  Wrote large file in %d ns (%d ms) %n",
+            t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
         } catch (IOException e) {
             // Can't set up the test, abort it
             err.println("xferTest05 was aborted.");
@@ -444,12 +455,12 @@
         RandomAccessFile raf = new RandomAccessFile(file, "rw");
         FileChannel fc = raf.getChannel();
 
-        out.println("  Creating large file...");
+        out.println("  Writing large file...");
         long t0 = System.nanoTime();
         try {
             fc.write(ByteBuffer.wrap("0123456789012345".getBytes("UTF-8")), 6*G);
             long t1 = System.nanoTime();
-            out.printf("  Created large file in %d ns (%d ms) %n",
+            out.printf("  Wrote large file in %d ns (%d ms) %n",
             t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
         } catch (IOException x) {
             err.println("  Unable to create test file:" + x);
--- a/test/java/nio/channels/FileChannel/Transfers.java	Thu Mar 16 15:30:54 2017 +0000
+++ b/test/java/nio/channels/FileChannel/Transfers.java	Thu Mar 16 08:58:31 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2017, 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
@@ -26,6 +26,7 @@
  * @summary Comprehensive test for FileChannel.transfer{From,To}
  * @bug 4708120
  * @author Mark Reinhold
+ * @run main/timeout=300 Transfers
  */
 
 import java.io.*;