@Test(timeout = 30000)
public void testcheckAndGetApplicationLifetime() throws Exception {

  long maxLifetime = 10;
  long defaultLifetime = 5;
  // positive integer value
  CapacityScheduler cs = setUpCSQueue(maxLifetime, defaultLifetime);
  Assert.assertEquals(maxLifetime,
      cs.checkAndGetApplicationLifetime("default", 100));
  Assert.assertEquals(9, cs.checkAndGetApplicationLifetime("default", 9));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", -1));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", 0));
  Assert.assertEquals(maxLifetime,
      cs.getMaximumApplicationLifetime("default"));
  maxLifetime = -1;
  defaultLifetime = -1;
  // test for default values
  cs = setUpCSQueue(maxLifetime, defaultLifetime);
  Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", -1));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", 0));
  Assert.assertEquals(maxLifetime,
      cs.getMaximumApplicationLifetime("default"));
  maxLifetime = 10;
  defaultLifetime = 10;
  cs = setUpCSQueue(maxLifetime, defaultLifetime);
  Assert.assertEquals(maxLifetime,
      cs.checkAndGetApplicationLifetime("default", 100));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", -1));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", 0));
  Assert.assertEquals(maxLifetime,
      cs.getMaximumApplicationLifetime("default"));
  maxLifetime = 0;
  defaultLifetime = 0;
  cs = setUpCSQueue(maxLifetime, defaultLifetime);
  Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", -1));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", 0));
  maxLifetime = 10;
  defaultLifetime = -1;
  cs = setUpCSQueue(maxLifetime, defaultLifetime);
  Assert.assertEquals(maxLifetime,
      cs.checkAndGetApplicationLifetime("default", 100));
  Assert.assertEquals(maxLifetime,
      cs.checkAndGetApplicationLifetime("default", -1));
  Assert.assertEquals(maxLifetime,
      cs.checkAndGetApplicationLifetime("default", 0));
  maxLifetime = 5;
  defaultLifetime = 10;
  try {
    setUpCSQueue(maxLifetime, defaultLifetime);
    Assert.fail("Expected to fails since maxLifetime < defaultLifetime.");
  } catch (ServiceStateException sse) {
    Throwable rootCause = sse.getCause().getCause();
    Assert.assertTrue(
        rootCause.getMessage().contains("can't exceed maximum lifetime"));
  }
  maxLifetime = -1;
  defaultLifetime = 10;
  cs = setUpCSQueue(maxLifetime, defaultLifetime);
  Assert.assertEquals(100,
      cs.checkAndGetApplicationLifetime("default", 100));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", -1));
  Assert.assertEquals(defaultLifetime,
      cs.checkAndGetApplicationLifetime("default", 0));
}