}
FunctionalTestComponent ftc = getFunctionalTestComponent("Bouncer");
// whether a MessageRedeliverdException has been fired
final Latch mrexFired = new Latch();
muleContext.registerListener(new ExceptionNotificationListener<ExceptionNotification>()
{
public void onNotification(ExceptionNotification notification)
{
logger.debug("onNotification() = " + notification.getException().getClass().getName());
if (notification.getException() instanceof MessageRedeliveredException)
{
mrexFired.countDown();
// Test for MULE-4630
assertEquals(DESTINATION, ((MessageRedeliveredException) notification.getException()).getEndpoint().getEndpointURI().toString());
assertEquals(MAX_REDELIVERY, ((MessageRedeliveredException) notification.getException()).getMaxRedelivery());
assertTrue(((MessageRedeliveredException) notification.getException()).getMuleMessage().getPayload() instanceof javax.jms.Message);
}
}
});
// enhance the counter callback to count, then throw an exception
final CounterCallback callback = new CounterCallback()
{
@Override
public void eventReceived(MuleEventContext context, Object Component) throws Exception
{
final int count = incCallbackCount();
logger.info("Message Delivery Count is: " + count);
throw new FunctionalTestException();
}
};
ftc.setEventCallback(callback);
client.dispatch(DESTINATION, TEST_MESSAGE, null);
Thread.sleep(2000);
mrexFired.await(timeout, TimeUnit.MILLISECONDS);
assertEquals("MessageRedeliveredException never fired.", 0, mrexFired.getCount());
assertEquals("Wrong number of delivery attempts", MAX_REDELIVERY + 1, callback.getCallbackCount());
MuleMessage dl = client.request("jms://dead.letter", 1000);
assertNotNull(dl);
assertTrue(dl.getPayload() instanceof ExceptionMessage);