Skip to content

Commit

Permalink
Fixed bug where the recoverable attribute where not set for interface…
Browse files Browse the repository at this point in the history
… message types
  • Loading branch information
andreasohlund committed Sep 26, 2011
1 parent c51e107 commit dce5d55
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SomeUserNamespace
{
using NServiceBus;

public interface InterfaceMessage:IMessage
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace NServiceBus.Unicast.Tests
using System.Collections.Generic;
using System.Linq;
using MasterNode;
using MessageInterfaces.MessageMapper.Reflection;
using MessageMutator;
using NUnit.Framework;
using ObjectBuilder;
Expand All @@ -22,6 +23,7 @@ public class using_a_configured_unicastbus

protected Address gatewayAddress;
MessageHeaderManager headerManager = new MessageHeaderManager();
MessageMapper messageMapper = new MessageMapper();

[SetUp]
public void SetUp()
Expand Down Expand Up @@ -59,7 +61,8 @@ public void SetUp()
MessageSender = messageSender,
Transport = MockRepository.GenerateStub<ITransport>(),
SubscriptionStorage = subscriptionStorage,
AutoSubscribe = true
AutoSubscribe = true,
MessageMapper = messageMapper
};
bus = unicastBus;
ExtensionMethods.SetHeaderAction = headerManager.SetHeader;
Expand All @@ -71,14 +74,18 @@ protected void RegisterMessageHandlerType<T>()
unicastBus.MessageHandlerTypes = new[] { typeof(T) };
}

protected void RegisterMessageType<T>()
protected Address RegisterMessageType<T>()
{
unicastBus.RegisterMessageType(typeof(T), new Address(typeof(T).Name, "localhost"), false);
var address = new Address(typeof (T).Name, "localhost");
RegisterMessageType<T>(address);

return address;
}

protected void RegisterMessageType<T>(Address address)
{
if(typeof(T).IsInterface)
messageMapper.Initialize(new[]{typeof(T)});
unicastBus.RegisterMessageType(typeof(T), address, false);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.MasterNode.dll</HintPath>
</Reference>
<Reference Include="NServiceBus.MessageInterfaces, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.MessageInterfaces.dll</HintPath>
</Reference>
<Reference Include="NServiceBus.MessageInterfaces.MessageMapper.Reflection">
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.MessageInterfaces.MessageMapper.Reflection.dll</HintPath>
</Reference>
<Reference Include="NServiceBus.MessageMutator, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.MessageMutator.dll</HintPath>
Expand Down Expand Up @@ -75,6 +82,7 @@
<Compile Include="AutoSubscriptions.cs" />
<Compile Include="Contexts\CommandMessage.cs" />
<Compile Include="Contexts\EventMessage.cs" />
<Compile Include="Contexts\InterfaceMessage.cs" />
<Compile Include="Sending.cs" />
<Compile Include="Contexts\MessageHeaderManager.cs" />
<Compile Include="Publishing.cs" />
Expand Down
29 changes: 29 additions & 0 deletions src/unicast/NServiceBus.Unicast.Tests/Sending.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,33 @@ public void The_gateway_address_should_be_generated_based_on_the_master_node()
messageSender.AssertWasCalled(x => x.Send(Arg<TransportMessage>.Is.Anything, Arg<Address>.Is.Equal(gatewayAddress)));
}
}

[TestFixture]
public class When_sending_a_command_message : using_the_unicastbus
{
[Test]
public void Should_specify_the_message_to_be_recoverable()
{
RegisterMessageType<CommandMessage>();

bus.Send(new CommandMessage());

messageSender.AssertWasCalled(x => x.Send(Arg<TransportMessage>.Matches(m => m.Recoverable == true), Arg<Address>.Is.Anything));
}
}


[TestFixture]
public class When_sending_a_interface_message : using_the_unicastbus
{
[Test]
public void Should_specify_the_message_to_be_recoverable()
{
var defaultAddress = RegisterMessageType<InterfaceMessage>();

bus.Send<InterfaceMessage>(m=>{});

messageSender.AssertWasCalled(x => x.Send(Arg<TransportMessage>.Matches(m => m.Recoverable), Arg<Address>.Is.Equal(defaultAddress)));
}
}
}
8 changes: 5 additions & 3 deletions src/unicast/NServiceBus.Unicast/UnicastBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,10 +1444,12 @@ protected TransportMessage MapTransportMessageFor(object[] rawMessages, Transpor

foreach (var message in messages)
{
if (recoverableMessageTypes.Contains(message.GetType()))
var messageType = message.GetType();

if (recoverableMessageTypes.Any(rt => rt.IsAssignableFrom(messageType)))
result.Recoverable = true;

var span = GetTimeToBeReceivedForMessageType(message.GetType());
var span = GetTimeToBeReceivedForMessageType(messageType);
timeToBeReceived = (span < timeToBeReceived ? span : timeToBeReceived);
}

Expand Down Expand Up @@ -1708,4 +1710,4 @@ private class MessageTypeDestinationEventArgs : EventArgs
private readonly static ILog Log = LogManager.GetLogger(typeof(UnicastBus));
#endregion
}
}
}

0 comments on commit dce5d55

Please sign in to comment.