-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix-4.7.2' into support-4.7
- Loading branch information
Showing
6 changed files
with
318 additions
and
15 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
src/NServiceBus.AcceptanceTests/Distributor/Processing_SLR_message.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,133 @@ | ||
namespace NServiceBus.AcceptanceTests.Distributor | ||
{ | ||
using System; | ||
using System.Messaging; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NServiceBus.AcceptanceTests.ScenarioDescriptors; | ||
using NServiceBus.Config; | ||
using NServiceBus.Transports.Msmq; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class Processing_SLR_message : NServiceBusAcceptanceTest | ||
{ | ||
static TimeSpan SlrDelay = TimeSpan.FromSeconds(5); | ||
|
||
[Test] | ||
public void Worker_should_sends_a_ready_message_to_the_distributor() | ||
{ | ||
try | ||
{ | ||
var queue = new MessageQueue(MsmqUtilities.GetFullPath(Address.Parse("distributor.distributor.processingslrmessage.msmq.distributor.storage")), false, true, QueueAccessMode.Receive); | ||
queue.Purge(); | ||
} | ||
// ReSharper disable once EmptyGeneralCatchClause | ||
catch (Exception) | ||
{ | ||
//NOOP | ||
} | ||
|
||
var context = new Context | ||
{ | ||
Id = Guid.NewGuid() | ||
}; | ||
Scenario.Define(context) | ||
.WithEndpoint<Client>(b => b | ||
.Given((bus, c) => bus.Send(new MyMessage | ||
{ | ||
Id = c.Id | ||
})) | ||
) | ||
.WithEndpoint<Distributor>() | ||
.WithEndpoint<Worker>() | ||
.Done(c => c.SecondAttemptSucceeded) | ||
.Repeat(r => r.For(Transports.Msmq)) | ||
.Run(); | ||
|
||
Assert.IsTrue(context.FirstAttemptFailed); | ||
Assert.IsTrue(context.SecondAttemptSucceeded); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public Guid Id { get; set; } | ||
public bool FirstAttemptFailed { get; set; } | ||
public bool SecondAttemptSucceeded { get; set; } | ||
} | ||
|
||
public class Client : EndpointConfigurationBuilder | ||
{ | ||
public Client() | ||
{ | ||
EndpointSetup<DefaultServer>() | ||
.AddMapping<MyMessage>(typeof(Distributor)); | ||
} | ||
} | ||
|
||
public class Distributor : EndpointConfigurationBuilder | ||
{ | ||
public Distributor() | ||
{ | ||
EndpointSetup<DefaultServer>(c => c.RunDistributor(false)); | ||
} | ||
} | ||
|
||
public class Worker : EndpointConfigurationBuilder | ||
{ | ||
public Worker() | ||
{ | ||
EndpointSetup<DefaultServer>(c => c.EnlistWithDistributor()) | ||
.AllowExceptions() | ||
.WithConfig<TransportConfig>(c => | ||
{ | ||
c.MaxRetries = 0; //to skip the FLR | ||
}) | ||
.WithConfig<UnicastBusConfig>(c => | ||
{ | ||
c.DistributorControlAddress = "distributor.distributor.processingslrmessage.msmq.distributor.control"; | ||
c.DistributorDataAddress = "distributor.distributor.processingslrmessage.msmq"; | ||
}) | ||
.WithConfig<SecondLevelRetriesConfig>(c => | ||
{ | ||
c.NumberOfRetries = 1; | ||
c.TimeIncrease = SlrDelay; | ||
}).WithConfig<MasterNodeConfig>(c => | ||
{ | ||
c.Node = "particular.net"; | ||
}); | ||
} | ||
|
||
public class MyMessageHandler : IHandleMessages<MyMessage> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public IBus Bus { get; set; } | ||
|
||
public void Handle(MyMessage request) | ||
{ | ||
if (Context.Id != request.Id) | ||
{ | ||
return; | ||
} | ||
|
||
if (!Context.FirstAttemptFailed) | ||
{ | ||
Context.FirstAttemptFailed = true; | ||
throw new Exception("Triggering SLR"); | ||
} | ||
if (Bus.CurrentMessageContext.Headers.ContainsKey(Headers.Retries)) | ||
{ | ||
Context.SecondAttemptSucceeded = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class MyMessage : IMessage | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/NServiceBus.AcceptanceTests/Exceptions/When_processing_a_message_without_an_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,99 @@ | ||
namespace NServiceBus.AcceptanceTests.Exceptions | ||
{ | ||
using System; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NServiceBus.Config; | ||
using NServiceBus.MessageMutator; | ||
using NServiceBus.Unicast; | ||
using NServiceBus.Unicast.Transport; | ||
using NUnit.Framework; | ||
|
||
public class When_processing_a_message_without_an_id : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Should_invoke_start_message_processing_listeners() | ||
{ | ||
var context = new Context(); | ||
|
||
Scenario.Define(context) | ||
.WithEndpoint<Endpoint>(b => b.Given(bus => bus.SendLocal(new Message()))) | ||
.Done(c => c.StartMessageProcessingCalled) | ||
.Run(); | ||
|
||
Assert.IsTrue(context.StartMessageProcessingCalled); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool StartMessageProcessingCalled { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.Configurer.ConfigureComponent<CorruptionMutator>(DependencyLifecycle.InstancePerCall); | ||
c.Configurer.ConfigureComponent<StartProcessingListener>(DependencyLifecycle.SingleInstance); | ||
c.DisableTimeoutManager(); | ||
}) | ||
.WithConfig<TransportConfig>(c => | ||
{ | ||
c.MaxRetries = 0; | ||
}) | ||
.AllowExceptions(); | ||
} | ||
|
||
class StartProcessingListener : IWantToRunWhenBusStartsAndStops | ||
{ | ||
Context context; | ||
|
||
public StartProcessingListener(UnicastBus bus, Context context) | ||
{ | ||
this.context = context; | ||
bus.Transport.StartedMessageProcessing += transport_StartedMessageProcessing; | ||
} | ||
|
||
void transport_StartedMessageProcessing(object sender, StartedMessageProcessingEventArgs e) | ||
{ | ||
context.StartMessageProcessingCalled = true; | ||
} | ||
|
||
public void Start() | ||
{ | ||
} | ||
|
||
public void Stop() | ||
{ | ||
} | ||
} | ||
|
||
class CorruptionMutator : IMutateTransportMessages | ||
{ | ||
public void MutateIncoming(TransportMessage transportMessage) | ||
{ | ||
} | ||
|
||
public void MutateOutgoing(object[] messages, TransportMessage transportMessage) | ||
{ | ||
transportMessage.Headers[Headers.MessageId] = ""; | ||
} | ||
} | ||
|
||
class Handler : IHandleMessages<Message> | ||
{ | ||
public void Handle(Message message) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class Message : 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
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
Oops, something went wrong.