PullEventMailbox mb = getPullMailbox();
int i = 0;
// Register and check lease
MailboxPullRegistration mr = getPullRegistration(mb, DURATION1);
Lease mrl = getPullMailboxLease(mr);
checkLease(mrl, DURATION1);
// 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);
// Create another event generator and pass it the
// mailbox's remote event listener.
TestGenerator myGen2 = TestUtils.createGenerator(manager);
logger.log(Level.FINEST,
"Test generator class tree"
+ getClassLoaderTree(myGen2.getClass().getClassLoader()));
EventRegistration evtReg2 =
myGen2.register(EVENT_ID2, // Event ID to use
null, // handback
mbRel, // Notification target
DURATION1); // Lease duration
Lease tgl2 = evtReg2.getLease();
checkLease(tgl2, DURATION1);
// Get events and verify
logger.log(Level.INFO, "Getting events from empty mailbox.");
RemoteEventIterator rei = mr.getRemoteEvents();
RemoteEvent rei_event;
Date before = new Date();
logger.log(Level.INFO, "Calling next() on empty set @ {0}", before);
rei_event = rei.next(MAX_WAIT_GET_EVENT);
Date after = new Date();
logger.log(Level.INFO, "Returned from next() @ {0}", after);
//Verify that timeout was honored
long delta = after.getTime() - before.getTime();
if (delta < MAX_WAIT_GET_EVENT) {
throw new TestException("Returned from next() before expected: "
+ delta);
}
if (rei_event != null) {
throw new TestException(
"Received unexpected event from empty mailbox: " + rei_event);
}
// Start event generator thread with a delay of MAX_WAIT_SEND_EVENT
Thread t =
new Thread(
new MyEventGeneratorRunnable(myGen, evtReg.getID(), 3, 1,
logger, MAX_WAIT_SEND_EVENT ));
t.start();
before = new Date();
logger.log(Level.INFO, "Calling next() on empty set @ {0}", before);
rei_event = rei.next(MAX_WAIT_GET_EVENT);
after = new Date();
//Verify that we returned before the timeout
delta = after.getTime() - before.getTime();
logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}",
new Object[] {after, new Long(delta)});
if (delta >= MAX_WAIT_GET_EVENT) {
throw new TestException("Returned from next() after expected: "
+ delta);
} else if (delta <= MAX_WAIT_SEND_EVENT) {
throw new TestException("Returned from next() before expected: "
+ delta);
}
if (rei_event == null) {
throw new TestException(
"Did not receive expected event from mailbox.");
}
//Generate a soon-to-be unknown event.
myGen.generateEvent(evtReg.getID(), 3);
/*
* Add genereated event to unknown list and verify that they aren't
* subsequently received.
*/
ArrayList unknowns = new ArrayList(1);
unknowns.add(rei_event);
mr.addUnknownEvents(unknowns);
before = new Date();
logger.log(Level.INFO, "Calling next() on empty set @ {0}", before);
rei_event = rei.next(MAX_WAIT_GET_EVENT);
after = new Date();