HadoopArchiveLogsRunner implements Tool { @Override public int run(String[] args) throws Exception { handleOpts(args); Integer exitCode = 1; UserGroupInformation loginUser = UserGroupInformation.getLoginUser(); if (!proxy || loginUser.getShortUserName().equals(user)) { LOG.info("Running as " + user); exitCode = runInternal(); } else { 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; } HadoopArchiveLogsRunner(Configuration conf); static void main(String[] args); @Override int run(String[] args); @Override void setConf(Configuration conf); @Override Configuration getConf();  }
@Test public void testHadoopArchiveLogs() throws Exception { String[] args = getArgs(); final HadoopArchiveLogsRunner halr = new HadoopArchiveLogsRunner(conf); assertEquals(0, ToolRunner.run(halr, args)); fs = FileSystem.get(conf); FileStatus[] app1Files = fs.listStatus(app1Path); Assert.assertEquals(1, app1Files.length); FileStatus harFile = app1Files[0]; Assert.assertEquals(app1.toString() + ".har", harFile.getPath().getName()); Path harPath = new Path("har: FileStatus[] harLogs = HarFs.get(harPath.toUri(), conf).listStatus(harPath); Assert.assertEquals(FILE_COUNT, harLogs.length); Arrays.sort(harLogs, new Comparator<FileStatus>() { @Override public int compare(FileStatus o1, FileStatus o2) { return o1.getPath().getName().compareTo(o2.getPath().getName()); } }); for (int i = 0; i < FILE_COUNT; i++) { FileStatus harLog = harLogs[i]; Assert.assertEquals("log" + (i + 1), harLog.getPath().getName()); Assert.assertEquals(FILE_SIZES[i] * FILE_SIZE_INCREMENT, harLog.getLen()); Assert.assertEquals( new FsPermission(FsAction.READ_WRITE, FsAction.READ, FsAction.NONE), harLog.getPermission()); Assert.assertEquals(System.getProperty("user.name"), harLog.getOwner()); } Assert.assertEquals(0, fs.listStatus(workingDir).length); }
@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)); 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()); } }