SPRNET-1300 - NMS custom schema is missing a way to set the Exception Listener when creating message listener containers

SPRNET-1302 - Add IErrorHandler interface to be called when exception thrown by message processing is not of vendor specific messaging exception type.
This commit is contained in:
markpollack
2009-12-16 19:00:48 +00:00
parent 5dbf70699e
commit 5b0ede6a7c
15 changed files with 537 additions and 28 deletions

View File

@@ -26,6 +26,7 @@ using NUnit.Framework;
using Rhino.Mocks;
using Spring.Messaging.Ems.Common;
using Spring.Messaging.Ems.Listener;
using Spring.Util;
using TIBCO.EMS;
#endregion
@@ -99,17 +100,56 @@ namespace Spring.Messaging.Ems.Core
// manually trigger an Exception with the above bad MessageListener...
messageConsumer.SendMessage(message);
mocks.VerifyAll();
}
[Test]
public void RegisteredErrorHandlerIsInvokedOnException()
{
SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();
ISession session = (ISession)mocks.CreateMock(typeof(ISession));
Expect.Call(session.CreateQueue(DESTINATION_NAME)).Return(QUEUE_DESTINATION);
Expect.Call(session.CreateConsumer(QUEUE_DESTINATION, null)).Return(messageConsumer);
// an exception is thrown, so the rollback logic is being applied here...
Expect.Call(session.Transacted).Return(false);
IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection));
//connection.ExceptionListener += container.OnException;
connection.ExceptionListener = container;
Expect.Call(connection.CreateSession(false, container.SessionAcknowledgeMode)).Return(session);
connection.Start();
IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
Expect.Call(connectionFactory.CreateConnection()).Return(connection);
IllegalStateException theException = new IllegalStateException(EXCEPTION_MESSAGE);
IErrorHandler errorHandler = (IErrorHandler)mocks.CreateMock(typeof(IErrorHandler));
errorHandler.HandleError(theException);
//IMessage message = (IMessage) mocks.CreateMock(typeof (IMessage));
TextMessage message = new TextMessage(null, "hello");
mocks.ReplayAll();
container.ConnectionFactory = connectionFactory;
container.DestinationName = DESTINATION_NAME;
container.MessageListener = new BadSessionAwareMessageListener(theException);
container.ErrorHandler = errorHandler;
container.AfterPropertiesSet();
// manually trigger an Exception with the above bad MessageListener...
messageConsumer.SendMessage(message);
mocks.VerifyAll();
}
}
internal class BadSessionAwareMessageListener : ISessionAwareMessageListener
{
private EMSException exception;

View File

@@ -25,6 +25,7 @@ using Apache.NMS;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Messaging.Nms.Listener;
using Spring.Util;
#endregion
@@ -94,15 +95,48 @@ namespace Spring.Messaging.Nms.Core
// manually trigger an Exception with the above bad MessageListener...
messageConsumer.SendMessage(message);
mocks.VerifyAll();
}
[Test]
public void RegisteredErrorHandlerIsInvokedOnException()
{
SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();
ISession session = (ISession)mocks.CreateMock(typeof(ISession));
Expect.Call(session.GetQueue(DESTINATION_NAME)).Return(QUEUE_DESTINATION);
Expect.Call(session.CreateConsumer(QUEUE_DESTINATION, null)).Return(messageConsumer);
// an exception is thrown, so the rollback logic is being applied here...
Expect.Call(session.Transacted).Return(false);
IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection));
connection.ExceptionListener += container.OnException;
Expect.Call(connection.CreateSession(container.SessionAcknowledgeMode)).Return(session);
connection.Start();
IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
Expect.Call(connectionFactory.CreateConnection()).Return(connection);
IllegalStateException theException = new IllegalStateException(EXCEPTION_MESSAGE);
IErrorHandler errorHandler = (IErrorHandler)mocks.CreateMock(typeof(IErrorHandler));
errorHandler.HandleError(theException);
IMessage message = (IMessage)mocks.CreateMock(typeof(IMessage));
mocks.ReplayAll();
container.ConnectionFactory = connectionFactory;
container.DestinationName = DESTINATION_NAME;
container.MessageListener = new BadSessionAwareMessageListener(theException);
container.ErrorHandler = errorHandler;
container.AfterPropertiesSet();
// manually trigger an Exception with the above bad MessageListener...
messageConsumer.SendMessage(message);
mocks.VerifyAll();
}
}