Skip to content

Commit

Permalink
Merge branch 'release-3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonPobiega committed Jul 12, 2017
2 parents 89308d1 + 6ed60e3 commit ad7ae18
Show file tree
Hide file tree
Showing 429 changed files with 6,280 additions and 24,022 deletions.
6 changes: 3 additions & 3 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
assembly-versioning-scheme: Major
next-version: 3.0
next-version: 3.1
branches:
develop:
tag: alpha
releases?[/-]:
tag: rc
release:
tag: rc
2 changes: 1 addition & 1 deletion packaging/nuget/NServiceBus.SqlServer.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
</dependencies>
</metadata>
<files>
<file src="..\..\binaries\NServiceBus.Transport.SqlServer.???" target="lib\net452" />
<file src="..\..\binaries\net452\NServiceBus.Transport.SqlServer.???" target="lib\net452" />
</files>
</package>
61 changes: 61 additions & 0 deletions src/CompatibilityTests/Facade_1.2/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Configuration;
using System.Linq;
using System.Reflection;

public abstract class AppConfig : IDisposable
{
public static AppConfig Change(string path)
{
return new ChangeAppConfig(path);
}

public abstract void Dispose();

class ChangeAppConfig : AppConfig
{
string oldConfig = AppDomain.CurrentDomain.GetData("APP_CONFIG_FILE").ToString();

bool disposedValue;

public ChangeAppConfig(string path)
{
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);
ResetConfigMechanism();
}

public override void Dispose()
{
if (!disposedValue)
{
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", oldConfig);
ResetConfigMechanism();

disposedValue = true;
}
GC.SuppressFinalize(this);
}

static void ResetConfigMechanism()
{
typeof(ConfigurationManager)
.GetField("s_initState", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, 0);

typeof(ConfigurationManager)
.GetField("s_configSystem", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, null);

typeof(ConfigurationManager)
.Assembly.GetTypes()
.Where(x => x.FullName ==
"System.Configuration.ClientConfigPaths")
.First()
.GetField("s_current", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, null);
}
}
}
34 changes: 34 additions & 0 deletions src/CompatibilityTests/Facade_1.2/AppConfigGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;

class AppConfigGenerator
{
public static FileInfo Generate(string connectionString, List<ConnectionStringOverrides> connectionStrings)
{
var nodes = CreateConnectionStringNode(null, connectionString);

nodes = connectionStrings.Aggregate(nodes, (current, m) => current + CreateConnectionStringNode(m.Address, m.ConnectionString));

var content = $@"<?xml version='1.0' encoding='utf-8'?>
<configuration>
<connectionStrings>
<clear />
{nodes}
</connectionStrings>
</configuration>";

File.WriteAllText("custom-app.config", content);

return new FileInfo("custom-app.config");
}


static string CreateConnectionStringNode(string name, string connectionString)
{
var connectionStringAttribute = connectionString;
var nameAttribute = name != null ? $"NServiceBus/Transport/{name}" : "NServiceBus/Transport";

return $@"<add name=""{nameAttribute}"" connectionString=""{connectionStringAttribute}"" />";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ConnectionStringOverrides
{
public string Address { get; set; }
public string ConnectionString { get; set; }
}
68 changes: 68 additions & 0 deletions src/CompatibilityTests/Facade_1.2/CustomConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Configuration;
using NServiceBus.Config;
using NServiceBus.Config.ConfigurationSource;

class CustomConfiguration : IConfigurationSource
{
List<MessageEndpointMapping> messageMappings = new List<MessageEndpointMapping>();

public void AddMapping(MessageEndpointMapping mapping)
{
messageMappings.Add(mapping);
}

public T GetConfiguration<T>() where T : class, new()
{
if (typeof(T) == typeof(MessageForwardingInCaseOfFaultConfig))
{
return new MessageForwardingInCaseOfFaultConfig
{
ErrorQueue = "error"
} as T;
}

if (typeof(T) == typeof(UnicastBusConfig))
{
var endpointMappingsCollection = new MessageEndpointMappingCollection();

foreach (var em in messageMappings)
{
endpointMappingsCollection.Add(em);
}

return new UnicastBusConfig
{
MessageEndpointMappings = endpointMappingsCollection,
} as T;
}

if (typeof(T) == typeof(TransportConfig))
{
return new TransportConfig
{
MaxRetries = 0,
} as T;
}

if (typeof(T) == typeof(AuditConfig))
{
return new AuditConfig
{
QueueName = "audit"
}
as T;
}

if (typeof(T) == typeof(SecondLevelRetriesConfig))
{
return new SecondLevelRetriesConfig
{
NumberOfRetries = 0
} as T;
}

// leaving the rest of the configuration as is:
return ConfigurationManager.GetSection(typeof(T).Name) as T;
}
}
147 changes: 147 additions & 0 deletions src/CompatibilityTests/Facade_1.2/EndpointFacade.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CompatibilityTests.Common;
using CompatibilityTests.Common.Messages;
using NServiceBus;
using NServiceBus.Config;
using NServiceBus.Features;
using NServiceBus.Support;
using NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions;

class EndpointFacade : MarshalByRefObject, IEndpointFacade, IEndpointConfigurationV1
{
IBus bus;
IStartableBus startableBus;
MessageStore messageStore;
CallbackResultStore callbackResultStore;
SubscriptionStore subscriptionStore;
Configure configure;
List<ConnectionStringOverrides> connectionStringsOverrides = new List<ConnectionStringOverrides>();
CustomConfiguration customConfiguration;
string connectionString;

public void Dispose()
{
startableBus.Dispose();
}

public IEndpointConfiguration Bootstrap(EndpointDefinition endpointDefinition)
{
if (endpointDefinition.MachineName != null)
{
RuntimeEnvironment.MachineNameAction = () => endpointDefinition.MachineName;
}

configure = Configure.With();
configure.DefaultBuilder();

configure.DefineEndpointName(endpointDefinition.Name);
Address.InitializeLocalAddress(endpointDefinition.Name);

configure.DefiningMessagesAs(t => t.Namespace != null && t.Namespace.EndsWith(".Messages") && t != typeof(TestEvent));
configure.DefiningEventsAs(t => t == typeof(TestEvent));

configure.UseInMemoryTimeoutPersister();
configure.InMemorySubscriptionStorage();

customConfiguration = new CustomConfiguration();
configure.CustomConfigurationSource(customConfiguration);

Feature.Enable<MessageDrivenSubscriptions>();

configure.Configurer.ConfigureComponent<MessageStore>(DependencyLifecycle.SingleInstance);

return this;
}

public void UseConnectionString(string connectionString)
{
this.connectionString = connectionString;
}

public void MapMessageToEndpoint(Type messageType, string destination)
{
customConfiguration.AddMapping(new MessageEndpointMapping
{Endpoint = destination, Messages = messageType.AssemblyQualifiedName});
}

public void Start()
{
var configFile = AppConfigGenerator.Generate(connectionString, connectionStringsOverrides);

//HINT: we need to generate custom app.config because v1 sqltransports does a direct read from ConfigurationManager
using (AppConfig.Change(configFile.FullName))
{
configure.UseTransport<SqlServer>();

startableBus = configure.UnicastBus().CreateBus();
bus = startableBus.Start(() => configure.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());

messageStore = (MessageStore)configure.Builder.Build(typeof(MessageStore));
subscriptionStore = new SubscriptionStore();
callbackResultStore = new CallbackResultStore();

configure.Builder.Build<MessageDrivenSubscriptionManager>().ClientSubscribed += (sender, args) => { subscriptionStore.Increment(); };
}
}

public void ConfigureNamedConnectionStringForAddress(string endpoint, string connectionString)
{
connectionStringsOverrides.Add(new ConnectionStringOverrides
{
Address = endpoint,
ConnectionString = connectionString
});
}

public void SendCommand(Guid messageId)
{
bus.Send(new TestCommand { Id = messageId });
}

public void SendRequest(Guid requestId)
{
bus.Send(new TestRequest { RequestId = requestId });
}

public void PublishEvent(Guid eventId)
{
bus.Publish<TestEvent>(e => e.EventId = eventId);
}

public void SendAndCallbackForInt(int value)
{
Task.Run(async () =>
{
var callback = bus.Send(new TestIntCallback { Response = value });

var res = await callback.Register();

callbackResultStore.Add(res);
});
}

public void SendAndCallbackForEnum(CallbackEnum value)
{
Task.Run(async () =>
{
var res = await bus.Send(new TestEnumCallback { CallbackEnum = value }).Register<CallbackEnum>();

callbackResultStore.Add(res);
});
}

public Guid[] ReceivedMessageIds => messageStore.GetAll();

public Guid[] ReceivedResponseIds => messageStore.Get<TestResponse>();

public Guid[] ReceivedEventIds => messageStore.Get<TestEvent>();

public int[] ReceivedIntCallbacks => callbackResultStore.Get<int>();

public CallbackEnum[] ReceivedEnumCallbacks => callbackResultStore.Get<CallbackEnum>();

public int NumberOfSubscriptions => subscriptionStore.NumberOfSubscriptions;

}
15 changes: 15 additions & 0 deletions src/CompatibilityTests/Facade_1.2/Facade_1.2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<AssemblyName>Facade</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.0" />
<PackageReference Include="NServiceBus" Version="4.4.8" />
<PackageReference Include="NServiceBus.Interfaces" Version="4.4.8" />
<PackageReference Include="NServiceBus.SqlServer" Version="1.2.5" />
<ProjectReference Include="..\..\NServiceBus.SqlServer.CompatibilityTests.Common\NServiceBus.SqlServer.CompatibilityTests.Common.csproj" />
<Reference Include="System.Configuration" />
</ItemGroup>
</Project>
40 changes: 40 additions & 0 deletions src/CompatibilityTests/Facade_1.2/Handler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using CompatibilityTests.Common;
using CompatibilityTests.Common.Messages;
using NServiceBus;

public class Handler : IHandleMessages<TestCommand>, IHandleMessages<TestRequest>, IHandleMessages<TestResponse>, IHandleMessages<TestEvent>, IHandleMessages<TestIntCallback>, IHandleMessages<TestEnumCallback>
{
public IBus Bus { get; set; }

public MessageStore Store { get; set; }

public void Handle(TestCommand command)
{
Store.Add<TestCommand>(command.Id);
}

public void Handle(TestRequest message)
{
Bus.Reply(new TestResponse { ResponseId = message.RequestId });
}

public void Handle(TestResponse message)
{
Store.Add<TestResponse>(message.ResponseId);
}

public void Handle(TestEvent message)
{
Store.Add<TestEvent>(message.EventId);
}

public void Handle(TestIntCallback message)
{
Bus.Return(message.Response);
}

public void Handle(TestEnumCallback message)
{
Bus.Return(message.CallbackEnum);
}
}
Loading

0 comments on commit ad7ae18

Please sign in to comment.