long expirTime1;
long expirTime2;
long leaseTime1 = timeout1;
long leaseTime2 = timeout2;
long leaseTime3 = leaseTime1 + checkTime;
Lease lease1 = null;
Lease lease2 = null;
Transaction txn;
// first check that space is empty
if (!checkSpace(space)) {
throw new TestException(
"Space is not empty in the beginning.");
}
// create snapshots
snapshot1 = space.snapshot(sampleEntry1);
snapshot2 = space.snapshot(sampleEntry2);
// create the non null transaction
txn = getTransaction();
/*
* write an entry with Lease.ANY lease time using it's template
* within the transaction
*/
lease1 = space.write(snapshot1, txn, Lease.ANY);
curTime1 = System.currentTimeMillis();
/*
* check that returned lease is not equal to null,
* expiration time is not less then current time
*/
if (lease1 == null) {
throw new TestException(
"performed write with Lease.ANY lease time within the"
+ " non null transaction, expected result is non null"
+ " lease but null has been returned.");
}
expirTime1 = lease1.getExpiration();
if (expirTime1 < curTime1) {
throw new TestException(
"performed write of " + sampleEntry1
+ " with Lease.ANY lease time using it's snapshot"
+ " within the non null transaction, expected"
+ " expiration time is greater then current time "
+ curTime1 + " but returned value is " + expirTime1);
}
logDebugText("Write operation of " + sampleEntry1
+ " with Lease.ANY value for lease time using it's snapshot"
+ " within the transaction works as expected.");
// clean the space within the transaction
cleanSpace(space, txn);
/*
* write an entry with Lease.FOREVER lease time using it's snapshot
* within the transaction
*/
lease1 = space.write(snapshot1, txn, Lease.FOREVER);
curTime1 = System.currentTimeMillis();
/*
* check that returned lease is not equal to null,
* expiration time is not less then current time
*/
if (lease1 == null) {
throw new TestException(
"performed write with Lease.FOREVER lease time within"
+ " the non null transaction, expected result is non"
+ " null lease but null has been returned.");
}
expirTime1 = lease1.getExpiration();
if (expirTime1 < curTime1) {
throw new TestException(
"performed write of " + sampleEntry1
+ " with Lease.FOREVER lease time using it's snapshot"
+ " within the non null transaction, expected"
+ " expiration time is greater then current time "
+ curTime1 + " but returned value is " + expirTime1);
}
logDebugText("Write operation of " + sampleEntry1
+ " with Lease.FOREVER value for lease time using it's"
+ " snapshot within the non null transaction works"
+ " as expected.");
// clean the space
cleanSpace(space, txn);
/*
* write two sample entries with different finite lease times
* using their snapshots into the space within the transaction.
*/
lease1 = space.write(snapshot1, txn, leaseTime1);
curTime1 = System.currentTimeMillis();
expirTime1 = lease1.getExpiration();
lease2 = space.write(snapshot2, txn, leaseTime2);
curTime2 = System.currentTimeMillis();
expirTime2 = lease2.getExpiration();
// check that returned leases are not equal to null
if (lease1 == null) {
throw new TestException(
"performed write of " + sampleEntry1 + " with "
+ leaseTime1 + " lease time using it's snapshot"
+ " within the non null transaction returned null"
+ " lease.");
}
if (lease2 == null) {
throw new TestException(
"performed write of " + sampleEntry2 + " with "
+ leaseTime2 + " lease time using it's snapshot"
+ " within the non null transaction returned null"
+ " lease.");
}
// check that write operations return required expiration times
if (((expirTime1 - curTime1) > leaseTime1)
|| (expirTime1 - curTime1) < (leaseTime1 - instantTime)) {
throw new TestException(
"performed write of " + sampleEntry1 + " with "
+ leaseTime1 + " lease time uting it's snapshot"
+ " within the non null transaction."
+ " Expected conditions are not satisfied: "
+ leaseTime1 + "(specified lease time) <= ("
+ expirTime1 + "(returned expiration time) - "
+ curTime1 + "(current time)) >= (" + leaseTime1
+ "(specified lease time) + " + instantTime + ").");
}
if (((expirTime2 - curTime2) > leaseTime2)
|| (expirTime2 - curTime2) < (leaseTime2 - instantTime)) {
throw new TestException(
"performed write of " + sampleEntry2 + " with "
+ leaseTime2 + " lease time uting it's snapshot"
+ " within the non null transaction."
+ " Expected conditions are not satisfied: "
+ leaseTime2 + "(specified lease time) <= ("
+ expirTime2 + "(returned expiration time) - "
+ curTime2 + "(current time)) >= (" + leaseTime2
+ "(specified lease time) + " + instantTime + ").");
}
logDebugText("Write operations within the non null tranasction of "
+ sampleEntry1 + " with " + leaseTime1 + " lease time and\n"
+ sampleEntry2 + " with " + leaseTime2
+ " lease time using their snapshots work as expected.");
/*
* write 1-st sample entry with another finite lease time
* using it's snapshot to the space within the transaction again
*/
lease1 = space.write(snapshot1, txn, leaseTime3);
curTime1 = System.currentTimeMillis();
expirTime1 = lease1.getExpiration();
// check that returned leases are not equal to null
if (lease1 == null) {
throw new TestException(
"performed 2-nd write of " + sampleEntry1 + " with "
+ leaseTime3 + " lease time using it's snapshot"
+ " within the non null tranasaction returned null"
+ " result.");
}
// check that write operations return required expiration times
if (((expirTime1 - curTime1) > leaseTime3)
|| (expirTime1 - curTime1) < (leaseTime3 - instantTime)) {
throw new TestException(
"performed 2-nd write of " + sampleEntry1 + " with "
+ leaseTime3 + " lease time using it's snapshot"
+ " within the non null transaction."
+ " Expected conditions are not satisfied: "
+ leaseTime3 + "(specified lease time) <= ("
+ expirTime1 + "(returned expiration time) - "
+ curTime1 + "(current time)) >= (" + leaseTime3
+ "(specified lease time) + " + instantTime + ").");
}
logDebugText("2-nd write operation of " + sampleEntry1 + " with "
+ leaseTime3 + " lease time within the non null transaction"
+ " works as expected.");
/*
* write 2-nd sample entry with Lease.ANY value for lease time
* to the space using it's snapshot within the transaction again
*/
lease2 = space.write(snapshot2, txn, Lease.ANY);
curTime2 = System.currentTimeMillis();
expirTime2 = lease2.getExpiration();
// check that returned leases are not equal to null
if (lease2 == null) {
throw new TestException(
"performed 2-nd write of " + sampleEntry2