// Get the mailbox service provided listener
RemoteEventListener mbRel = getPullMailboxListener(mr);
// Create an event generator and pass it the
// mailbox's remote event listener.
TestGenerator myGen = TestUtils.createGenerator(manager);
logger.log(Level.FINEST,
"Test generator class tree"
+ getClassLoaderTree(myGen.getClass().getClassLoader()));
EventRegistration evtReg =
myGen.register(EVENT_ID, // Event ID to use
null, // handback
mbRel, // Notification target
DURATION1); // Lease duration
Lease tgl = evtReg.getLease();
checkLease(tgl, DURATION1);
TestListener goodListener = TestUtils.createListener(manager);
int goodCount = 0;
int goodPullCount = 0;
// Generate some events
logger.log(Level.INFO, "Generating " + NUM_EVENTS + " events");
RemoteEvent[] events = new RemoteEvent[NUM_EVENTS];
for (i = 0; i < NUM_EVENTS; i++) {
events[i] = myGen.generateEvent(evtReg.getID(), 3);
}
RemoteEvent[] bogus = {
new RemoteEvent(myGen, 9999, 9999, null),
new RemoteEvent(myGen, 5678, 1234, null),
};
//
// Kill event mailbox service
//
logger.log(Level.INFO, "Killing mailbox service ...");
shutdown(0);
// Enable good listener
logger.log(Level.INFO, "Enabling good listener");
mr.enableDelivery(goodListener);
goodCount = NUM_EVENTS;
logger.log(Level.INFO, "Wating for event delivery of " + goodCount);
waitForEvents(goodListener, goodCount, MAX_WAIT);
logger.log(Level.INFO, "Asserting event count");
assertCount(goodListener, goodCount);
logger.log(Level.INFO, "Verifying events");
assertEvents(goodListener, events);
//
// Kill event mailbox service
//
shutdown(0);
// Should now be using recovered listener with
// recovered preparer
logger.log(Level.INFO, "Generating another event");
RemoteEvent re = myGen.generateEvent(evtReg.getID(), 3);
goodCount++;
logger.log(Level.INFO, "Wating for event delivery" + goodCount);
waitForEvents(goodListener, goodCount, MAX_WAIT);
logger.log(Level.INFO, "Asserting event count");
assertCount(goodListener, goodCount);
logger.log(Level.INFO, "Verifying events");
assertEvent(goodListener, re);
// Switch to pull interface -- should disable event listener
logger.log(Level.INFO, "Switching to pull listener -- not expecting any events.");
goodPullCount = 0;
RemoteEventIterator rei = mr.getRemoteEvents();
RemoteEvent rei_event = rei.next(MAX_WAIT);
if (rei_event != null) {
throw new TestException("Got event from empty iterator " + rei_event);
}
logger.log(Level.INFO, "Event iterator was empty -- OK");
//
// Kill event mailbox service
//
shutdown(0);
// Generate another event and verify that it isn't delivered
logger.log(Level.INFO, "Generating another event");
re = myGen.generateEvent(evtReg.getID(), 3);
// Don't bump goodCount because it shouldn't be delivered
logger.log(Level.INFO, "Wating for event delivery" + goodCount);
// Force delay by waiting for goodCount+1 -- should not get an event, though
waitForEvents(goodListener, goodCount+1, MAX_WAIT/NUM_EVENTS);
logger.log(Level.INFO, "Asserting event count");
assertCount(goodListener, goodCount);
//
// Kill event mailbox service
//
shutdown(0);
goodPullCount++;
logger.log(Level.INFO, "Getting events. Expecting " + goodPullCount);
rei_event = rei.next(MAX_WAIT/NUM_EVENTS);
if (rei_event == null ||
!new RemoteEventHandle(rei_event).equals(new RemoteEventHandle(re))) {
throw new TestException(
"Didn't get expected event from iterator: " + rei_event);
}
logger.log(Level.INFO, "Got expected event from iterator");
// Note checking for "empty" also forces the proxy the call the
// the service back to see if there are anymore events, which will
// also advance the read pointer past the last returned event. This
// will prevent the "push" listener from seeing an extra event later on.
rei_event = rei.next(MAX_WAIT/NUM_EVENTS);
if (rei_event != null) {
throw new TestException(
"Got unexpected event from empty iterator: " + rei_event);
}
logger.log(Level.INFO, "Verified iterator is empty");
// Re-enable good listener. Should invalidate the iterator.
logger.log(Level.INFO, "Re-enabling good listener");
mr.enableDelivery(goodListener);
logger.log(Level.INFO, "Trying to pull events from invalid iterator reference");
try {
rei.next(MAX_WAIT/NUM_EVENTS);
throw new TestException("Successfully called invalid iterator.");
} catch (InvalidIteratorException iie) {
logger.log(Level.INFO, "Caught expected IllegalIteratorException", iie);
}
//
// Kill event mailbox service
//
shutdown(0);
logger.log(Level.INFO, "Generating another event");
re = myGen.generateEvent(evtReg.getID(), 3);
goodCount++;
logger.log(Level.INFO, "Wating for event delivery" + goodCount);
waitForEvents(goodListener, goodCount, MAX_WAIT);
logger.log(Level.INFO, "Asserting event count");
assertCount(goodListener, goodCount);