-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3379 from Particular/hotfix-5.0.11
Hotfix 5.0.11
- Loading branch information
Showing
7 changed files
with
246 additions
and
55 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,193 @@ | ||
namespace NServiceBus.Core.Tests.Faults | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using NServiceBus.Faults; | ||
using NServiceBus.Faults.Forwarder; | ||
using NServiceBus.ObjectBuilder; | ||
using NServiceBus.ObjectBuilder.Common; | ||
using NServiceBus.Settings; | ||
using NServiceBus.Transports; | ||
using NServiceBus.Unicast; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class FaultManagerTests | ||
{ | ||
private IManageMessageFailures faultManager; | ||
private FakeSender fakeSender; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
fakeSender = new FakeSender(); | ||
var settingsHolder = new SettingsHolder(); | ||
faultManager = new FaultManager(new FakeBuilder(fakeSender), new Configure(settingsHolder, new FakeContainer(), new List<Action<IConfigureComponents>>(), null)); | ||
faultManager.Init(new Address("fake", "fake")); | ||
} | ||
|
||
[Test] | ||
public void SendingToErrorQueue_WhenSerializationFailedForMessage_ShouldRemoveTTBR() | ||
{ | ||
var exception = new InvalidOperationException(); | ||
var message = new TransportMessage("id", new Dictionary<string, string>()); | ||
message.TimeToBeReceived = TimeSpan.FromHours(1); | ||
|
||
faultManager.SerializationFailedForMessage(message, exception); | ||
|
||
var sentMessage = fakeSender.SentMessage; | ||
Assert.AreEqual(TimeSpan.MaxValue, sentMessage.TimeToBeReceived); | ||
} | ||
|
||
[Test] | ||
public void SendingToErrorQueue_ProcessingAlwaysFailsForMessage_WhenSentFromSLR_ShouldRemoveTTBR() | ||
{ | ||
var exception = new InvalidOperationException(); | ||
var message = new TransportMessage("id", new Dictionary<string, string>()); | ||
message.TimeToBeReceived = TimeSpan.FromHours(1); | ||
|
||
((FaultManager) faultManager).RetriesQueue = new Address("fake", "fake"); | ||
|
||
faultManager.ProcessingAlwaysFailsForMessage(message, exception); | ||
|
||
var sentMessage = fakeSender.SentMessage; | ||
Assert.AreEqual(TimeSpan.MaxValue, sentMessage.TimeToBeReceived); | ||
} | ||
|
||
[Test] | ||
public void SendingToErrorQueue_ProcessingAlwaysFailsForMessage_WhenRetriesQueueIsNull_ShouldRemoveTTBR() | ||
{ | ||
var exception = new InvalidOperationException(); | ||
var message = new TransportMessage("id", new Dictionary<string, string>()); | ||
message.TimeToBeReceived = TimeSpan.FromHours(1); | ||
|
||
faultManager.ProcessingAlwaysFailsForMessage(message, exception); | ||
|
||
var sentMessage = fakeSender.SentMessage; | ||
Assert.AreEqual(TimeSpan.MaxValue, sentMessage.TimeToBeReceived); | ||
} | ||
|
||
[Test] | ||
public void SendingToRetriesQueue_ProcessingAlwaysFailsForMessage_ShouldRemoveTTBR() | ||
{ | ||
var exception = new InvalidOperationException(); | ||
var message = new TransportMessage("id", new Dictionary<string, string>()); | ||
message.TimeToBeReceived = TimeSpan.FromHours(1); | ||
|
||
var manager = (FaultManager)faultManager; | ||
manager.RetriesQueue = new Address("retries", "fake"); | ||
|
||
faultManager.ProcessingAlwaysFailsForMessage(message, exception); | ||
|
||
var sentMessage = fakeSender.SentMessage; | ||
Assert.AreEqual(TimeSpan.MaxValue, sentMessage.TimeToBeReceived); | ||
} | ||
|
||
class FakeBuilder : IBuilder | ||
{ | ||
private readonly FakeSender sender; | ||
|
||
public FakeBuilder(FakeSender sender) | ||
{ | ||
this.sender = sender; | ||
} | ||
|
||
public object Build(Type typeToBuild) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public T Build<T>() | ||
{ | ||
return (dynamic) sender; | ||
} | ||
|
||
public IEnumerable<object> BuildAll(Type typeToBuild) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IEnumerable<T> BuildAll<T>() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void BuildAndDispatch(Type typeToBuild, Action<object> action) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IBuilder CreateChildBuilder() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Release(object instance) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
class FakeSender : ISendMessages | ||
{ | ||
public void Send(TransportMessage message, SendOptions sendOptions) | ||
{ | ||
SentMessage = message; | ||
} | ||
|
||
public TransportMessage SentMessage { get; set; } | ||
} | ||
|
||
class FakeContainer : IContainer | ||
{ | ||
public void Dispose() | ||
{ | ||
} | ||
|
||
public object Build(Type typeToBuild) | ||
{ | ||
return null; | ||
} | ||
|
||
public IContainer BuildChildContainer() | ||
{ | ||
return null; | ||
} | ||
|
||
public IEnumerable<object> BuildAll(Type typeToBuild) | ||
{ | ||
yield break; | ||
} | ||
|
||
public void Configure(Type component, DependencyLifecycle dependencyLifecycle) | ||
{ | ||
} | ||
|
||
public void Configure<T>(Func<T> component, DependencyLifecycle dependencyLifecycle) | ||
{ | ||
} | ||
|
||
public void ConfigureProperty(Type component, string property, object value) | ||
{ | ||
} | ||
|
||
public void RegisterSingleton(Type lookupType, object instance) | ||
{ | ||
} | ||
|
||
public bool HasComponent(Type componentType) | ||
{ | ||
return true; | ||
} | ||
|
||
public void Release(object instance) | ||
{ | ||
} | ||
} | ||
} | ||
} |
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
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.