@Test(timeout = 10000)
public void testCheckFilesAndSeedApps() throws Exception {

  Configuration conf = new Configuration();
  HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
  FileSystem fs = FileSystem.getLocal(conf);
  Path rootLogDir = new Path("target", "logs");
  String suffix = "logs";
  Path logDir = new Path(rootLogDir, new Path(USER, suffix));
  fs.delete(logDir, true);
  Assert.assertFalse(fs.exists(logDir));
  fs.mkdirs(logDir);
  // no files found
  ApplicationId appId1 = ApplicationId.newInstance(CLUSTER_TIMESTAMP, 1);
  Path app1Path = new Path(logDir, appId1.toString());
  fs.mkdirs(app1Path);
  // too few files
  ApplicationId appId2 = ApplicationId.newInstance(CLUSTER_TIMESTAMP, 2);
  Path app2Path = new Path(logDir, appId2.toString());
  fs.mkdirs(app2Path);
  createFile(fs, new Path(app2Path, "file1"), 1);
  hal.minNumLogFiles = 2;
  // too large
  ApplicationId appId3 = ApplicationId.newInstance(CLUSTER_TIMESTAMP, 3);
  Path app3Path = new Path(logDir, appId3.toString());
  fs.mkdirs(app3Path);
  createFile(fs, new Path(app3Path, "file1"), 2);
  createFile(fs, new Path(app3Path, "file2"), 5);
  hal.maxTotalLogsSize = FILE_SIZE_INCREMENT * 6;
  // has har already
  ApplicationId appId4 = ApplicationId.newInstance(CLUSTER_TIMESTAMP, 4);
  Path app4Path = new Path(logDir, appId4.toString());
  fs.mkdirs(app4Path);
  createFile(fs, new Path(app4Path, appId4 + ".har"), 1);
  // just right
  ApplicationId appId5 = ApplicationId.newInstance(CLUSTER_TIMESTAMP, 5);
  Path app5Path = new Path(logDir, appId5.toString());
  fs.mkdirs(app5Path);
  createFile(fs, new Path(app5Path, "file1"), 2);
  createFile(fs, new Path(app5Path, "file2"), 3);
  Assert.assertEquals(0, hal.eligibleApplications.size());
  hal.checkFilesAndSeedApps(fs, rootLogDir, suffix, new Path(rootLogDir,
      "archive-logs-work"));
  Assert.assertEquals(1, hal.eligibleApplications.size());
  Assert.assertEquals(appId5.toString(),
      hal.eligibleApplications.iterator().next().getAppId());
}