Permalink
Browse files

Added throwing of exception from the handler on the waiting thread.

  • Loading branch information...
1 parent 9a28ed0 commit 1f9d4872d4885cc01794daa37b8104467b78bc80 @phatboyg phatboyg committed Jul 17, 2011
View
39 src/MassTransit.Tests/PublishRequest_Specs.cs
@@ -12,6 +12,7 @@
// specific language governing permissions and limitations under the License.
namespace MassTransit.Tests
{
+ using System;
using Exceptions;
using Magnum.Extensions;
using Magnum.TestFramework;
@@ -79,5 +80,43 @@ public void Should_throw_a_timeout_exception_if_no_response_received()
pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
pongReceived.IsAvailable(timeout).ShouldBeFalse("The pong should not have been received");
}
+
+ [Test]
+ public void Should_throw_a_handler_exception_on_the_calling_thread()
+ {
+ var pongReceived = new FutureMessage<PongMessage>();
+ var pingReceived = new FutureMessage<PingMessage>();
+
+ RemoteBus.SubscribeHandler<PingMessage>(message =>
+ {
+ pingReceived.Set(message);
+ RemoteBus.MessageContext<PingMessage>().Respond(new PongMessage(message.CorrelationId));
+ });
+
+ var ping = new PingMessage();
+
+ var timeout = 8.Seconds();
+
+ var exception = Assert.Throws<RequestException>(() =>
+ {
+ LocalBus.PublishRequest(ping, x =>
+ {
+ x.Handle<PongMessage>(message =>
+ {
+ pongReceived.Set(message);
+
+ throw new InvalidOperationException("I got it, but I am naughty with it.");
+ });
+
+ x.SetTimeout(timeout);
+ });
+ }, "A request exception should have been thrown");
+
+ exception.ResponseMessage.ShouldBeAnInstanceOf<PongMessage>();
+ exception.HandlerException.ShouldBeAnInstanceOf<InvalidOperationException>();
+
+ pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
+ pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
+ }
}
}
View
1 src/MassTransit/Exceptions/RequestException.cs
@@ -15,7 +15,6 @@ namespace MassTransit.Exceptions
using System;
using System.Runtime.Serialization;
-
[Serializable]
public class RequestException :
MassTransitException
View
4 src/MassTransit/RequestResponse/Configurators/RequestConfiguratorImpl.cs
@@ -62,8 +62,8 @@ public void Handle<TResponse>(Action<TResponse> handler)
}
catch (Exception ex)
{
- var responseException = new RequestException(message, ex);
- _request.Fail(responseException);
+ var exception = new RequestException(message, ex);
+ _request.Fail(exception);
}
};

0 comments on commit 1f9d487

Please sign in to comment.