Transaction txn;
String msg;
// first check that space is empty
if (!checkSpace(space)) {
throw new TestException("Space is not empty in the beginning.");
}
// write three sample entries twice to the space
space.write(sampleEntry1, null, leaseForeverTime);
space.write(sampleEntry1, null, leaseForeverTime);
space.write(sampleEntry2, null, leaseForeverTime);
space.write(sampleEntry2, null, leaseForeverTime);
space.write(sampleEntry3, null, leaseForeverTime);
space.write(sampleEntry3, null, leaseForeverTime);
// create the non null transaction
txn = getTransaction();
/*
* readIfExists 1-st entry from the space using snapshot of
* the same one as a template with JavaSpace.NO_WAIT timeout
* within the transaction
*/
msg = testTemplate(sampleEntry1, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
/*
* readIfExists sample entry from the space using snapshots of
* wrong template entries and JavaSpace.NO_WAIT timeout
* within the transaction
*/
template = new SimpleEntry("TestEntry #3", 1);
msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 2-nd wrong template
template = new SimpleEntry("TestEntry #1", 3);
msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 3-rd wrong template
template = new SimpleEntry("TestEntry #3", 3);
msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 4-th wrong template
template = new SimpleEntry(null, 3);
msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 5-th wrong template
template = new SimpleEntry("TestEntry #3", null);
msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
/*
* readIfExists entry from the space using snapshot of null as a
* template and JavaSpace.NO_WAIT timeout within the transaction
*/
msg = testTemplate(null, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
/*
* readIfExists sample entries from the space using snapshots of
* templates with null as a wildcard for different fields
* and JavaSpace.NO_WAIT timeout within the transaction
*/
template = new SimpleEntry("TestEntry #1", null);
msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// try 2-nd template
template = new SimpleEntry(null, 2);
msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// 3-rd template
template = new SimpleEntry(null, null);
msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);
if (msg != null) {
throw new TestException(msg);
}
// commit the transaction
txnCommit(txn);
}