public void run() throws Exception {
EventMailbox mb = getConfiguredMailbox();
int i = 0;
// Register and check lease
MailboxRegistration mr = getRegistration(mb, DURATION1);
Lease mrl = getMailboxLease(mr);
checkLease(mrl, DURATION1);
logger.log(Level.INFO, "Mailbox lease good until"
+ new Date(mrl.getExpiration()));
// Get the mailbox service provided listener
RemoteEventListener mbRel = getMailboxListener(mr);
// Create an event generator and pass it the
// mailbox's remote event listener.
TestGenerator myGen = TestUtils.createGenerator(manager);
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);
// Create two listener objects
TestListener myListener = TestUtils.createListener(manager);
int eventCount = 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),
};
// Enable the first of our listener objects
assertCount(myListener, eventCount);
logger.log(Level.INFO, "Enabling delivery to our REL" + myListener);
mr.enableDelivery(myListener);
logger.log(Level.INFO, "Wating for event delivery");
eventCount = NUM_EVENTS;
waitForEvents(myListener, eventCount, MAX_WAIT);
logger.log(Level.INFO, "Verifying event delivery count of " + eventCount);
assertCount(myListener, eventCount);
logger.log(Level.INFO, "Verifying events ");
assertEvents(myListener, events);
if(myListener.verifyEvents(bogus)) {
throw new TestException("Successfully verified bogus events");
}
// Delay to ensure that we sleep past the
// lease expiration.
logger.log(Level.INFO, "Sleeping for " + DURATION1);
try {
Thread.sleep(DURATION1);
} catch (InterruptedException ie) {
logger.log(Level.INFO, "Sleep interrupted");
}
logger.log(Level.INFO, "Waking up at " + new Date(getTime()));
logger.log(Level.INFO, "Generating " + NUM_EVENTS + " more events");
try {
for (i = 0; i < NUM_EVENTS; i++) {
events[i] = myGen.generateEvent(evtReg.getID(), 3);
}
} catch (ServerException se) {
if (se.detail != null &&
se.detail instanceof NoSuchObjectException) {
// can safely ignore this since we expect
// that the registration has expired.
logger.log(Level.INFO, "Caught NoSuchObjectException - expected");
} else { throw se; }
}
logger.log(Level.INFO, "Asserting that the event count hasn't changed");
assertCount(myListener, eventCount);
try {
logger.log(Level.INFO, "Re-enabling delivery to our REL" + myListener);
mr.enableDelivery(myListener);
throw new TestException("Successfully re-enabled an expired registration");
} catch (NoSuchObjectException nsoe) {
logger.log(Level.INFO, "Caught NoSuchObjectException - expected");
}