set.renewFor(testLease, 0);
// success, keep on trucking ...
} catch (IllegalArgumentException ex) {
String message = "An attempt to add a client lease\n";
message += " with a 0 membership duration has failed.";
throw new TestException(message, ex);
}
/* assert that using a membership duration of -99 (negative test)
does NOT generate an IllegalArgumentException */
try {
set.renewFor(testLease, -99);
// success, keep on trucking ...
} catch (IllegalArgumentException ex) {
String message = "An attempt to add a client lease\n";
message += "with a negative membership duration has ";
message += "failed.";
throw new TestException(message, ex);
}
// trying to remove the lease should result in null value
Lease managedLease = set.remove(testLease);
if (managedLease != null) {
String message = "Lease was added to renewal set in error\n";
message += "from a call to renewFor with 0 membership.";
throw new TestException(message);
}
/* assert that using a membership duration of Lease.ANY
does NOT generate an IllegalArgumentException */
try {
set.renewFor(testLease, Lease.ANY);
set.remove(testLease);
// success, keep on trucking ...
} catch (IllegalArgumentException ex) {
String message = "An attempt to add a client lease\n";
message += "with a Lease.ANY membership duration\n";
message += "has failed with an IllegalArgumentException.";
throw new TestException(message, ex);
}
/* assert that using a membership duration of Lease.FOREVER
does NOT generate an IllegalArgumentException */
try {
set.renewFor(testLease, Lease.FOREVER);
set.remove(testLease);
// success, keep on trucking ...
} catch (IllegalArgumentException ex) {
String message = "An attempt to add a client lease\n";
message += "with a Lease.FOREVER membership duration\n";
message += "has failed with an IllegalArgumentException.";
throw new TestException(message, ex);
}
/* assert that using a membership duration of Long.MAX_VALUE
does NOT generate an IllegalArgumentException */
try {
set.renewFor(testLease, Long.MAX_VALUE);
set.remove(testLease);
// success, keep on trucking ...
} catch (IllegalArgumentException ex) {
String message = "An attempt to add a client lease\n";
message += "with a Long.MAX_VALUE membership duration\n";
message += "has failed with an IllegalArgumentException.";
throw new TestException(message, ex);
}
/* assert that using a membership duration of 1 (edge case)
does NOT generate an IllegalArgumentException */
try {
set.renewFor(testLease, 1);
set.remove(testLease);
// success, keep on trucking ...
} catch (IllegalArgumentException ex) {
String message = "An attempt to add a client lease\n";
message += "with a 1 millisecond membership duration\n";
message += "has failed with an IllegalArgumentException.";
throw new TestException(message, ex);
}
/* assert that using a membership duration of 30000 (normal case)
does NOT generate an IllegalArgumentException */
try {
set.renewFor(testLease, 30000L);
set.remove(testLease);
// success, keep on trucking ...
} catch (IllegalArgumentException ex) {
String message = "An attempt to add a client lease\n";
message += "with a 30000 millisecond membership duration\n";
message += "has failed with an IllegalArgumentException.";
throw new TestException(message, ex);
}
}