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 three sample entries into the space
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
/*
* takeIfExists 1-st entry from the space using snapshot of
* the same one as a template within the transaction
*/
msg = testTemplate(sampleEntry1, txn, Long.MAX_VALUE, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// write taken entry back to the space
space.write(sampleEntry1, txn, leaseForeverTime);
/*
* takeIfExists sample entry from the space using snapshots of
* different wrong template entries within the transaction
*/
template = new SimpleEntry("TestEntry #3", 1);
msg = testWrongTemplate(template, txn, checkTime, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 2-nd wrong template
template = new SimpleEntry("TestEntry #1", 3);
msg = testWrongTemplate(template, txn, timeout1, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 3-rd wrong template
template = new SimpleEntry("TestEntry #3", 3);
msg = testWrongTemplate(template, txn, timeout2, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 4-th wrong template
template = new SimpleEntry(null, 3);
msg = testWrongTemplate(template, txn, checkTime, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 5-th wrong template
template = new SimpleEntry("TestEntry #3", null);
msg = testWrongTemplate(template, txn, timeout2, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
/*
* takeIfExists entry from the space using snapshot of null
* as a template within the transaction
*/
msg = testTemplate(null, txn, checkTime, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// clean the space and write 3 entries again
cleanSpace(space, txn);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
/*
* takeIfExists sample entries from the space using snapshots of
* templates with null as a wildcard for different fields
* within the transaction
*/
template = new SimpleEntry("TestEntry #1", null);
msg = testTemplate(template, txn, checkTime, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// clean the space and write 3 entries again
cleanSpace(space, txn);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
// try 2-nd template
template = new SimpleEntry(null, 2);
msg = testTemplate(template, txn, timeout1, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// clean the space and write 3 entries again
cleanSpace(space, txn);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
// 3-rd template
template = new SimpleEntry(null, null);
msg = testTemplate(template, txn, timeout2, 0, 0, true);
if (msg != null) {
throw new TestException(msg);
}
}