lrm.renewFor(prepareLease(set.getRenewalSetLease()), renewSetDur, null);
// create 2 unreadable test leases to be managed
logger.log(Level.FINE, "Creating an unreadable lease to be managed.");
logger.log(Level.FINE, "Duration == Lease.FOREVER");
TestLease specialLease01 =
unreadableLeaseProvider.createNewLease(leaseOwner,
Lease.FOREVER);
logger.log(Level.FINE, "Creating an unreadable lease to be managed.");
logger.log(Level.FINE, "Duration == Lease.FOREVER");
TestLease specialLease02 =
unreadableLeaseProvider.createNewLease(leaseOwner,
Lease.FOREVER);
// start managing the unreadable leases forever
logger.log(Level.FINE, "Adding unreadable lease with membership of " +
"Lease.FOREVER");
set.renewFor(specialLease01, Lease.FOREVER);
logger.log(Level.FINE, "Adding unreadable lease with membership of " +
"Lease.FOREVER");
set.renewFor(specialLease02, Lease.FOREVER);
/* Assert that a LeaseUnmarshalException is thrown when getLeases()
is called */
try {
UnreadableTestLease.setFailMode(true);
Lease[] leaseArray = set.getLeases();
UnreadableTestLease.setFailMode(false);
/* here we have succeeded to getLeases so something went
frightfully wrong */
String message =
"The getLeases() method succeeded but should\n" +
"have thrown a LeaseUnMarshalException.";
throw new TestException(message);
} catch (LeaseUnmarshalException ex) {
// set failure mode
UnreadableTestLease.setFailMode(false);
/* assert that the getLeases has exactly the
0 leases. */
Lease[] goodLeases = ex.getLeases();
if (goodLeases.length != 0) {
String message = "The getLeases method returned " +
goodLeases.length + " leases.\n" + "We were" +
" expecting 0.";
throw new TestException(message);
}
/* assert that the getMarshalledLeases has exactly the
2 leases we are expecting. */
MarshalledObject[] badLeases = ex.getMarshalledLeases();
if (badLeases.length != 2) {
String message = "The getLeases method returned " +
badLeases.length + " marshalled objects.\n" +
"We were expecting 2.";
throw new TestException(message);
}
// are they the two that we expect??
if (rstUtil.indexOfLease(specialLease01, badLeases) == -1) {
String message = "StillMarshalled array is missing" +
" special lease #1";
throw new TestException(message);
}
if (rstUtil.indexOfLease(specialLease02, badLeases) == -1) {
String message = "StillMarshalled array is missing" +
" special lease #2";
throw new TestException(message);
}
/* assert that the getExceptions has exactly the
2 two we are expecting. */
Throwable[] exception = ex.getExceptions();
if (exception.length != 2) {
String message = "The getExceptions method returned " +
exception.length + " exceptions.\n" +
"We were expecting 2.";
throw new TestException(message);
}
/* the exceptions have the lease id embedded so we can
check which exception goes with which lease */
int[] exceptionID = new int[exception.length];
for (int i = 0; i < exception.length; ++i) {
String eMessage = exception[i].getMessage();
StringTokenizer sTok =
new StringTokenizer(eMessage, "=");
sTok.nextToken(); // skip leading text
String idStr = sTok.nextToken().trim();
exceptionID[i] = Integer.parseInt(idStr);
}
// assert that the ids of the exceptions and leases match
int leaseIndex =
rstUtil.indexOfLease(specialLease01, badLeases);
if (exceptionID[leaseIndex] != specialLease01.id()) {
String message = "The order of the leases in the\n" +
"bad leases array does not correspond to the\n" +
"order of the exceptions in the exceptions array.";
throw new TestException(message);
}
leaseIndex = rstUtil.indexOfLease(specialLease02, badLeases);
if (exceptionID[leaseIndex] != specialLease02.id()) {
String message = "The order of the leases in the\n" +
"bad leases array does not correspond to the\n" +
"order of the exceptions in the exceptions array.";
throw new TestException(message);
}