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);
/*
* take 1-st entry from the space using the same one as a template
* with JavaSpace.NO_WAIT timeout within the transaction
*/
msg = testTemplate(sampleEntry1, txn, JavaSpace.NO_WAIT, 0, 0,
false);
if (msg != null) {
throw new TestException(msg);
}
// write taken entry back to the space
space.write(sampleEntry1, txn, leaseForeverTime);
/*
* take sample entry from the space using
* 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, 0,
false);
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, 0,
false);
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, 0,
false);
if (msg != null) {
throw new TestException(msg);
}
// 4-th wrong template
template = new SimpleEntry(null, 3);
msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0,
false);
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, 0,
false);
if (msg != null) {
throw new TestException(msg);
}
/*
* take entry from the space using null as a template
* and JavaSpace.NO_WAIT timeout within the transaction
*/
msg = testTemplate(null, txn, JavaSpace.NO_WAIT, 0, 0, false);
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);
/*
* take sample entries from the space using 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, 0, false);
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, JavaSpace.NO_WAIT, 0, 0, false);
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, JavaSpace.NO_WAIT, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// commit the transaction
txnCommit(txn);
}