// create a 2 leases that will fail on renewal
long renewGrant = renewSetDur * 5 / 10;
logger.log(Level.FINE, "Creating failing lease #1 with duration of " +
renewGrant + " milliseconds.");
TestLease lease01 =
leaseProvider.createNewLease(failingOwner,
rstUtil.durToExp(renewGrant));
logger.log(Level.FINE, "Creating failing lease # 2 with duration of " +
renewGrant + " milliseconds.");
TestLease lease02 =
leaseProvider.createNewLease(failingOwner,
rstUtil.durToExp(renewGrant));
// add lease01 to set01 and lease02 to set02
logger.log(Level.FINE, "Adding lease #1 to set #1");
set01.renewFor(lease01, Long.MAX_VALUE);
logger.log(Level.FINE, "Adding lease #2 to set #2");
set02.renewFor(lease02, Long.MAX_VALUE);
/* wait for the expiration warning events to arrive.
By the time they do, all RenewalFailureEvents should also
have arrived. */
rstUtil.waitForRemoteEvents(normalListener01, 1, renewSetDur);
rstUtil.waitForRemoteEvents(failingListener01, 1, renewSetDur);
// Assert that we had one call each on the failing listeners
RemoteEvent[] events01 = failingListener01.getEvents();
RemoteEvent[] events02 = failingListener02.getEvents();
if (events01.length != 1) {
String message = "Failing Listener #1 received " +
events01.length + " events but is required to\n" +
"receive exactly 1.";
throw new TestException(message);
}
if (events02.length != 1) {
String message = "Failing Listener #2 received " +
events02.length + " events but is required to\n" +
"receive exactly 1.";
throw new TestException(message);
}
// Assert that we had one call each on the normal listeners
events01 = normalListener01.getEvents();
events02 = normalListener02.getEvents();
if (events01.length != 1) {
String message = "Normal Listener #1 received " +
events01.length + " events but is required to\n" +
"receive exactly 1.";
throw new TestException(message);
}
if (events02.length != 1) {
String message = "Normal Listener #2 received " +
events02.length + " events but is required to\n" +
"receive exactly 1.";
throw new TestException(message);
}
// Assert we can renew both set's leases without error
renewSetDur = renewSetDur * 6 / 10; // use a shorter time
try {
logger.log(Level.FINE, "Renewing set #1's lease with duration " +
"of " + renewSetDur + " milliseconds.");
prepareLease(set01.getRenewalSetLease()).renew(renewSetDur);
} catch (UnknownLeaseException ex) {
String message = "Attempt to renew lease for renewal set\n" +
"#1 has failed due to " + ex;
throw new TestException(message, ex);
}
try {
logger.log(Level.FINE, "Renewing set #2's lease with duration " +
"of " + renewSetDur + " milliseconds.");
prepareLease(set02.getRenewalSetLease()).renew(renewSetDur);
} catch (UnknownLeaseException ex) {
String message = "Attempt to renew lease for renewal set\n" +
"#2 has failed due to " + ex;
throw new TestException(message, ex);
}
/* Assert that calls to remove do not result in a
NoSuchObjectException. Given the renewal of the leases
above this assertion is probably somewhat redundant. */
try {
Lease managedLease = set01.remove(lease01);
} catch (NoSuchObjectException ex) {
String message = "Attempt to call remove on set\n" +
"#1 has failed due to a NoSuchObjectException";
throw new TestException(message, ex);
}
try {
Lease managedLease = set02.remove(lease02);
} catch (NoSuchObjectException ex) {
String message = "Attempt to call remove on set\n" +
"#2 has failed due to a NoSuchObjectException";
throw new TestException(message, ex);
}
// Restore both sets to original configurations
renewGrant = renewSetDur * 3 / 10;
logger.log(Level.FINE, "Creating failing lease #3 with duration of " +
renewGrant + " milliseconds.");
TestLease lease03 =
leaseProvider.createNewLease(failingOwner,
rstUtil.durToExp(renewGrant));
logger.log(Level.FINE, "Adding lease #3 to set #1");
set01.renewFor(lease03, Long.MAX_VALUE);
logger.log(Level.FINE, "Creating failing lease #4 with duration of " +
renewGrant + " milliseconds.");
TestLease lease04 =
leaseProvider.createNewLease(failingOwner,
rstUtil.durToExp(renewGrant));
logger.log(Level.FINE, "Adding lease #4 to set #2");
set02.renewFor(lease04, Long.MAX_VALUE);