getConfig().getStringConfigVal(
MAILBOX_PROPERTY_NAME,
MAILBOX_IF_NAME);
logger.log(Level.INFO, "Getting ref to " + mbType);
MailboxRegistration mr = null;
Lease mrl = null;
if (mbType.equals(MAILBOX_IF_NAME)) {
EventMailbox mb = getMailbox();
mr = getRegistration(mb, DURATION);
mrl = getMailboxLease(mr);
} else if (mbType.equals(PULL_MAILBOX_IF_NAME)) {
PullEventMailbox pmb = getPullMailbox();
MailboxPullRegistration mpr = getPullRegistration(pmb, DURATION);
mrl = getPullMailboxLease(mpr);
mr = mpr;
} else {
throw new TestException(
"Unsupported mailbox type requested" + mbType);
}
// Register and check lease
checkLease(mrl, DURATION);
// 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
DURATION); // Lease duration
Lease tgl = evtReg.getLease();
checkLease(tgl, DURATION);
// Create another event generator and pass it the
// mailbox's remote event listener.
TestGenerator myGen2 = TestUtils.createGenerator(manager);
EventRegistration evtReg2 =
myGen2.register(EVENT_ID2, // Event ID to use
null, // handback
mbRel, // Notification target
DURATION); // Lease duration
Lease tgl2 = evtReg2.getLease();
checkLease(tgl2, DURATION);
// Create two listener objects
TestListener goodRel = TestUtils.createListener(manager);
TestListener badRel = TestUtils.createUEListener(manager);
int goodRelCount = 0, badRelCount = 0;
// Generate some events from both generators
logger.log(Level.INFO, "Generating some events");
RemoteEvent event = myGen.generateEvent(evtReg.getID(), 2);
RemoteEvent event2 = myGen2.generateEvent(evtReg2.getID(), 2);
goodRelCount += 2;
RemoteEvent[] bogus = {
new RemoteEvent(myGen, 9999, 9999, null),
new RemoteEvent(myGen2, 1234, 1, null),
};
// Enable the first of our listener objects
assertCount(goodRel, 0);
logger.log(Level.INFO, "Enabling delivery to our REL" + goodRel);
mr.enableDelivery(goodRel);
// Wait for events to arrive and verify
logger.log(Level.INFO, "Wating for event delivery");
waitForEvents(goodRel, goodRelCount, MAX_WAIT);
logger.log(Level.INFO, "Verifying event delivery");
assertCount(goodRel, goodRelCount);
assertEvent(goodRel, event);
assertEvent(goodRel, event2);
if (goodRel.verifyEvents(bogus)) {
throw new TestException("Successfully verified bogus events");
}
logger.log(Level.INFO, "Disabling event delivery");
mr.disableDelivery();
// Generate some more events
logger.log(Level.INFO, "Generating some more events");
event = myGen.generateEvent(evtReg.getID(), 3);
event2 = myGen2.generateEvent(evtReg2.getID(), 3);
badRelCount += 2;
// enable second listener object
logger.log(Level.INFO, "Enabling delivery to our (bad) REL2" + badRel);
mr.enableDelivery(badRel);
// Wait for events to arrive and verify
logger.log(Level.INFO, "Wating for event delivery");
waitForEvents(badRel, badRelCount, MAX_WAIT);
assertCount(badRel, badRelCount);
assertEvent(badRel, event);
assertEvent(badRel, event2);
// Generate some more events
// This is timing dependent. It's possible to have recieved
// the event (above) and before the mailbox has time to
// process the exception, the same event type is sent again.
// In this case, the latter event will be accepted because
// the mailbox hasn't processed the intial exception.
// In either case, though, the event should never be received
// by our listener objects since our implementation will fully
// process a delivery for a registration before processing
// another event for that process.
logger.log(Level.INFO, "Generating some unknown events");
try {
event = myGen.generateEvent(evtReg.getID(), 3);
throw new TestException("Succesfully sent an unknown event");
} catch (UnknownEventException ue) {
}
try {
event2 = myGen2.generateEvent(evtReg2.getID(), 3);
throw new TestException("Succesfully sent an unknown event");
} catch (UnknownEventException ue) {
}
// Note: count should not change since they should be
// on the unknown event list.
logger.log(Level.INFO, "Wating for event delivery");
waitForEvents(badRel, badRelCount, MAX_WAIT);
assertCount(badRel, badRelCount);
// Kill the mailbox service
shutdown(0);
// Generate some more events
logger.log(Level.INFO, "Generating some more events");
try {
event = myGen.generateEvent(evtReg.getID(), 3);
throw new TestException("Succesfully sent an unknown event");
} catch (UnknownEventException ue) {
}
try {
event2 = myGen2.generateEvent(evtReg2.getID(), 3);
throw new TestException("Succesfully sent an unknown event");
} catch (UnknownEventException ue) {
}
// Note: count should not change since they should be
// on the unknown event list.
logger.log(Level.INFO, "Wating for event delivery");
waitForEvents(badRel, badRelCount, MAX_WAIT);
assertCount(badRel, badRelCount);
logger.log(Level.INFO, "Re-enabling (good) REL" + goodRel);
mr.enableDelivery(goodRel);
logger.log(Level.INFO, "Asserting that event counts haven't changed");
assertCount(goodRel, goodRelCount);
assertCount(badRel, badRelCount);
// Generate another event