Skip to content

Commit

Permalink
Merge branch 'release-4.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasohlund committed Apr 11, 2014
2 parents 3e8edf8 + 791ab1f commit 914a8a2
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 35 deletions.
83 changes: 83 additions & 0 deletions src/NServiceBus.AcceptanceTests/MessageMutators/Issue_1980.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace NServiceBus.AcceptanceTests.Sagas
{
using System;
using EndpointTemplates;
using AcceptanceTesting;
using MessageMutator;
using NUnit.Framework;

public class Issue_1980 : NServiceBusAcceptanceTest
{
[Test]
public void Run()
{
var context = new Context();

Scenario.Define(context)
.WithEndpoint<Endpoint>(b => b.Given((bus, c) => bus.SendLocal(new V1Message())))
.Done(c => c.V2MessageReceived)
.Run();

Assert.IsTrue(context.V2MessageReceived);
Assert.IsFalse(context.V1MessageReceived);
}

public class Context : ScenarioContext
{
public bool V1MessageReceived { get; set; }
public bool V2MessageReceived { get; set; }
}

public class Endpoint : EndpointConfigurationBuilder
{
public Endpoint()
{
EndpointSetup<DefaultServer>(
c => c.Configurer.ConfigureComponent<MutateIncomingMessages>(DependencyLifecycle.InstancePerCall));
}

class MutateIncomingMessages : IMutateIncomingMessages
{
public object MutateIncoming(object message)
{
if (message is V1Message)
{
return new V2Message();
}

return message;
}
}

class V2MessageHandler : IHandleMessages<V2Message>
{
public Context Context { get; set; }

public void Handle(V2Message message)
{
Context.V2MessageReceived = true;
}
}

class V1MessageHandler : IHandleMessages<V1Message>
{
public Context Context { get; set; }

public void Handle(V1Message message)
{
Context.V1MessageReceived = true;
}
}
}

[Serializable]
public class V1Message : ICommand
{
}

[Serializable]
public class V2Message : ICommand
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace NServiceBus.AcceptanceTests.Sagas
{
using System;
using AcceptanceTesting;
using EndpointTemplates;
using MessageMutator;
using NUnit.Framework;

public class When_outgoing_mutator_replaces_message_instance : NServiceBusAcceptanceTest
{
[Test]
public void Message_sent_should_be_new_instance()
{
var context = new Context();

Scenario.Define(context)
.WithEndpoint<Endpoint>(b => b.Given((bus, c) => bus.SendLocal(new V1Message())))
.Done(c => c.V2MessageReceived)
.Run();

Assert.IsTrue(context.V2MessageReceived);
Assert.IsFalse(context.V1MessageReceived);
}

public class Context : ScenarioContext
{
public bool V1MessageReceived { get; set; }
public bool V2MessageReceived { get; set; }
}

public class Endpoint : EndpointConfigurationBuilder
{
public Endpoint()
{
EndpointSetup<DefaultServer>(
c => c.Configurer.ConfigureComponent<MutateOutgoingMessages>(DependencyLifecycle.InstancePerCall));
}

class MutateOutgoingMessages : IMutateOutgoingMessages
{
public object MutateOutgoing(object message)
{
if (message is V1Message)
{
return new V2Message();
}

return message;
}
}

class V2MessageHandler : IHandleMessages<V2Message>
{
public Context Context { get; set; }

public void Handle(V2Message message)
{
Context.V2MessageReceived = true;
}
}

class V1MessageHandler : IHandleMessages<V1Message>
{
public Context Context { get; set; }

public void Handle(V1Message message)
{
Context.V1MessageReceived = true;
}
}
}

[Serializable]
public class V1Message : ICommand
{
}

[Serializable]
public class V2Message : ICommand
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
<Compile Include="BasicMessaging\When_Deferring_a_message.cs" />
<Compile Include="BusStartStop\When_bus_start_raises_an_inmemory_message.cs" />
<Compile Include="HostInformation\When_a_message_is_received.cs" />
<Compile Include="MessageMutators\Issue_1980.cs" />
<Compile Include="MessageMutators\When_outgoing_mutator_replaces_message_instance.cs" />
<Compile Include="MessageMutators\When_defining_outoing_message_mutators.cs" />
<Compile Include="PipelineExtension\MutingHandlerExceptions.cs" />
<Compile Include="PipelineExtension\FilteringWhatGetsAudited.cs" />
Expand Down Expand Up @@ -147,6 +149,7 @@
<Compile Include="Retries\When_messages_fails_flr.cs" />
<Compile Include="Retries\When_message_fails_with_retries_set_to_0.cs" />
<Compile Include="Retries\When_doing_flr_with_default_settings.cs" />
<Compile Include="Sagas\Issue_2044.cs" />
<Compile Include="Sagas\When_doing_request_response_between_sagas.cs" />
<Compile Include="Sagas\Issue_1819.cs" />
<Compile Include="Sagas\When_sending_from_a_saga_timeout.cs" />
Expand Down
99 changes: 99 additions & 0 deletions src/NServiceBus.AcceptanceTests/Sagas/Issue_2044.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace NServiceBus.AcceptanceTests.Sagas
{
using System;
using EndpointTemplates;
using AcceptanceTesting;
using NUnit.Framework;
using Saga;

public class Issue_2044 : NServiceBusAcceptanceTest
{
[Test]
public void Run()
{
var context = new Context();

Scenario.Define(context)
.WithEndpoint<Sender>(b => b.Given((bus, c) => bus.Send(new MessageToSaga())))
.WithEndpoint<ReceiverWithSaga>()
.Done(c => c.ReplyReceived)
.Run();

Assert.IsTrue(context.ReplyReceived);
}

public class Context : ScenarioContext
{
public bool ReplyReceived { get; set; }
}

public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
EndpointSetup<DefaultServer>()
.AddMapping<MessageToSaga>(typeof(ReceiverWithSaga));
}

public class ReplyHandler : IHandleMessages<Reply>
{
public Context Context { get; set; }


public void Handle(Reply message)
{
Context.ReplyReceived = true;
}
}
}

public class ReceiverWithSaga : EndpointConfigurationBuilder
{
public ReceiverWithSaga()
{
EndpointSetup<DefaultServer>();
}

public class Saga1 : Saga<Saga1.Saga1Data>, IAmStartedByMessages<StartSaga1>, IHandleMessages<MessageToSaga>
{

public void Handle(StartSaga1 message)
{
}

public void Handle(MessageToSaga message)
{
}

public class Saga1Data : ContainSagaData
{
}
}

public class SagaNotFound : IHandleSagaNotFound
{
public IBus Bus { get; set; }

public void Handle(object message)
{
Bus.Reply(new Reply());
}
}
}

[Serializable]
public class StartSaga1 : ICommand
{
}

[Serializable]
public class MessageToSaga : ICommand
{
}

[Serializable]
public class Reply : IMessage
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Incoming_databus_properties_should_be_hydrated()
{
Key = propertyKey
}
}, new Dictionary<string, string> { { "NServiceBus.DataBus." + propertyKey, databusKey } });
}, new Dictionary<string, string> { { "NServiceBus.DataBus." + propertyKey, databusKey } }, null);

using (var stream = new MemoryStream())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Should_not_blow_up()
TimeToBeReceived = TimeSpan.FromDays(1)
};

var message = new LogicalMessage(metadata, new MessageWithNullDataBusProperty(), new Dictionary<string, string>());
var message = new LogicalMessage(metadata, new MessageWithNullDataBusProperty(), new Dictionary<string, string>(), null);
var context = new SendLogicalMessageContext(null,new SendOptions(), message);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Outgoing_databus_properties_should_be_dehydrated()
var message = new LogicalMessage(metadata, new MessageWithDataBusProperty
{
DataBusProperty = new DataBusProperty<string>("test")
}, new Dictionary<string, string>());
}, new Dictionary<string, string>(), null);

Invoke(message);

Expand All @@ -49,7 +49,7 @@ public void Time_to_live_should_be_passed_on_the_databus()
var message = new LogicalMessage(metadata, new MessageWithExplicitTimeToLive
{
DataBusProperty = new DataBusProperty<string>("test")
}, new Dictionary<string, string>());
}, new Dictionary<string, string>(), null);

Invoke(message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void Init()
config.Configurer.ConfigureComponent<ReadyMessageSender>(DependencyLifecycle.SingleInstance)
.ConfigureProperty(p => p.DistributorControlAddress, distributorControlAddress);

Address.OverridePublicReturnAddress(distributorControlAddress);
Address.OverridePublicReturnAddress(masterNodeAddress);

config.Configurer.ConfigureComponent<ReturnAddressRewriter>(
DependencyLifecycle.SingleInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public void Invoke(ReceiveLogicalMessageContext context, Action next)
{
var current = context.LogicalMessage.Instance;

//message mutators may need to assume that this has been set (eg. for the purposes of headers).
ExtensionMethods.CurrentMessageBeingHandled = current;

foreach (var mutator in context.Builder.BuildAll<IMutateIncomingMessages>())
{
context.LogicalMessage.UpdateMessageInstance(mutator.MutateIncoming(current));
//message mutators may need to assume that this has been set (eg. for the purposes of headers).
ExtensionMethods.CurrentMessageBeingHandled = current;
current = mutator.MutateIncoming(current);
context.LogicalMessage.UpdateMessageInstance(current);
}

next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ public class MutateOutgoingMessageBehavior : IBehavior<SendLogicalMessageContext
{
public void Invoke(SendLogicalMessageContext context, Action next)
{
foreach (var mutator in context.Builder.BuildAll<IMutateOutgoingMessages>())
var currentMessageToSend = context.MessageToSend.Instance;

foreach (var mutator in context.Builder.BuildAll<IMutateOutgoingMessages>())
{
context.MessageToSend.UpdateMessageInstance(mutator.MutateOutgoing(context.MessageToSend.Instance));
currentMessageToSend = mutator.MutateOutgoing(currentMessageToSend);
context.MessageToSend.UpdateMessageInstance(currentMessageToSend);
}

next();
Expand Down
2 changes: 1 addition & 1 deletion src/NServiceBus.Core/Sagas/SagaSendBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Invoke(SendLogicalMessageContext context, Action next)
{
ActiveSagaInstance saga;

if (context.TryGet(out saga))
if (context.TryGet(out saga) && !saga.NotFound)
{
context.MessageToSend.Headers[Headers.OriginatingSagaId] = saga.Instance.Entity.Id.ToString();
context.MessageToSend.Headers[Headers.OriginatingSagaType] = saga.SagaType.AssemblyQualifiedName;
Expand Down
Loading

0 comments on commit 914a8a2

Please sign in to comment.