@Test(timeout = 100000)
public void testMapFileAccess() throws IOException {

  // This will run only in NativeIO is enabled as SecureIOUtils need it
  assumeTrue(NativeIO.isAvailable());
  Configuration conf = new Configuration();
  conf.setInt(ShuffleHandler.SHUFFLE_PORT_CONFIG_KEY, 0);
  conf.setInt(ShuffleHandler.MAX_SHUFFLE_CONNECTIONS, 3);
  conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
      "kerberos");
  UserGroupInformation.setConfiguration(conf);
  conf.set(YarnConfiguration.NM_LOCAL_DIRS, ABS_LOG_DIR.getAbsolutePath());
  ApplicationId appId = ApplicationId.newInstance(12345, 1);
  LOG.info(appId.toString());
  String appAttemptId = "attempt_12345_1_m_1_0";
  String user = "randomUser";
  String reducerId = "0";
  List<File> fileMap = new ArrayList<File>();
  createShuffleHandlerFiles(ABS_LOG_DIR, user, appId.toString(), appAttemptId,
      conf, fileMap);
  ShuffleHandler shuffleHandler = new ShuffleHandler() {
    @Override
    protected Shuffle getShuffle(Configuration conf) {
      // replace the shuffle handler with one stubbed for testing
      return new Shuffle(conf) {
        @Override
        protected void verifyRequest(String appid, ChannelHandlerContext ctx,
            HttpRequest request, HttpResponse response, URL requestUri)
            throws IOException {
          // Do nothing.
        }
      };
    }
  };
  AuxiliaryLocalPathHandler pathHandler = new TestAuxiliaryLocalPathHandler();
  shuffleHandler.setAuxiliaryLocalPathHandler(pathHandler);
  shuffleHandler.init(conf);
  try {
    shuffleHandler.start();
    DataOutputBuffer outputBuffer = new DataOutputBuffer();
    outputBuffer.reset();
    Token<JobTokenIdentifier> jt =
        new Token<JobTokenIdentifier>("identifier".getBytes(),
            "password".getBytes(), new Text(user), new Text("shuffleService"));
    jt.write(outputBuffer);
    shuffleHandler
      .initializeApplication(new ApplicationInitializationContext(user,
        appId, ByteBuffer.wrap(outputBuffer.getData(), 0,
          outputBuffer.getLength())));
    URL url =
        new URL(
            "http://127.0.0.1:"
                + shuffleHandler.getConfig().get(
                    ShuffleHandler.SHUFFLE_PORT_CONFIG_KEY)
                + "/mapOutput?job=job_12345_0001&reduce=" + reducerId
                + "&map=attempt_12345_1_m_1_0");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty(ShuffleHeader.HTTP_HEADER_NAME,
        ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
    conn.setRequestProperty(ShuffleHeader.HTTP_HEADER_VERSION,
        ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
    conn.connect();
    byte[] byteArr = new byte[10000];
    try {
      DataInputStream is = new DataInputStream(conn.getInputStream());
      is.readFully(byteArr);
    } catch (EOFException e) {
      // ignore
    }
    // Retrieve file owner name
    FileInputStream is = new FileInputStream(fileMap.get(0));
    String owner = NativeIO.POSIX.getFstat(is.getFD()).getOwner();
    is.close();
    String message =
        "Owner '" + owner + "' for path " + fileMap.get(0).getAbsolutePath()
            + " did not match expected owner '" + user + "'";
    Assert.assertTrue((new String(byteArr)).contains(message));
  } finally {
    shuffleHandler.stop();
    FileUtil.fullyDelete(ABS_LOG_DIR);
  }
}