< prev index next >

test/jdk/java/nio/channels/FileChannel/LoopingTruncate.java

Print this page
rev 51731 : imported patch 8210732


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 8137121 8137230
  27  * @summary (fc) Infinite loop FileChannel.truncate
  28  * @library /lib/testlibrary
  29  * @build jdk.testlibrary.Utils
  30  * @run main/othervm/timeout=300 LoopingTruncate
  31  */
  32 
  33 import java.nio.ByteBuffer;
  34 import java.nio.channels.FileChannel;
  35 import java.nio.channels.ClosedByInterruptException;
  36 import java.nio.file.Files;
  37 import java.nio.file.Path;
  38 import static java.nio.file.StandardOpenOption.*;
  39 import java.util.concurrent.TimeUnit;
  40 import static jdk.testlibrary.Utils.adjustTimeout;
  41 
  42 public class LoopingTruncate {
  43 
  44     // (int)FATEFUL_SIZE == -3 == IOStatus.INTERRUPTED
  45     static long FATEFUL_SIZE = 0x1FFFFFFFDL;
  46 
  47     // At least 20 seconds
  48     static long TIMEOUT = adjustTimeout(20_000);
  49 
  50     public static void main(String[] args) throws Throwable {
  51         Path path = Files.createTempFile("LoopingTruncate.tmp", null);
  52         try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) {
  53             fc.position(FATEFUL_SIZE + 1L);
  54             System.out.println("  Writing large file...");
  55             long t0 = System.nanoTime();
  56             fc.write(ByteBuffer.wrap(new byte[] {0}));
  57             long t1 = System.nanoTime();
  58             System.out.printf("  Wrote large file in %d ns (%d ms) %n",
  59                 t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
  60 




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 8137121 8137230
  27  * @summary (fc) Infinite loop FileChannel.truncate
  28  * @library /test/lib
  29  * @build jdk.test.lib.Utils
  30  * @run main/othervm/timeout=300 LoopingTruncate
  31  */
  32 
  33 import java.nio.ByteBuffer;
  34 import java.nio.channels.FileChannel;
  35 import java.nio.channels.ClosedByInterruptException;
  36 import java.nio.file.Files;
  37 import java.nio.file.Path;
  38 import static java.nio.file.StandardOpenOption.*;
  39 import java.util.concurrent.TimeUnit;
  40 import static jdk.test.lib.Utils.adjustTimeout;
  41 
  42 public class LoopingTruncate {
  43 
  44     // (int)FATEFUL_SIZE == -3 == IOStatus.INTERRUPTED
  45     static long FATEFUL_SIZE = 0x1FFFFFFFDL;
  46 
  47     // At least 20 seconds
  48     static long TIMEOUT = adjustTimeout(20_000);
  49 
  50     public static void main(String[] args) throws Throwable {
  51         Path path = Files.createTempFile("LoopingTruncate.tmp", null);
  52         try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) {
  53             fc.position(FATEFUL_SIZE + 1L);
  54             System.out.println("  Writing large file...");
  55             long t0 = System.nanoTime();
  56             fc.write(ByteBuffer.wrap(new byte[] {0}));
  57             long t1 = System.nanoTime();
  58             System.out.printf("  Wrote large file in %d ns (%d ms) %n",
  59                 t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
  60 


< prev index next >