Skip to content

Commit

Permalink
Added throwing of exception from the handler on the waiting thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed Jul 17, 2011
1 parent 9a28ed0 commit 1f9d487
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
39 changes: 39 additions & 0 deletions src/MassTransit.Tests/PublishRequest_Specs.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
}
1 change: 0 additions & 1 deletion src/MassTransit/Exceptions/RequestException.cs
Expand Up @@ -15,7 +15,6 @@ namespace MassTransit.Exceptions
using System;
using System.Runtime.Serialization;


[Serializable]
public class RequestException :
MassTransitException
Expand Down
Expand Up @@ -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);
}
};

Expand Down

0 comments on commit 1f9d487

Please sign in to comment.