Transaction txn;
String msg;
// first check that space is empty
if (!checkSpace(space)) {
throw new TestException("Space is not empty in the beginning.");
}
// create the non null transaction
txn = getTransaction();
// write two sample entries twice to the space
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
/*
* take 1-st entry twice from the space using the same one as
* a template within the transaction
*/
for (int i = 1; i <= 2; i++) {
msg = testTemplate(sampleEntry1, txn, Long.MAX_VALUE, i, 2,
false);
if (msg != null) {
throw new TestException(msg);
}
}
// write taken entries to the space again
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry1, txn, leaseForeverTime);
// write 3-rd sample entry twice to the space
space.write(sampleEntry3, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
/*
* Take entry from the space using null as a template
* within the transaction 6 times to take all written
* entries from the space.
*/
for (int i = 1; i <= 6; i++) {
msg = testTemplate(null, txn, checkTime, i, 6, false);
if (msg != null) {
throw new TestException(msg);
}
}
// write all taken entries to the space again
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
/*
* Take entry from the space using template with 1-st null field
* within the transaction 4 times to take all matching written
* entries from the space.
*/
template = new SimpleEntry(null, 2);
for (int i = 1; i <= 4; i++) {
msg = testTemplate(template, txn, timeout1, i, 4, false);
if (msg != null) {
throw new TestException(msg);
}
}
// write taken entries back to the space
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
/*
* Take entry from the space using template with 2-nd null field
* within the transaction 4 times to take all matching written
* entries from the space.
*/
template = new SimpleEntry("TestEntry #1", null);
for (int i = 1; i <= 4; i++) {
msg = testTemplate(template, txn, timeout2, i, 4, false);
if (msg != null) {
throw new TestException(msg);
}
}
// write taken entries back to the space
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
/*
* Take entry from the space using template with both null fields
* within the transaction 6 times to take all matching written
* entries from the space.
*/
template = new SimpleEntry(null, null);
for (int i = 1; i <= 6; i++) {
msg = testTemplate(template, txn, checkTime, i, 6, false);
if (msg != null) {
throw new TestException(msg);
}
}
// commit the transaction
txnCommit(txn);