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

  Configuration conf = new Configuration();
  HadoopArchiveLogs.AppInfo app1 = new HadoopArchiveLogs.AppInfo(
      ApplicationId.newInstance(CLUSTER_TIMESTAMP, 1).toString(), USER);
  app1.setFinishTime(CLUSTER_TIMESTAMP - 5);
  HadoopArchiveLogs.AppInfo app2 = new HadoopArchiveLogs.AppInfo(
      ApplicationId.newInstance(CLUSTER_TIMESTAMP, 2).toString(), USER);
  app2.setFinishTime(CLUSTER_TIMESTAMP - 10);
  HadoopArchiveLogs.AppInfo app3 = new HadoopArchiveLogs.AppInfo(
      ApplicationId.newInstance(CLUSTER_TIMESTAMP, 3).toString(), USER);
  // app3 has no finish time set
  HadoopArchiveLogs.AppInfo app4 = new HadoopArchiveLogs.AppInfo(
      ApplicationId.newInstance(CLUSTER_TIMESTAMP, 4).toString(), USER);
  app4.setFinishTime(CLUSTER_TIMESTAMP + 5);
  HadoopArchiveLogs.AppInfo app5 = new HadoopArchiveLogs.AppInfo(
      ApplicationId.newInstance(CLUSTER_TIMESTAMP, 5).toString(), USER);
  app5.setFinishTime(CLUSTER_TIMESTAMP + 10);
  HadoopArchiveLogs.AppInfo app6 = new HadoopArchiveLogs.AppInfo(
      ApplicationId.newInstance(CLUSTER_TIMESTAMP, 6).toString(), USER);
  // app6 has no finish time set
  HadoopArchiveLogs.AppInfo app7 = new HadoopArchiveLogs.AppInfo(
      ApplicationId.newInstance(CLUSTER_TIMESTAMP, 7).toString(), USER);
  app7.setFinishTime(CLUSTER_TIMESTAMP);
  HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
  Assert.assertEquals(0, hal.eligibleApplications.size());
  hal.eligibleApplications.add(app1);
  hal.eligibleApplications.add(app2);
  hal.eligibleApplications.add(app3);
  hal.eligibleApplications.add(app4);
  hal.eligibleApplications.add(app5);
  hal.eligibleApplications.add(app6);
  hal.eligibleApplications.add(app7);
  Assert.assertEquals(7, hal.eligibleApplications.size());
  hal.maxEligible = -1;
  hal.checkMaxEligible();
  Assert.assertEquals(7, hal.eligibleApplications.size());
  hal.maxEligible = 6;
  hal.checkMaxEligible();
  Assert.assertEquals(6, hal.eligibleApplications.size());
  Assert.assertFalse(hal.eligibleApplications.contains(app5));
  hal.maxEligible = 5;
  hal.checkMaxEligible();
  Assert.assertEquals(5, hal.eligibleApplications.size());
  Assert.assertFalse(hal.eligibleApplications.contains(app4));
  hal.maxEligible = 4;
  hal.checkMaxEligible();
  Assert.assertEquals(4, hal.eligibleApplications.size());
  Assert.assertFalse(hal.eligibleApplications.contains(app7));
  hal.maxEligible = 3;
  hal.checkMaxEligible();
  Assert.assertEquals(3, hal.eligibleApplications.size());
  Assert.assertFalse(hal.eligibleApplications.contains(app1));
  hal.maxEligible = 2;
  hal.checkMaxEligible();
  Assert.assertEquals(2, hal.eligibleApplications.size());
  Assert.assertFalse(hal.eligibleApplications.contains(app2));
  hal.maxEligible = 1;
  hal.checkMaxEligible();
  Assert.assertEquals(1, hal.eligibleApplications.size());
  Assert.assertFalse(hal.eligibleApplications.contains(app6));
  Assert.assertTrue(hal.eligibleApplications.contains(app3));
}