Skip to content

Commit

Permalink
Merge branch 'hotfix-5.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Sep 13, 2015
2 parents 060dcee + 185de35 commit cd860c1
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
namespace NServiceBus.AcceptanceTests.HostInformation
{
using System;
using System.Collections.Concurrent;
using System.Reflection;
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTests.EndpointTemplates;
using NServiceBus.Features;
using NUnit.Framework;

public class When_feature_overrides_hostid : NServiceBusAcceptanceTest
{

[Test]
public void MD5_should_not_be_used()
{
var context = new Context();

Scenario.Define(context)
.WithEndpoint<MyEndpoint>(e => e.Given(b => b.SendLocal(new MyMessage())))
.Done(c => c.Done)
.Run();

Assert.IsTrue(context.NotSet);
}

public class MyEndpoint : EndpointConfigurationBuilder
{
public MyEndpoint()
{
EndpointSetup<DefaultServer>(c => c.UniquelyIdentifyRunningInstance().UsingCustomIdentifier(Guid.NewGuid()));
}
}

public class MyFeatureThatOverridesHostInformationDefaults : Feature
{
bool notSet;

public MyFeatureThatOverridesHostInformationDefaults()
{
EnableByDefault();
DependsOn("UnicastBus");
Defaults(s =>
{
// remove the override, we need to hack it via reflection!
var fieldInfo = s.GetType().GetField("Overrides", BindingFlags.Instance | BindingFlags.NonPublic);
var dictionary = (ConcurrentDictionary<string, object>)fieldInfo.GetValue(s);
object s2;
dictionary.TryRemove("NServiceBus.HostInformation.HostId", out s2);
// Try to get value, setting should not exist
notSet = !s.HasSetting("NServiceBus.HostInformation.HostId");
// Set override again so we have something
s.Set("NServiceBus.HostInformation.HostId", Guid.NewGuid());
});
}

protected override void Setup(FeatureConfigurationContext context)
{
context.Container.ConfigureProperty<Context>(c => c.NotSet, notSet);
}
}

public class MyMessageHandler : IHandleMessages<MyMessage>
{
public Context Context { get; set; }

public void Handle(MyMessage message)
{
Context.Done = true;
}
}

public class Context : ScenarioContext
{
public bool NotSet { get; set; }
public bool Done { get; set; }
}

[Serializable]
public class MyMessage : ICommand
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<Compile Include="Basic\When_TimeToBeReceived_has_expired.cs" />
<Compile Include="Basic\When_Deferring_a_message.cs" />
<Compile Include="Basic\When_using_callback_to_get_message.cs" />
<Compile Include="HostInformation\When_feature_overrides_hostid.cs" />
<Compile Include="PerfMon\CriticalTime\When_deferring_a_message.cs" />
<Compile Include="PubSub\When_publishing_from_sendonly.cs" />
<Compile Include="PubSub\When_publishing_an_event_implementing_two_unrelated_interfaces.cs" />
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
<Compile Include="Features\FeatureSettingsTests.cs" />
<Compile Include="Features\FeatureStartupTests.cs" />
<Compile Include="Features\FeatureTests.cs" />
<Compile Include="Hosting\When_creating_host_information_from_environment.cs" />
<Compile Include="Logging\RollingLoggerTests.cs" />
<Compile Include="Outbox\OutboxRecordBehaviorTests.cs" />
<Compile Include="Persistence\InMemory\AnotherSagaWithTwoUniquePropertiesData.cs" />
Expand Down Expand Up @@ -260,6 +259,7 @@
<Compile Include="Unicast\ConfigurationSettings.cs" />
<Compile Include="Unicast\ConfiguringMessageEndpointMapping.cs" />
<Compile Include="Unicast\Config\ConfigurationSettings.cs" />
<Compile Include="Unicast\Config\PathUtilities_Tests.cs" />
<Compile Include="Unicast\Contexts\CommandMessage.cs" />
<Compile Include="Unicast\Contexts\CommandWithDataBusPropertyMessage.cs" />
<Compile Include="Unicast\Contexts\EventMessage.cs" />
Expand Down
58 changes: 58 additions & 0 deletions src/NServiceBus.Core.Tests/Unicast/Config/PathUtilities_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace NServiceBus.Features.Tests
{
using NUnit.Framework;

[TestFixture]
public class PathUtilities_Tests
{
[Test]
public void Parse_from_path_without_spaces_but_with_quotes()
{
var path = PathUtilities.SanitizedPath("\"pathto\\mysuperduper.exe\" somevar");

Assert.AreEqual("pathto\\mysuperduper.exe", path);
}

[Test]
public void Parse_from_path_without_spaces_but_without_quotes()
{
var path = PathUtilities.SanitizedPath("pathto\\mysuperduper.exe somevar");

Assert.AreEqual("pathto\\mysuperduper.exe", path);
}

[Test]
public void Paths_without_spaces_are_equal()
{
var path1 = PathUtilities.SanitizedPath("\"pathto\\mysuperduper.exe\" somevar");
var path2 = PathUtilities.SanitizedPath("pathto\\mysuperduper.exe somevar");

Assert.AreEqual(path1, path2);
}

[Test]
public void Parse_from_path_with_spaces_having_a_parameter_with_spaces()
{
var path = PathUtilities.SanitizedPath("\"pathto\\mysuper duper.exe\" \"somevar with spaces\"");

Assert.AreEqual("pathto\\mysuper duper.exe", path);
}

[Test]
public void Parse_from_path_with_spaces_having_a_parameter_without_spaces()
{
var path = PathUtilities.SanitizedPath("\"pathto\\mysuper duper.exe\" somevar");

Assert.AreEqual("pathto\\mysuper duper.exe", path);
}

[Test]
public void Both_paths_with_spaces_are_equal()
{
var path1 = PathUtilities.SanitizedPath("\"pathto\\mysuper duper.exe\" \"somevar with spaces\"");
var path2 = PathUtilities.SanitizedPath("\"pathto\\mysuper duper.exe\" somevar");

Assert.AreEqual(path1, path2);
}
}
}
2 changes: 1 addition & 1 deletion src/NServiceBus.Core/NServiceBus.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@
<Compile Include="Unicast\Behaviors\InvokeSagaNotFoundBehavior.cs" />
<Compile Include="Unicast\BusAsyncResultEventArgs.cs" />
<Compile Include="Unicast\Config\LoadMessageHandlersExtentions_Obsolete.cs" />
<Compile Include="Unicast\Config\PathUtilities.cs" />
<Compile Include="Unicast\Config\RegisterHandlersInOrder.cs" />
<Compile Include="Monitoring\SLA\SLABehavior.cs" />
<Compile Include="Monitoring\CriticalTime\CriticalTimeBehavior.cs" />
<Compile Include="Monitoring\MonitoringConfig_Obsolete.cs" />
<Compile Include="Monitoring\SLA\SLAMonitoring.cs" />
<Compile Include="Monitoring\ProcessingStatisticsBehavior.cs" />
<Compile Include="Unicast\DefaultHostIdGenerator.cs" />
<Compile Include="Unicast\IMessageDispatcherFactory_Obsolete.cs" />
<Compile Include="MessageDeserializationException.cs" />
<Compile Include="Unicast\Transport\Config\TransportConfiguration.cs" />
Expand Down
19 changes: 19 additions & 0 deletions src/NServiceBus.Core/Unicast/Config/PathUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace NServiceBus.Features
{
using System.Linq;
using System.Text.RegularExpressions;

internal static class PathUtilities
{
public static string SanitizedPath(string commandLine)
{
if (commandLine.StartsWith("\""))
{
return (from Match match in Regex.Matches(commandLine, "\"([^\"]*)\"")
select match.ToString()).First().Trim('"');
}

return commandLine.Split(' ').First();
}
}
}
19 changes: 7 additions & 12 deletions src/NServiceBus.Core/Unicast/Config/UnicastBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NServiceBus.Features
using Logging;
using NServiceBus.Hosting;
using NServiceBus.Support;
using NServiceBus.Unicast;
using NServiceBus.Utils;
using Pipeline;
using Pipeline.Contexts;
using Transports;
Expand All @@ -26,8 +26,12 @@ internal UnicastBus()

Defaults(s =>
{
string fullPathToStartingExe;
s.SetDefault("NServiceBus.HostInformation.HostId", GenerateDefaultHostId(out fullPathToStartingExe));
var fullPathToStartingExe = PathUtilities.SanitizedPath(Environment.CommandLine);
if (!s.HasExplicitValue("NServiceBus.HostInformation.HostId"))
{
s.SetDefault("NServiceBus.HostInformation.HostId", DeterministicGuid.Create(fullPathToStartingExe, RuntimeEnvironment.MachineName));
}
s.SetDefault("NServiceBus.HostInformation.DisplayName", RuntimeEnvironment.MachineName);
s.SetDefault("NServiceBus.HostInformation.Properties", new Dictionary<string, string>
{
Expand Down Expand Up @@ -72,15 +76,6 @@ protected internal override void Setup(FeatureConfigurationContext context)
SetTransportThresholds(context);
}

static Guid GenerateDefaultHostId(out string fullPathToStartingExe)
{
var gen = new DefaultHostIdGenerator(Environment.CommandLine, RuntimeEnvironment.MachineName);

fullPathToStartingExe = gen.FullPathToStartingExe;

return gen.HostId;
}

void SetTransportThresholds(FeatureConfigurationContext context)
{
var transportConfig = context.Settings.GetConfigSection<TransportConfig>();
Expand Down
28 changes: 0 additions & 28 deletions src/NServiceBus.Core/Unicast/DefaultHostIdGenerator.cs

This file was deleted.

0 comments on commit cd860c1

Please sign in to comment.