LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.FOREVER);
set = prepareSet(set);
lrm.renewFor(prepareLease(set.getRenewalSetLease()), Long.MAX_VALUE, null);
// create a handback object
MarshalledObject handback = new MarshalledObject(new Integer(99));
// register listener to receive events
EventRegistration evReg =
set.setRenewalFailureListener(rrl, handback);
evReg = prepareRegistration(evReg);
// create a lease that will fail to renew
logger.log(Level.FINE, "Creating the lease to be managed.");
logger.log(Level.FINE, "Duration == " + renewGrant);
TestLease testLease =
leaseProvider.createNewLease(definiteOwner,
rstUtil.durToExp(renewGrant));
// start managing the lease for as long as we can
logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
logger.log(Level.FINE, "Membership = Lease.FOREVER.");
set.renewFor(testLease, Lease.FOREVER);
// wait for the lease to expire
rstUtil.waitForLeaseExpiration(testLease,
"for client lease to expire.");
/* Assert that the notification was received at approximately
the lease expiration time */
Long[] arrivalTimes = rrl.getArrivalTimes();
// must at lease have received one event
if (arrivalTimes.length == 0) {
String message = "RenewalFailure event never received.";
throw new TestException(message);
}
// must NOT have received more than one event
if (arrivalTimes.length > 1) {
String message = "Too many events received.";
throw new TestException(message);
}
/* TESTING ASSERTION #1
was the event received around the right time? */
long leaseExpiration = testLease.getExpiration();
long maxAllowed = leaseExpiration + latencySlop;
long actualArrivalTime = arrivalTimes[0].longValue();
// event must arrive within our assumed constraints
if (actualArrivalTime < maxAllowed) {
// we say event was received around the right time
logger.log(Level.FINE, "Assertion #1 passes!");
} else {
/* There was a lag. This could be a network problem or an
overloaded cpu but we will just have to assume that the
specification was not met. */
String message = "Assertion #1 failed ...\n" +
"Event was not received within " + latencySlop +
" milliseconds of client lease expiration.";
throw new TestException(message);
}
/* TESTING ASSERTION #2
the handback object is the one we expect. */
RemoteEvent[] events = rrl.getEvents();
MarshalledObject mObj = events[0].getRegistrationObject();
if (handback.equals(mObj) == false) {
String message = "Assertion #2 failed ...\n" +
"Handback object does not match original.";
throw new TestException(message);
}