// create a lease renewal set
LeaseRenewalSet set = lrs.createLeaseRenewalSet(renewSetDur);
set = prepareSet(set);
// create a handback object
MarshalledObject handback = new MarshalledObject(new Integer(99));
// register listener to receive events
EventRegistration evReg =
set.setExpirationWarningListener(rrl, minWarning, handback);
evReg = prepareRegistration(evReg);
if (rstUtil.isValidExpWarnEventReg(evReg, set) == false) {
String message = "Event Registration is invalid.";
message += rstUtil.getFailureReason();
throw new TestException(message);
}
// allow the set's lease to expire
rstUtil.waitForRemoteEvents(rrl, 1, renewSetDur);
/* Assert that the notification was received at approximately
the lease expiration time - minWarning */
Long[] arrivalTimes = rrl.getArrivalTimes();
// must at lease have received one event
if (arrivalTimes.length == 0) {
String message = "ExpirationWarning 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? */
String prop = "com.sun.jini.test.spec.renewalservice." +
"slop_percent_tolerance";
int tolerance =
getConfig().getIntConfigVal(prop, SLOP_PERCENT_TOLERANCE);
logger.log(Level.FINE, "Allowing a slop tolerance of (+/-)" +
tolerance + "% of expected warning time.");
long leaseExpiration = prepareLease(set.getRenewalSetLease()).getExpiration();
long idealArrival = leaseExpiration - minWarning;
long arrivalSlop = minWarning * tolerance / 100;
long minAllowed = idealArrival - arrivalSlop;
long maxAllowed = idealArrival + arrivalSlop;
long actualArrivalTime = arrivalTimes[0].longValue();
if (actualArrivalTime > minAllowed &&
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 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";
message += "Event was not received +/- " + arrivalSlop;
message += " milliseconds.";
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";
message += "Handback object does not match original.";
throw new TestException(message);
}