public static boolean isAvailable() {
    return NativeCodeLoader.isNativeCodeLoaded() && nativeLoaded;
  }
@Test(timeout=10000)
  public void testMlock() throws Exception {
    assumeTrue(NativeIO.isAvailable());
    final File TEST_FILE = GenericTestUtils.getTestDir("testMlockFile");
    final int BUF_LEN = 12289;
    byte buf[] = new byte[BUF_LEN];
    int bufSum = 0;
    for (int i = 0; i < buf.length; i++) {
      buf[i] = (byte)(i % 60);
      bufSum += buf[i];
    }
    FileOutputStream fos = new FileOutputStream(TEST_FILE);
    try {
      fos.write(buf);
      fos.getChannel().force(true);
    } finally {
      fos.close();
    }
    
    FileInputStream fis = null;
    FileChannel channel = null;
    try {
      // Map file into memory
      fis = new FileInputStream(TEST_FILE);
      channel = fis.getChannel();
      long fileSize = channel.size();
      MappedByteBuffer mapbuf = channel.map(MapMode.READ_ONLY, 0, fileSize);
      // mlock the buffer
      NativeIO.POSIX.mlock(mapbuf, fileSize);
      // Read the buffer
      int sum = 0;
      for (int i=0; i<fileSize; i++) {
        sum += mapbuf.get(i);
      }
      assertEquals("Expected sums to be equal", bufSum, sum);
      // munmap the buffer, which also implicitly unlocks it
      NativeIO.POSIX.munmap(mapbuf);
    } finally {
      if (channel != null) {
        channel.close();
      }
      if (fis != null) {
        fis.close();
      }
    }
  }