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);
int expectedEventCount = 0;
// Generate some events
logger.log(Level.INFO, "Generating " + NUM_EVENTS + " events");
ArrayList generatedEvents = new ArrayList();
RemoteEvent[] genEvents = new RemoteEvent[NUM_EVENTS];
for (i = 0; i < NUM_EVENTS; i++) {
genEvents[i] = myGen.generateEvent(evtReg.getID(), 3);
generatedEvents.add(genEvents[i]);
}
expectedEventCount += NUM_EVENTS;
// Generate some events
logger.log(Level.INFO, "Generating " + NUM_EVENTS + " events");
for (i = 0; i < NUM_EVENTS; i++) {
generatedEvents.add(myGen2.generateEvent(evtReg2.getID(), 3));
}
logger.log(Level.INFO, "Sent events {0}", generatedEvents);
expectedEventCount += NUM_EVENTS;
// Get events and verify
logger.log(Level.INFO, "Getting events.");
RemoteEventIterator rei = mr.getRemoteEvents();
ArrayList receivedEvents = new ArrayList();
RemoteEvent rei_event;
while ((rei_event = rei.next(MAX_WAIT)) != null) {
receivedEvents.add(rei_event);
}
logger.log(Level.INFO, "Received events {0}", receivedEvents);
logger.log(Level.INFO, "Verifying received events");
assertEvents(generatedEvents, receivedEvents);
if (receivedEvents.size() != expectedEventCount) {
throw new TestException("Received " + receivedEvents.size()
+ " events, but expected " + expectedEventCount);
}
// Set myGen events as unknown events
logger.log(Level.INFO, "Calling addUnknownEvents");
mr.addUnknownEvents(java.util.Arrays.asList(genEvents));
// Send some myGen events -- should be rejected
int exceptionCount = 0;
logger.log(Level.INFO, "Generating some unknown events");
for (i = 0; i < NUM_EVENTS; i++) {
try {
genEvents[i] = myGen.generateEvent(evtReg.getID(), 3);
} catch (UnknownEventException uue) {
exceptionCount++;
logger.log(Level.INFO, "Caught expected exception -- ignoring",
uue);
}
}
if (exceptionCount != NUM_EVENTS) {
throw new TestException("Unexpected number of exceptions "
+ exceptionCount);
}
//Verify that events weren't delivered
RemoteEvent re = null;
if ((re = rei.next(MAX_WAIT)) != null) {
throw new TestException("Unexpected event received " + re);
}
logger.log(Level.INFO, "Did not receive any unknown events");
// Generate some myGen2 events -- should be accepted
logger.log(Level.INFO, "Generating " + NUM_EVENTS + " events");
for (i = 0; i < NUM_EVENTS; i++) {
generatedEvents.add(myGen2.generateEvent(evtReg2.getID(), 3));
}
expectedEventCount += NUM_EVENTS;
logger.log(Level.INFO, "Sent events {0}", generatedEvents);
while ((rei_event = rei.next(MAX_WAIT)) != null) {
receivedEvents.add(rei_event);
}
logger.log(Level.INFO, "Received events {0}", receivedEvents);
logger.log(Level.INFO, "Verifying received events");
assertEvents(generatedEvents, receivedEvents);
if (receivedEvents.size() != expectedEventCount) {
throw new TestException("Received " + receivedEvents.size()
+ " events, but expected " + expectedEventCount);
}
//
// Kill event mailbox service
//
logger.log(Level.INFO, "Killing mailbox service");
shutdown(0);
// Send some myGen events -- should be rejected
exceptionCount = 0;
logger.log(Level.INFO, "Generating some more unknown events");
for (i = 0; i < NUM_EVENTS; i++) {
try {
genEvents[i] = myGen.generateEvent(evtReg.getID(), 3);
} catch (UnknownEventException uue) {
exceptionCount++;
logger.log(Level.INFO, "Caught expected exception -- ignoring",
uue);
}
}
if (exceptionCount != NUM_EVENTS) {
throw new TestException("Unexpected number of exceptions "
+ exceptionCount);
}
//Verify that events weren't delivered
re = null;
if ((re = rei.next(MAX_WAIT)) != null) {
throw new TestException("Unexpected event received " + re);
}
logger.log(Level.INFO, "Did not receive any unknown events");
// Get new iter -- should clear unknown event list
logger.log(Level.INFO, "Getting new remote event iterator.");
rei = mr.getRemoteEvents();
re = null;
if ((re = rei.next(MAX_WAIT)) != null) {
throw new TestException("Unexpected event received " + re);
}
logger.log(Level.INFO, "Did not receive any unknown events");