leases[i] = getTransactionManagerLease(mbrs[i]);
checkLease(leases[i], DURATION);
}
logger.log(Level.INFO, "Generating LeaseMap to manage all leases");
LeaseMap lm = leases[0].createLeaseMap(DURATION);
for (i = 1; i < numRegs; i++) {
if (lm.canContainKey(leases[i])) {
lm.put(leases[i], new Long(DURATION));
} else {
throw new TestException( "Could not add valid lease to LeaseMap");
}
}
logger.log(Level.INFO, "Renewing all leases");
try {
lm.renewAll();
} catch (Exception e) {
throw new TestException( "Caught unexpected exception: " + e);
}
logger.log(Level.INFO, "Cancelling even numbered leases");
int cancelCount = 0;
for (i = 0; i < numRegs; i++) {
try {
if ((i % 2) == 0) {
leases[i].cancel();
cancelCount++;
}
} catch (Exception e) {
throw new TestException( "Caught unexpected excetion: " + e);
}
}
logger.log(Level.INFO, "Renewing all leases");
try {
lm.renewAll();
throw new TestException( "Successfully renewed non-existent lease");
} catch (LeaseMapException lme) {
if (lme.exceptionMap.size() != cancelCount) {
dumpLeaseMapException(lme);
throw new TestException( "Received unexpected number of "
+ "exceptions upon renewal");
} else {
logger.log(Level.INFO, "Received expected number of "
+ "renewal exceptions");
}
}
// Note that the LeaseMap will REMOVE the Leases that failed to
// to renew from the Map. We are working with a subset now.
logger.log(Level.INFO, "Cancelling another lease");
leases[1].cancel();
cancelCount = 1;
logger.log(Level.INFO, "Cancelling remaining leases");
try {
logger.log(Level.INFO,
"Note: Expect cancelAll() to produce an exception trace "
+ "for the generated LeaseMapException");
lm.cancelAll();
throw new TestException("Successfully cancelled non-existent"
+ "lease");
} catch (LeaseMapException lme) {
if (lme.exceptionMap.size() != cancelCount) {
dumpLeaseMapException(lme);