{
TestSubscriptionEventBean bean1 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
"testSubscribingEventBean1");
assertNotNull(bean1);
final Latch whenFinished1 = new Latch();
EventCallback callback = new EventCallback()
{
public void eventReceived(MuleEventContext context, Object o) throws Exception
{
MuleApplicationEvent returnEvent = new MuleApplicationEvent("MuleEvent from a spring bean",
"vm://testBean2");
MuleApplicationEvent e = (MuleApplicationEvent) o;
e.getApplicationContext().publishEvent(returnEvent);
if (eventCounter1.incrementAndGet() == NUMBER_OF_MESSAGES)
{
whenFinished1.countDown();
}
}
};
bean1.setEventCallback(callback);
TestSubscriptionEventBean bean2 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
"testSubscribingEventBean2");
assertNotNull(bean2);
Latch whenFinished2 = new Latch();
bean2.setEventCallback(new CountingEventCallback(eventCounter2, NUMBER_OF_MESSAGES, whenFinished2));
// send asynchronously
this.doSend("vm://event.multicaster", "Test Spring MuleEvent", NUMBER_OF_MESSAGES);
whenFinished1.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
whenFinished2.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
assertEquals(NUMBER_OF_MESSAGES, eventCounter1.get());
assertEquals(NUMBER_OF_MESSAGES, eventCounter2.get());
}