diff options
author | Michael Barker <mike@middlesoft.co.uk> | 2009-01-05 07:39:22 +0300 |
---|---|---|
committer | Michael Barker <mike@middlesoft.co.uk> | 2009-01-05 07:39:22 +0300 |
commit | 3777c193211cfec77bad2546697e11952f6804f9 (patch) | |
tree | 69eda4f58349da423808ed9d19a220727005f27f /mcs/class | |
parent | 74b04d62184751483bfde3f88bcae57218bcba5e (diff) |
2009-01-03 Michael Barker <mike@middlesoft.co.uk>
* AsyncPeekTest.cs: Added test for handling exceptions aysnchronously.
* AsyncReceiveTest.cs: Added test for handling exceptions aysnchronously.
* MessageQueueBase.cs: Added support for handling exception asynchronously.
svn path=/trunk/mcs/; revision=122408
Diffstat (limited to 'mcs/class')
5 files changed, 49 insertions, 9 deletions
diff --git a/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/AsyncPeekTest.cs b/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/AsyncPeekTest.cs index 40cf60855fd..9663aa63ef7 100644 --- a/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/AsyncPeekTest.cs +++ b/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/AsyncPeekTest.cs @@ -62,7 +62,8 @@ namespace MonoTests.Mono.Messaging.RabbitMQ Message rMsg = q.EndPeek (result); Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal"); Assert.IsTrue (eventCalled, "Handle Message not called"); - q.Purge (); + + Assert.IsNotNull (q.Receive (), "Message not peeked"); } [Test] @@ -79,7 +80,7 @@ namespace MonoTests.Mono.Messaging.RabbitMQ Message rMsg = q.EndPeek (result); Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal"); - q.Purge (); + Assert.IsNotNull (q.Receive (), "Message not peeked"); } [Test] @@ -97,7 +98,7 @@ namespace MonoTests.Mono.Messaging.RabbitMQ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal"); Assert.AreEqual ("foo", result.AsyncState, "State not passed properly"); - q.Purge (); + Assert.IsNotNull (q.Receive (), "Message not peeked"); } private bool success = false; @@ -123,7 +124,17 @@ namespace MonoTests.Mono.Messaging.RabbitMQ Assert.AreEqual ("foo", result.AsyncState, "State not passed properly"); Assert.IsTrue (success, "Callback not run"); - q.Purge (); + Assert.IsNotNull (q.Receive (), "Message not peeked"); } + + [Test] + [ExpectedException (typeof (MessageQueueException))] + public void BeginPeekWithException() + { + MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-5"); + IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2)); + result.AsyncWaitHandle.WaitOne (); + Message rMsg = q.EndPeek (result); + } } } diff --git a/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/AsyncReceiveTest.cs b/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/AsyncReceiveTest.cs index 53c3a2b50b6..e7febea3c2a 100644 --- a/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/AsyncReceiveTest.cs +++ b/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/AsyncReceiveTest.cs @@ -126,5 +126,15 @@ namespace MonoTests.Mono.Messaging.RabbitMQ Assert.AreEqual ("foo", result.AsyncState, "State not passed properly"); Assert.IsTrue (success, "Callback not run"); } + + [Test] + [ExpectedException (typeof (MessageQueueException))] + public void BeginReceiveWithException() + { + MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-5"); + IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2)); + result.AsyncWaitHandle.WaitOne (); + Message rMsg = q.EndReceive (result); + } } } diff --git a/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/ChangeLog b/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/ChangeLog index 289039fbbdf..c0c90ee8e15 100644 --- a/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/ChangeLog +++ b/mcs/class/Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/ChangeLog @@ -1,3 +1,8 @@ +2009-01-03 Michael Barker <mike@middlesoft.co.uk> + + * AsyncPeekTest.cs: Added test for handling exceptions aysnchronously. + * AsyncReceiveTest.cs: Added test for handling exceptions aysnchronously. + 2008-12-20 Michael Barker <mike@middlesoft.co.uk> * AsyncReceiveTest.cs: New, tests for Asynchronous Receive methods. diff --git a/mcs/class/Mono.Messaging/Mono.Messaging/ChangeLog b/mcs/class/Mono.Messaging/Mono.Messaging/ChangeLog index 222a74f0088..00af9d8d6ef 100644 --- a/mcs/class/Mono.Messaging/Mono.Messaging/ChangeLog +++ b/mcs/class/Mono.Messaging/Mono.Messaging/ChangeLog @@ -1,3 +1,7 @@ +2009-01-03 Michael Barker <mike@middlesoft.co.uk> + + * MessageQueueBase.cs: Added support for handling exception asynchronously. + 2008-12-21 Michael Barker <mike@middlesoft.co.uk> * MessageQueueBase.cs: Added optional base class that provide async diff --git a/mcs/class/Mono.Messaging/Mono.Messaging/MessageQueueBase.cs b/mcs/class/Mono.Messaging/Mono.Messaging/MessageQueueBase.cs index e15d4471e63..06b4a045c3a 100644 --- a/mcs/class/Mono.Messaging/Mono.Messaging/MessageQueueBase.cs +++ b/mcs/class/Mono.Messaging/Mono.Messaging/MessageQueueBase.cs @@ -162,6 +162,7 @@ namespace Mono.Messaging protected IMessage message; protected readonly TimeSpan timeout; protected readonly AsyncCallback callback; + protected MonoMessagingException ex = null; public AsyncResultBase (object asyncState, IMessageQueue q, @@ -195,7 +196,12 @@ namespace Mono.Messaging } internal IMessage Message { - get { return message; } + get { + if (ex != null) + throw new MonoMessagingException ("Asynchronous Wrapped Exception", ex); + + return message; + } } protected abstract IMessage GetMessage (); @@ -204,10 +210,14 @@ namespace Mono.Messaging private void run () { - message = GetMessage (); - isCompleted = true; - callback (this); - SendCompletedEvent (this); + try { + message = GetMessage (); + isCompleted = true; + callback (this); + SendCompletedEvent (this); + } catch (MonoMessagingException ex) { + this.ex = ex; + } } } |