* MatchSet.next() method
*/
JavaSpace05 space05 = (JavaSpace05) space;
templates.add(sampleEntry1);
txn = getTransaction();
MatchSet matchSet = space05.contents(templates, txn, Lease.ANY,
MAX_ENTRIES);
if (matchSet.next() == null) {
throw new TestException(
"Match set is exhausted. But it shouldn't be.");
}
// -- now it is supposed to be exhausted
if (matchSet.next() != null) {
throw new TestException(
"Match set was not exhausted. But should have been.");
}
space.write(sampleEntry1, txn, leaseForeverTime);
Thread.sleep(1000);
if (matchSet.next() != null) {
throw new TestException("An entry added to exhausted match set. "
+ "But must not have been.");
}
txn.commit();
reset();
/*
* After maxEntries entries are yielded by next invocations the match
* set becomes empty. For this test case let maxEntries = 2
*/
templates.add(null); // for 3 existing entries
txn = getTransaction();
matchSet = space05.contents(templates, txn, Lease.ANY, 2);
matchSet.next();
matchSet.next();
if (matchSet.next() != null) {
throw new TestException("Match set is not empty after maxEntries "
+ "are yielded by next invocations");
}
txn.commit();
reset();
/*
* The initial duration of the lease must be less than or equal to
* leaseDuration. Let leaseDuration = instantTime.
*/
templates.add(null); // for 3 existing entries
txn = getTransaction();
matchSet = space05.contents(templates, txn, leaseForeverTime,
MAX_ENTRIES);
Lease lease = matchSet.getLease();
if (lease != null) {
long initialDuration = lease.getExpiration()
- System.currentTimeMillis();
if (initialDuration > leaseForeverTime) {
throw new TestException("Initial duration of the lease "
+ "is more than leaseDuration");
}
} // else Lease is not tested as the matchset is not leased
txn.commit();
reset();
//corresponds to item #6 in this method's comments
txn = getTransaction();
templates.add((SimpleEntry) sampleEntry1.clone());
matchSet = space05.contents(templates, txn, leaseForeverTime,
MAX_ENTRIES);
matchSet.next();
SimpleEntry entry = (SimpleEntry) space.take(
(SimpleEntry) sampleEntry1.clone(), null, instantTime);
if (entry != null) {
throw new TestException("Locked entry can be taken "
+ "from the space.");