-
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 #2472 from Particular/cantConvertToTransportMessage
Failure to convert to TransportMessage should result in ErrorQueue
- Loading branch information
Showing
15 changed files
with
374 additions
and
103 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
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
17 changes: 17 additions & 0 deletions
17
...iceBus.AcceptanceTests/Exceptions/Cant_convert_to_TransportMessage/SerializerCorrupter.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,17 @@ | ||
namespace NServiceBus.AcceptanceTests.Exceptions | ||
{ | ||
using System; | ||
using System.Reflection; | ||
|
||
static class SerializerCorrupter | ||
{ | ||
|
||
public static void Corrupt() | ||
{ | ||
var msmqUtilitiesType = Type.GetType("NServiceBus.MsmqUtilities, NServiceBus.Core"); | ||
var headerSerializerField = msmqUtilitiesType.GetField("headerSerializer", BindingFlags.Static | BindingFlags.NonPublic); | ||
headerSerializerField.SetValue(null, null); | ||
} | ||
|
||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...ests/Exceptions/Cant_convert_to_TransportMessage/When_cant_convert_to_TransportMessage.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,60 @@ | ||
namespace NServiceBus.AcceptanceTests.Exceptions | ||
{ | ||
using System; | ||
using System.Linq; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTesting.Support; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
|
||
public class When_cant_convert_to_TransportMessage : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Should_send_message_to_error_queue() | ||
{ | ||
Scenario.Define<Context>() | ||
.WithEndpoint<Sender>(b => b.Given(bus => bus.Send(new Message()))) | ||
.WithEndpoint<Receiver>() | ||
.AllowExceptions() | ||
.Done(c => c.GetAllLogs().Any(l=>l.Level == "error")) | ||
.Repeat(r=>r.For(ScenarioDescriptors.Transports.Msmq)) | ||
.Should(c => | ||
{ | ||
var logs = c.GetAllLogs(); | ||
Assert.True(logs.Any(l => l.Message.Contains("is corrupt and will be moved to"))); | ||
}) | ||
.Run(new RunSettings | ||
{ | ||
UseSeparateAppDomains = true | ||
}); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
} | ||
|
||
public class Sender : EndpointConfigurationBuilder | ||
{ | ||
public Sender() | ||
{ | ||
EndpointSetup<DefaultServer>() | ||
.AddMapping<Message>(typeof(Receiver)); | ||
} | ||
} | ||
|
||
public class Receiver : EndpointConfigurationBuilder | ||
{ | ||
public Receiver() | ||
{ | ||
SerializerCorrupter.Corrupt(); | ||
EndpointSetup<DefaultServer>(); | ||
} | ||
|
||
} | ||
|
||
[Serializable] | ||
public class Message : IMessage | ||
{ | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
.../Cant_convert_to_TransportMessage/When_cant_convert_to_TransportMessage_NoTransactions.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,60 @@ | ||
namespace NServiceBus.AcceptanceTests.Exceptions | ||
{ | ||
using System; | ||
using System.Linq; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTesting.Support; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
using IMessage = NServiceBus.IMessage; | ||
|
||
public class When_cant_convert_to_TransportMessage_NoTransactions : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Should_send_message_to_error_queue() | ||
{ | ||
Scenario.Define<Context>() | ||
.WithEndpoint<Sender>(b => b.Given(bus => bus.Send(new Message()))) | ||
.WithEndpoint<Receiver>() | ||
.AllowExceptions() | ||
.Done(c => c.GetAllLogs().Any(l=>l.Level == "error")) | ||
.Repeat(r=>r.For(ScenarioDescriptors.Transports.Msmq)) | ||
.Should(c => | ||
{ | ||
var logs = c.GetAllLogs(); | ||
Assert.True(logs.Any(l => l.Message.Contains("is corrupt and will be moved to"))); | ||
}) | ||
.Run(new RunSettings | ||
{ | ||
UseSeparateAppDomains = true | ||
}); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
} | ||
|
||
public class Sender : EndpointConfigurationBuilder | ||
{ | ||
public Sender() | ||
{ | ||
EndpointSetup<DefaultServer>(b => b.Transactions().Disable()) | ||
.AddMapping<Message>(typeof(Receiver)); | ||
} | ||
} | ||
|
||
public class Receiver : EndpointConfigurationBuilder | ||
{ | ||
public Receiver() | ||
{ | ||
SerializerCorrupter.Corrupt(); | ||
EndpointSetup<DefaultServer>(b => b.Transactions().Disable()); | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class Message : IMessage | ||
{ | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...s/Cant_convert_to_TransportMessage/When_cant_convert_to_TransportMessage_SuppressedDTC.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,59 @@ | ||
namespace NServiceBus.AcceptanceTests.Exceptions | ||
{ | ||
using System; | ||
using System.Linq; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTesting.Support; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
|
||
public class When_cant_convert_to_TransportMessage_SuppressedDTC : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Should_send_message_to_error_queue() | ||
{ | ||
Scenario.Define<Context>() | ||
.WithEndpoint<Sender>(b => b.Given(bus => bus.Send(new Message()))) | ||
.WithEndpoint<Receiver>() | ||
.AllowExceptions() | ||
.Done(c => c.GetAllLogs().Any(l=>l.Level == "error")) | ||
.Repeat(r=>r.For(ScenarioDescriptors.Transports.Msmq)) | ||
.Should(c => | ||
{ | ||
var logs = c.GetAllLogs(); | ||
Assert.True(logs.Any(l => l.Message.Contains("is corrupt and will be moved to"))); | ||
}) | ||
.Run(new RunSettings | ||
{ | ||
UseSeparateAppDomains = true | ||
}); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
} | ||
|
||
public class Sender : EndpointConfigurationBuilder | ||
{ | ||
public Sender() | ||
{ | ||
EndpointSetup<DefaultServer>(b => b.Transactions().DisableDistributedTransactions()) | ||
.AddMapping<Message>(typeof(Receiver)); | ||
} | ||
} | ||
|
||
public class Receiver : EndpointConfigurationBuilder | ||
{ | ||
public Receiver() | ||
{ | ||
SerializerCorrupter.Corrupt(); | ||
EndpointSetup<DefaultServer>(b => b.Transactions().DisableDistributedTransactions()); | ||
} | ||
} | ||
|
||
[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
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,52 @@ | ||
namespace NServiceBus.Faults | ||
{ | ||
using System.Configuration; | ||
using NServiceBus.Config; | ||
using NServiceBus.Logging; | ||
using NServiceBus.Settings; | ||
using NServiceBus.Utils; | ||
|
||
static class ErrorQueueSettings | ||
{ | ||
public static Address GetConfiguredErrorQueue(ReadOnlySettings settings) | ||
{ | ||
var errorQueue = Address.Undefined; | ||
|
||
var section = settings.GetConfigSection<MessageForwardingInCaseOfFaultConfig>(); | ||
if (section != null) | ||
{ | ||
if (string.IsNullOrWhiteSpace(section.ErrorQueue)) | ||
{ | ||
throw new ConfigurationErrorsException( | ||
"'MessageForwardingInCaseOfFaultConfig' configuration section is found but 'ErrorQueue' value is missing." + | ||
"\n The following is an example for adding such a value to your app config: " + | ||
"\n <MessageForwardingInCaseOfFaultConfig ErrorQueue=\"error\"/> \n"); | ||
} | ||
|
||
Logger.Debug("Error queue retrieved from <MessageForwardingInCaseOfFaultConfig> element in config file."); | ||
|
||
errorQueue = Address.Parse(section.ErrorQueue); | ||
} | ||
else | ||
{ | ||
var registryErrorQueue = RegistryReader.Read("ErrorQueue"); | ||
if (!string.IsNullOrWhiteSpace(registryErrorQueue)) | ||
{ | ||
Logger.Debug("Error queue retrieved from registry settings."); | ||
errorQueue = Address.Parse(registryErrorQueue); | ||
} | ||
} | ||
|
||
if (errorQueue == Address.Undefined) | ||
{ | ||
throw new ConfigurationErrorsException("Faults forwarding requires an error queue to be specified. Please add a 'MessageForwardingInCaseOfFaultConfig' section to your app.config" + | ||
"\n or configure a global one using the powershell command: Set-NServiceBusLocalMachineSettings -ErrorQueue {address of error queue}"); | ||
} | ||
|
||
return errorQueue; | ||
|
||
} | ||
|
||
static ILog Logger = LogManager.GetLogger(typeof(ErrorQueueSettings)); | ||
} | ||
} |
Oops, something went wrong.