@Override
  public int run(String[] args) throws Exception {
    handleOpts(args);

    Integer exitCode = 1;
    UserGroupInformation loginUser = UserGroupInformation.getLoginUser();
    // If we're running as the user, then no need to impersonate
    // (which might fail if user is not a proxyuser for themselves)
    // Also if !proxy is set
    if (!proxy || loginUser.getShortUserName().equals(user)) {
      LOG.info("Running as " + user);
      exitCode = runInternal();
    } else {
      // Otherwise impersonate user.  If we're not allowed to, then this will
      // fail with an Exception
      LOG.info("Running as " + loginUser.getShortUserName() + " but will " +
          "impersonate " + user);
      UserGroupInformation proxyUser =
          UserGroupInformation.createProxyUser(user, loginUser);
      exitCode = proxyUser.doAs(new PrivilegedExceptionAction<Integer>() {
        @Override
        public Integer run() throws Exception {
          return runInternal();
        }
      });
    }
    return exitCode;
  }
@Test
  public void testHadoopArchiveLogsWithArchiveError() throws Exception {
    String[] args = getArgs();
    final HadoopArchiveLogsRunner halr = new HadoopArchiveLogsRunner(conf);
    HadoopArchives mockHadoopArchives = mock(HadoopArchives.class);
    when(mockHadoopArchives.run(Mockito.<String[]>any())).thenReturn(-1);
    halr.hadoopArchives = mockHadoopArchives;
    assertNotEquals(0, ToolRunner.run(halr, args));

    // Make sure the original log files are intact
    FileStatus[] app1Files = fs.listStatus(app1Path);
    assertEquals(FILE_COUNT, app1Files.length);
    for (int i = 0; i < FILE_COUNT; i++) {
      Assert.assertEquals(FILE_SIZES[i] * FILE_SIZE_INCREMENT,
          app1Files[i].getLen());
    }
  }