*
* <P>Notes:<BR>For more information see the JavaSpaces specification
* sections 2.5, 2.6.</P>
*/
public void run() throws Exception {
SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
SimpleEntry template;
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 into the space
space.write(sampleEntry1, null, leaseForeverTime);
space.write(sampleEntry2, null, leaseForeverTime);
space.write(sampleEntry3, null, leaseForeverTime);
/*
* take 1-st entry from the space using snapshot of the same one
* as a template
*/
msg = testTemplate(sampleEntry1, null, Long.MAX_VALUE, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// write taken entry back to the space
space.write(sampleEntry1, null, leaseForeverTime);
/*
* take sample entry from the space using snapshots of
* different wrong template entries
*/
template = new SimpleEntry("TestEntry #3", 1);
msg = testWrongTemplate(template, null, checkTime, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// 2-nd wrong template
template = new SimpleEntry("TestEntry #1", 3);
msg = testWrongTemplate(template, null, timeout1, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// 3-rd wrong template
template = new SimpleEntry("TestEntry #3", 3);
msg = testWrongTemplate(template, null, timeout2, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// 4-th wrong template
template = new SimpleEntry(null, 3);
msg = testWrongTemplate(template, null, checkTime, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// 5-th wrong template
template = new SimpleEntry("TestEntry #3", null);
msg = testWrongTemplate(template, null, timeout2, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// take entry from the space using snapshot of null as a template
msg = testTemplate(null, null, timeout1, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// clean the space and write 3 entries again
cleanSpace(space);
space.write(sampleEntry1, null, leaseForeverTime);
space.write(sampleEntry2, null, leaseForeverTime);
space.write(sampleEntry3, null, leaseForeverTime);
/*
* take sample entries from the space using snapshot of templates
* with null as a wildcard for different fields
*/
template = new SimpleEntry("TestEntry #1", null);
msg = testTemplate(template, null, checkTime, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// clean the space and write 3 entries again
cleanSpace(space);
space.write(sampleEntry1, null, leaseForeverTime);
space.write(sampleEntry2, null, leaseForeverTime);
space.write(sampleEntry3, null, leaseForeverTime);
// try 2-nd template
template = new SimpleEntry(null, 2);
msg = testTemplate(template, null, timeout1, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}
// clean the space and write 3 entries again
cleanSpace(space);
space.write(sampleEntry1, null, leaseForeverTime);
space.write(sampleEntry2, null, leaseForeverTime);
space.write(sampleEntry3, null, leaseForeverTime);
// 3-rd template
template = new SimpleEntry(null, null);
msg = testTemplate(template, null, timeout2, 0, 0, false);
if (msg != null) {
throw new TestException(msg);
}