Skip to content

Commit

Permalink
Merge branch 'hotfix-4.5.6' into support-4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Nov 25, 2014
2 parents cb8fbf5 + 2327b15 commit 3fceb46
Show file tree
Hide file tree
Showing 17 changed files with 383 additions and 75 deletions.
26 changes: 26 additions & 0 deletions src/NServiceBus.AcceptanceTesting/ScenarioContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace NServiceBus.AcceptanceTesting
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
Expand Down Expand Up @@ -61,5 +63,29 @@ public IMessage SyncProcessMessage(IMessage msg)

public bool EndpointsStarted { get; set; }
public string Exceptions { get; set; }

public void RecordLog(string endpointName, string level, string message)
{
endpointLogs.Add(new EndpointLogItem
{
Endpoint = endpointName,
Level = level.ToLower(),
Message = message
});
}

public List<EndpointLogItem> GetAllLogs()
{
return endpointLogs.ToList();
}

List<EndpointLogItem> endpointLogs = new List<EndpointLogItem>();

public class EndpointLogItem
{
public string Endpoint { get; set; }
public string Message { get; set; }
public string Level { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace NServiceBus.AcceptanceTests.BasicMessaging
{
using System;
using NUnit.Framework;

public class When_starting_a_send_only : NServiceBusAcceptanceTest
{
[Test]
public void Should_not_need_audit_or_fault_forwarding_config_to_start()
{
using ((IDisposable)Configure.With(new Type[]
{
})
.DefaultBuilder()
.UnicastBus()
.SendOnly())
{
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ protected override void Append(LoggingEvent loggingEvent)
context.Exceptions += loggingEvent.ExceptionObject + "/n/r";
}
}
if (loggingEvent.Level >= Level.Warn)
{
context.RecordLog(endpointConfiguration.EndpointName, loggingEvent.Level.ToString(), loggingEvent.RenderedMessage);
}

}

Expand Down
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.Transports.Msmq.MsmqUtilities, NServiceBus.Core");
var headerSerializerField = msmqUtilitiesType.GetField("headerSerializer", BindingFlags.Static | BindingFlags.NonPublic);
headerSerializerField.SetValue(null, null);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace NServiceBus.AcceptanceTests.Exceptions
{
using System;
using System.Linq;
using NServiceBus.AcceptanceTesting;
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>()
.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();
}

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>()
.AllowExceptions();
}

}

[Serializable]
public class Message : IMessage
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace NServiceBus.AcceptanceTests.Exceptions
{
using System;
using System.Linq;
using NServiceBus.AcceptanceTesting;
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>()
.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();
}

public class Context : ScenarioContext
{
}

public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
Configure.Transactions.Disable();
EndpointSetup<DefaultServer>()
.AddMapping<Message>(typeof(Receiver));
}
}

public class Receiver : EndpointConfigurationBuilder
{
public Receiver()
{
SerializerCorrupter.Corrupt();
Configure.Transactions.Disable();
EndpointSetup<DefaultServer>()
.AllowExceptions();
}
}

[Serializable]
public class Message : IMessage
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace NServiceBus.AcceptanceTests.Exceptions
{
using System;
using System.Linq;
using NServiceBus.AcceptanceTesting;
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>()
.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();
}

public class Context : ScenarioContext
{
}

public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
Configure.Transactions.Advanced(settings => settings.DisableDistributedTransactions());
EndpointSetup<DefaultServer>()
.AddMapping<Message>(typeof(Receiver));
}
}

public class Receiver : EndpointConfigurationBuilder
{
public Receiver()
{
SerializerCorrupter.Corrupt();
Configure.Transactions.Advanced(settings => settings.DisableDistributedTransactions());
EndpointSetup<DefaultServer>()
.AllowExceptions();
}
}

[Serializable]
public class Message : IMessage
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="BasicMessaging\When_starting_a_send_only.cs" />
<Compile Include="BasicMessaging\When_using_a_greedy_convention.cs" />
<Compile Include="BasicMessaging\When_using_a_message_with_TimeToBeReceived_has_not_expired.cs" />
<Compile Include="BasicMessaging\When_using_a_message_with_TimeToBeReceived_has_expired.cs" />
<Compile Include="BasicMessaging\When_Deferring_a_message.cs" />
<Compile Include="BusStartStop\When_bus_start_raises_an_inmemory_message.cs" />
<Compile Include="Exceptions\Cant_convert_to_TransportMessage\When_cant_convert_to_TransportMessage.cs" />
<Compile Include="Exceptions\Cant_convert_to_TransportMessage\When_cant_convert_to_TransportMessage_NoTransactions.cs" />
<Compile Include="Exceptions\Cant_convert_to_TransportMessage\When_cant_convert_to_TransportMessage_SuppressedDTC.cs" />
<Compile Include="Exceptions\Cant_convert_to_TransportMessage\SerializerCorrupter.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" />
Expand Down
48 changes: 3 additions & 45 deletions src/NServiceBus.Core/ConfigureFaultsForwarder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
namespace NServiceBus
{
using System.Configuration;
using Config;
using Faults;
using Faults.Forwarder;
using Logging;
using Settings;
using Utils;

/// <summary>
/// Contains extension methods to NServiceBus.Configure
Expand All @@ -27,45 +23,9 @@ public static Configure MessageForwardingInCaseOfFault(this Configure config)
return config;
}

ErrorQueue = Address.Undefined;

var section = Configure.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);

config.Configurer.ConfigureComponent<FaultManager>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(fm => fm.ErrorQueue, ErrorQueue);

return config;
}


var errorQueue = RegistryReader<string>.Read("ErrorQueue");
if (!string.IsNullOrWhiteSpace(errorQueue))
{
Logger.Debug("Error queue retrieved from registry settings.");
ErrorQueue = Address.Parse(errorQueue);

config.Configurer.ConfigureComponent<FaultManager>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(fm => fm.ErrorQueue, ErrorQueue);
}

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}");
}
ErrorQueue = config.GetConfiguredErrorQueue();
config.Configurer.ConfigureComponent<FaultManager>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(fm => fm.ErrorQueue, ErrorQueue);

return config;
}
Expand All @@ -74,8 +34,6 @@ public static Configure MessageForwardingInCaseOfFault(this Configure config)
/// The queue to which to forward errors.
/// </summary>
public static Address ErrorQueue { get; private set; }

static readonly ILog Logger = LogManager.GetLogger(typeof(ConfigureFaultsForwarder));
}

class Bootstrapper : INeedInitialization
Expand Down
Loading

0 comments on commit 3fceb46

Please sign in to comment.