Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making sure that message with a pre-existing sagaId won't start new s…
…aga. Fixes #2446 Adding failing acpt test for #2446 Making sure that a messages with a sagaid header won't start new sagas Since they are targeted to a specific saga a new one should not be created if it can't be found. Fixes #2446 Adding test to verify that saga type should match So that other sagas could be started Conflicts: src/NServiceBus.Core/Sagas/SagaPersistenceBehavior.cs
- Loading branch information
John Simons
committed
Oct 8, 2014
1 parent
5e66316
commit 978e847
Showing
4 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/NServiceBus.AcceptanceTests/Sagas/When_message_has_a_saga_id.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
namespace NServiceBus.AcceptanceTests.Sagas | ||
{ | ||
using System; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NServiceBus.Saga; | ||
using NUnit.Framework; | ||
|
||
public class When_message_has_a_saga_id : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Should_not_start_a_new_saga_if_not_found() | ||
{ | ||
var context = Scenario.Define<Context>() | ||
.WithEndpoint<SagaEndpoint>(b => b.Given(bus => | ||
{ | ||
var message = new MessageWithSagaId(); | ||
bus.SetMessageHeader(message, Headers.SagaId, Guid.NewGuid().ToString()); | ||
bus.SetMessageHeader(message, Headers.SagaType, typeof(MySaga).AssemblyQualifiedName); | ||
bus.SendLocal(message); | ||
})) | ||
.Done(c => c.NotFoundHandlerCalled && c.OtherSagaStarted) | ||
.Run(TimeSpan.FromSeconds(15)); | ||
|
||
Assert.True(context.NotFoundHandlerCalled); | ||
Assert.True(context.OtherSagaStarted); | ||
Assert.False(context.MessageHandlerCalled); | ||
Assert.False(context.TimeoutHandlerCalled); | ||
} | ||
|
||
class MySaga : Saga<MySaga.SagaData>, IAmStartedByMessages<MessageWithSagaId>, | ||
IHandleTimeouts<MessageWithSagaId>, | ||
IHandleSagaNotFound | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public class SagaData : ContainSagaData | ||
{ | ||
} | ||
|
||
public void Handle(MessageWithSagaId message) | ||
{ | ||
Context.MessageHandlerCalled = true; | ||
} | ||
|
||
public void Handle(object message) | ||
{ | ||
Context.NotFoundHandlerCalled = true; | ||
} | ||
|
||
public void Timeout(MessageWithSagaId state) | ||
{ | ||
Context.TimeoutHandlerCalled = true; | ||
} | ||
} | ||
|
||
class MyOtherSaga : Saga<MyOtherSaga.SagaData>, IAmStartedByMessages<MessageWithSagaId> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public void Handle(MessageWithSagaId message) | ||
{ | ||
Context.OtherSagaStarted = true; | ||
} | ||
|
||
public class SagaData : ContainSagaData | ||
{ | ||
} | ||
|
||
} | ||
|
||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool NotFoundHandlerCalled { get; set; } | ||
public bool MessageHandlerCalled { get; set; } | ||
public bool TimeoutHandlerCalled { get; set; } | ||
public bool OtherSagaStarted { get; set; } | ||
} | ||
|
||
public class SagaEndpoint : EndpointConfigurationBuilder | ||
{ | ||
public SagaEndpoint() | ||
{ | ||
EndpointSetup<DefaultServer>(); | ||
} | ||
} | ||
|
||
public class MessageWithSagaId : IMessage | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,5 +85,4 @@ public class Saga1Timeout : IMessage | |
{ | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters