"Lease.FOREVER");
long time01 = System.currentTimeMillis();
set.renewFor(testLease, Lease.FOREVER);
// Assert that the managed lease has original expiration time
Lease managedLease = set.remove(testLease);
long time02 = System.currentTimeMillis();
long actualExpTime = managedLease.getExpiration();
long deltaExpTime = actualExpTime - originalExpTime;
long roundTrip = time02 - time01;
if (deltaExpTime >= roundTrip) {
String message = "Expiration time was permaturely altered.";
throw new TestException(message);
}
// just to make certain assert that there are no renew or cancels
if (leaseOwner.getRenewCalls() > 0) {
String message = "LRS made an erronous call to renew.";
throw new TestException(message);
}
if (leaseOwner.getCancelCalls() > 0) {
String message = "LRS made a forbidden call to cancel.";
throw new TestException(message);
}
// create a test lease to be managed
logger.log(Level.FINE, "Creating the lease to be managed.");
logger.log(Level.FINE, "Duration == " + renewGrant);
long leaseCreation = System.currentTimeMillis();
testLease =
leaseProvider.createNewLease(leaseOwner,
rstUtil.durToExp(renewGrant));
originalExpTime = testLease.getExpiration();
// start managing the lease
long membershipDuration = renewGrant + (renewGrant / 2);
logger.log(Level.FINE, "Adding lease with membership of " +
membershipDuration + " millseconds.");
set.renewFor(testLease, membershipDuration);
// wait for client lease to become renewed
rstUtil.waitForLeaseExpiration(testLease,
"for client lease to renew.");
// remove the lease to prevent any further action
managedLease = set.remove(testLease);
/* By now the lease has been renewed (exactly) once.
To show that the expiration time of the lease reflects
the time set as a result of the last successful renew,
we will show that the renewal time is between the time
the test lease was originally created and its original
expiration time.
T0---------------T1----------T2-------------T3
\lease \renewal \original \current
creation time expriation expiration
Calculate T1 (T3-renewalGrant) and show that T0 < T1 < T2 */
long renewalTime = managedLease.getExpiration() - renewGrant;
boolean inRange = renewalTime > leaseCreation &&
renewalTime < originalExpTime;
if (inRange == false) {
String message = "Lease expiration does not reflect the\n" +
"latest successful renewal.";