JavaSpace05 space05 = (JavaSpace05) space;
reset(txn);
TestEventListener05 testEventListener0 = new TestEventListener05();
templates.add((SimpleEntry) sampleEntry1.clone());
EventRegistration er0 = space05.registerForAvailabilityEvent(templates,
txn, true, testEventListener0, leaseForeverTime,
new MarshalledObject("notUsedHere"));
final long gotER0Timestamp = System.currentTimeMillis();
List notifications = testEventListener0.getNotifications();
expectedResult.add(sampleEntry1); // this entry is to trigger the event
space.write(sampleEntry1, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing one entry to trigger an event");
registrations.add(er0);
reset(txn);
TestEventListener05 testEventListener1 = new TestEventListener05();
templates.add((SimpleEntry) sampleEntry1.clone());
templates.add((SimpleEntry) sampleEntry2.clone());
EventRegistration er1 = space05.registerForAvailabilityEvent(templates,
txn, true, testEventListener1, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener1.getNotifications();
expectedResult.add(sampleEntry1);
expectedResult.add(sampleEntry2);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 entries to trigger 2 events");
registrations.add(er1);
reset(txn);
TestEventListener05 testEventListener2 = new TestEventListener05();
templates.add(new SimpleEntry(null, 2));
EventRegistration er2 = space05.registerForAvailabilityEvent(templates,
txn, true, testEventListener2, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener2.getNotifications();
expectedResult.add(sampleEntry2);
expectedResult.add(sampleEntry3);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 entries to trigger 2 events "
+ "(with single template)");
registrations.add(er2);
reset(txn);
TestEventListener05 testEventListener3 = new TestEventListener05();
templates.add(new SimpleEntry(null, null));
EventRegistration er3 = space05.registerForAvailabilityEvent(templates,
txn, true, testEventListener3, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener3.getNotifications();
expectedResult.add(sampleEntry1);
expectedResult.add(sampleEntry2);
expectedResult.add(sampleEntry3);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 3 entries to trigger 3 events "
+ "(with single template)");
registrations.add(er3);
reset(txn);
TestEventListener05 testEventListener4 = new TestEventListener05();
templates.add(null);
EventRegistration er4 = space05.registerForAvailabilityEvent(templates,
txn, true, testEventListener4, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener4.getNotifications();
expectedResult.add(sampleEntry1);
expectedResult.add(sampleEntry2);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 entries to trigger 2 events "
+ "(with null template)");
registrations.add(er4);
reset(txn);
TestEventListener05 testEventListener5 = new TestEventListener05();
templates.add(null);
EventRegistration er5 = space05.registerForAvailabilityEvent(templates,
txn, true, testEventListener5, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener5.getNotifications();
expectedResult.add(sampleEntry1);
expectedResult.add(sampleEntry1);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry1, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 duplicate entries to trigger 2 events "
+ "(with null template)");
/*
* not adding this as a registration for such set
* of templates (null) already exists
*/
//registrations.add(er5);
reset(txn);
TestEventListener05 testEventListener6 = new TestEventListener05();
templates.add(null);
templates.add(new SimpleEntry(null, null));
templates.add((SimpleEntry) sampleEntry2.clone());
templates.add((SimpleEntry) sampleEntry3.clone());
templates.add(new SimpleEntry(null, 2));
EventRegistration er6 = space05.registerForAvailabilityEvent(templates,
txn, true, testEventListener6, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener6.getNotifications();
expectedResult.add(sampleEntry2);
expectedResult.add(sampleEntry3);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 entries to trigger 2 events " +
"(with multiple matching templates)");
registrations.add(er6);
reset(txn);
/*
* Section below is the same as above but
* with visibilityOnly flag set to false.
* "a" stands for availability.
*/
TestEventListener05 testEventListener0a = new TestEventListener05();
templates.add((SimpleEntry) sampleEntry1.clone());
EventRegistration er0a = space05.registerForAvailabilityEvent(
templates, txn, false,
testEventListener0a, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener0a.getNotifications();
expectedResult.add(sampleEntry1); // this entry is to trigger the event
space.write(sampleEntry1, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing one entry to trigger an event");
registrations.add(er0a);
reset(txn);
TestEventListener05 testEventListener1a = new TestEventListener05();
templates.add((SimpleEntry) sampleEntry1.clone());
templates.add((SimpleEntry) sampleEntry2.clone());
EventRegistration er1a = space05.registerForAvailabilityEvent(
templates, txn, false,
testEventListener1a, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener1a.getNotifications();
expectedResult.add(sampleEntry1);
expectedResult.add(sampleEntry2);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 entries to trigger 2 events");
registrations.add(er1a);
reset(txn);
TestEventListener05 testEventListener2a = new TestEventListener05();
templates.add(new SimpleEntry(null, 2));
EventRegistration er2a = space05.registerForAvailabilityEvent(
templates, txn, false,
testEventListener2a, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener2a.getNotifications();
expectedResult.add(sampleEntry2);
expectedResult.add(sampleEntry3);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 entries to trigger 2 events "
+ "(with single template)");
registrations.add(er2a);
reset(txn);
TestEventListener05 testEventListener3a = new TestEventListener05();
templates.add(new SimpleEntry(null, null));
EventRegistration er3a = space05.registerForAvailabilityEvent(
templates, txn, false,
testEventListener3a, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener3a.getNotifications();
expectedResult.add(sampleEntry1);
expectedResult.add(sampleEntry2);
expectedResult.add(sampleEntry3);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 3 entries to trigger 3 events "
+ "(with single template)");
registrations.add(er3a);
reset(txn);
TestEventListener05 testEventListener4a = new TestEventListener05();
templates.add(null);
EventRegistration er4a = space05.registerForAvailabilityEvent(
templates, txn, false,
testEventListener4a, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener4a.getNotifications();
expectedResult.add(sampleEntry1);
expectedResult.add(sampleEntry2);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry2, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 entries to trigger 2 events "
+ "(with null template)");
registrations.add(er4a);
reset(txn);
TestEventListener05 testEventListener5a = new TestEventListener05();
templates.add(null);
EventRegistration er5a = space05.registerForAvailabilityEvent(
templates, txn, false,
testEventListener5a, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener5a.getNotifications();
expectedResult.add(sampleEntry1);
expectedResult.add(sampleEntry1);
space.write(sampleEntry1, txn, leaseForeverTime);
space.write(sampleEntry1, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 duplicate entries to trigger 2 events "
+ "(with null template)");
/*
* not adding this as a registration for such set
* of templates (null) already exists
*/
//registrations.add(er5a);
reset(txn);
TestEventListener05 testEventListener6a = new TestEventListener05();
templates.add(null);
templates.add(new SimpleEntry(null, null));
templates.add((SimpleEntry) sampleEntry2.clone());
templates.add((SimpleEntry) sampleEntry3.clone());
templates.add(new SimpleEntry(null, 2));
EventRegistration er6a = space05.registerForAvailabilityEvent(
templates, txn, false,
testEventListener6a, leaseForeverTime,
new MarshalledObject("notUsedHere"));
notifications = testEventListener6a.getNotifications();
expectedResult.add(sampleEntry2);
expectedResult.add(sampleEntry3);
space.write(sampleEntry2, txn, leaseForeverTime);
space.write(sampleEntry3, txn, leaseForeverTime);
Thread.sleep(waitingNotificationsToComeTime);
checkNotifications(notifications, expectedResult,
"Writing 2 entries to trigger 2 events " +
"(with multiple matching templates)");
registrations.add(er6a);
reset(txn);
ArrayList eventIDs = new ArrayList();
Iterator registrationsItr = registrations.iterator();
while (registrationsItr.hasNext()) {
EventRegistration er = (EventRegistration) registrationsItr.next();
if (er == null) {
throw new TestException("Event registration is null");
}
Long id = new Long(er.getID());
if (eventIDs.contains(id)) {
throw new TestException("Event registrations have"
+ " identical IDs");
}
eventIDs.add(id);