< prev index next >

test/jdk/java/nio/channels/FileChannel/directio/DirectIOTest.java

Print this page
rev 59383 : [mq]: final
   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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 8164900
  27  * @summary Test for ExtendedOpenOption.DIRECT flag
  28  * @requires (os.family == "linux" | os.family == "solaris"
  29  *         | os.family == "aix")
  30  * @library /test/lib
  31  * @build jdk.test.lib.Platform
  32  * @run main/native DirectIOTest
  33  */
  34 
  35 import java.io.*;
  36 import java.nio.ByteBuffer;
  37 import java.nio.CharBuffer;
  38 import java.nio.channels.*;
  39 import java.nio.channels.FileChannel;
  40 import java.nio.file.Paths;
  41 import java.nio.file.Path;
  42 import java.nio.file.Files;
  43 import jdk.test.lib.Platform;
  44 import java.nio.file.FileStore;
  45 import java.nio.file.StandardOpenOption;
  46 import com.sun.nio.file.ExtendedOpenOption;
  47 
  48 public class DirectIOTest {
  49 


  63             fc.write(src);
  64         }
  65     }
  66 
  67     private static void testRead(Path p) throws Exception {
  68         try (FileChannel fc = FileChannel.open(p, ExtendedOpenOption.DIRECT)) {
  69             FileStore fs = Files.getFileStore(p);
  70             int alignment = (int)fs.getBlockSize();
  71             ByteBuffer dest = ByteBuffer.allocateDirect(SIZE + alignment - 1)
  72                                         .alignedSlice(alignment);
  73             fc.read(dest);
  74         }
  75     }
  76 
  77     public static Path createTempFile() throws IOException {
  78         return Files.createTempFile(
  79             Paths.get(System.getProperty("test.dir", ".")), "test", null);
  80     }
  81 
  82     public static boolean isDirectIOSupportedByFS(Path p) throws Exception {
  83         boolean supported = true;
  84         if (Platform.isSolaris()) {
  85             String fsType = Files.getFileStore(p).type();
  86             if (!fsType.equals("nfs") && !fsType.equals("ufs")) {
  87                 // print a message and return without failing
  88                 System.out.format("Skipping test: file system type %s of "
  89                     + "FileStore of %s is neither nfs nor ufs.%n", fsType, p);
  90                 supported = false;
  91             }
  92         }
  93         return supported;
  94     }
  95 
  96     private static boolean isFileInCache(Path p) {
  97         String path = p.toString();
  98         return isFileInCache0(SIZE, path);
  99     }
 100 
 101     private static native boolean isFileInCache0(int size, String path);
 102 
 103     public static void main(String[] args) throws Exception {
 104         Path p = createTempFile();
 105 
 106         if (!isDirectIOSupportedByFS(p)) {
 107             Files.delete(p);
 108             return;
 109         }
 110 
 111         System.loadLibrary("DirectIO");
 112 
 113         try {
   1 /*
   2  * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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 8164900
  27  * @summary Test for ExtendedOpenOption.DIRECT flag
  28  * @requires (os.family == "linux" | os.family == "aix")

  29  * @library /test/lib
  30  * @build jdk.test.lib.Platform
  31  * @run main/native DirectIOTest
  32  */
  33 
  34 import java.io.*;
  35 import java.nio.ByteBuffer;
  36 import java.nio.CharBuffer;
  37 import java.nio.channels.*;
  38 import java.nio.channels.FileChannel;
  39 import java.nio.file.Paths;
  40 import java.nio.file.Path;
  41 import java.nio.file.Files;
  42 import jdk.test.lib.Platform;
  43 import java.nio.file.FileStore;
  44 import java.nio.file.StandardOpenOption;
  45 import com.sun.nio.file.ExtendedOpenOption;
  46 
  47 public class DirectIOTest {
  48 


  62             fc.write(src);
  63         }
  64     }
  65 
  66     private static void testRead(Path p) throws Exception {
  67         try (FileChannel fc = FileChannel.open(p, ExtendedOpenOption.DIRECT)) {
  68             FileStore fs = Files.getFileStore(p);
  69             int alignment = (int)fs.getBlockSize();
  70             ByteBuffer dest = ByteBuffer.allocateDirect(SIZE + alignment - 1)
  71                                         .alignedSlice(alignment);
  72             fc.read(dest);
  73         }
  74     }
  75 
  76     public static Path createTempFile() throws IOException {
  77         return Files.createTempFile(
  78             Paths.get(System.getProperty("test.dir", ".")), "test", null);
  79     }
  80 
  81     public static boolean isDirectIOSupportedByFS(Path p) throws Exception {
  82         return true;










  83     }
  84 
  85     private static boolean isFileInCache(Path p) {
  86         String path = p.toString();
  87         return isFileInCache0(SIZE, path);
  88     }
  89 
  90     private static native boolean isFileInCache0(int size, String path);
  91 
  92     public static void main(String[] args) throws Exception {
  93         Path p = createTempFile();
  94 
  95         if (!isDirectIOSupportedByFS(p)) {
  96             Files.delete(p);
  97             return;
  98         }
  99 
 100         System.loadLibrary("DirectIO");
 101 
 102         try {
< prev index next >