// wait for expiration warning event
warnWaitThread.join(maxWaitTime);
if (warnWaitThread.isAlive() == true) {
String message = "ExpirationWarningEvent was never received.";
throw new TestException(message);
}
// capture the expiration time of the warning event
ExpirationWarningEvent warnEvent =
(ExpirationWarningEvent) warnListener.getEvents()[0];
long warnEventExpiration =
prepareLease(warnEvent.getRenewalSetLease()).getExpiration();
// wait for renewal failure event
failWaitThread.join(maxWaitTime);
// if the thread is still alive then the event was never received.
if (failWaitThread.isAlive() == true) {
String message = "RenewalFailureEvent was never received.";
throw new TestException(message);
}
// capture the expiration time of the renewal failure event
RenewalFailureEvent failEvent =
(RenewalFailureEvent) failListener.getEvents()[0];
long failEventExpiration = failEvent.getLease().getExpiration();
logger.log(Level.FINE, "Number of failure events = " +
warnListener.getEvents().length);
logger.log(Level.FINE, "Number of warning events = " +
failListener.getEvents().length);
/* ASSERTION #1 :
assert that the leases are the ones we expect */
if (warnLease.equals(prepareLease(warnEvent.getRenewalSetLease())) == false) {
String message = "Assertion #1 failed.\n" +
"Expiration warning lease does not match\n" +
"the lease encapsulated in the ExpirationWarningEvent " +
"object.";
throw new TestException(message);
}
if (failLease.equals(failEvent.getLease()) == false) {
String message = "Assertion #1 has failed.\n" +
"Renewal failure lease does not match the " +
"lease encapsulated in the RenewalFailureEvent object.";
throw new TestException(message);
}
logger.log(Level.FINE, "Assertion #1 passed.");
/* ASSERTION #2 :
the expiration will reflect the expiration of the lease
when the event occurred. */
long delta = warnLeaseExpiration - warnEventExpiration;
if (Math.abs(delta) > roundTrip) {
logger.log(Level.FINE, "Assertion #2 failed, delta = " + delta
+ " 10*roundTrip = " + roundTrip);
String message = "Assertion #2 has failed.\n" +
"Expiration time of lease in warning event does not\n" +
"reflect the expiration of the lease when the event " +
"occurred.";
throw new TestException(message);
} else {
logger.log(Level.FINE, "Assertion #2 passed, delta = " + delta
+ " 10*roundTrip = " + roundTrip);
}
/*
* This portion of the assertion is pretty weak. All it says
* is that the expiration time on the lease is at least
* within one renewGrant times worth of the original lease.
* That's pretty broad and may not be particularly useful.
* The problem is that there is no real way of determining
* exactly what the lease expiration was at the time the renewal
* failure event occurred and there is a significant (5 second)
* time interval between the delivery of the marshalling of the
* lease object and the delivery of the event.
*/
if (failEventExpiration > nextFailExpiration) {
String message = "Assertion #2 has failed.\n" +
"Expiration time of lease in failure event does not\n" +
"reflect the expiration of the lease when the event " +
"occurred.";
throw new TestException(message);
}
logger.log(Level.FINE, "Assertion #2 passed.");
/* ASSERTION #3 :
The Throwable Object is the one expected. */
Throwable failException = failEvent.getThrowable();
Throwable targetException = getExpectedException();
if (! (failException.getClass() == targetException.getClass())) {
String message = "Assertion #3 has failed.\n" +
"Throwable encapsulated by the RenewalFailureEvent is" +
" of type " + failException.getClass() +
"\nbut an exception of type " +
targetException.getClass() + " is excepted.";
throw new TestException(message);
}
if ((failException.getMessage().equals
(targetException.getMessage())) == false) {
String message = "Assertion #3 has failed.\n" +
"Throwable encapsulated by the RenewalFailureEvent is" +
" of type " + failException.getClass() +
"\nas expected but the instances are different.";
throw new TestException(message);
}
logger.log(Level.FINE, "Assertion #3 passed.");
/* ASSERTION #4
The lease whose renewal failed should have been removed
from the renewal set. */
Lease managedLease = set.remove(failLease);
if (managedLease != null) {
String message = "Assertion #4 failed.\n" +
"Failed lease was never removed from renewal set.";
throw new TestException(message);
}
logger.log(Level.FINE, "Assertion #4 passed.");
}