Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove subscription versioning for MSMQ and InMemory subscriptions #4177

Merged
merged 2 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
<Compile Include="Msmq\ConnectionStringParserTests.cs" />
<Compile Include="ObservableTests.cs" />
<Compile Include="Persistence\InMemory\InMemorySagaPersistenceFixture.cs" />
<Compile Include="Persistence\InMemory\InMemorySubscriptionStorageTests.cs" />
<Compile Include="Persistence\Msmq\MsmqSubscriptionStorageTests.cs" />
<Compile Include="Persistence\PersistenceExtentionsTests.cs" />
<Compile Include="Persistence\PersistenceStorageMergerTests.cs" />
<Compile Include="Sagas\SagaModelTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace NServiceBus.Persistence.InMemory.Tests
{
using System.Linq;
using NServiceBus.InMemory.SubscriptionStorage;
using NServiceBus.Unicast.Subscriptions;
using NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions;
using NUnit.Framework;

[TestFixture]
class InMemorySubscriptionStorageTests
{
[Test]
public void Should_ignore_message_version_on_subscriptions()
{
ISubscriptionStorage storage = new InMemorySubscriptionStorage();

storage.Subscribe(new Address("subscriberA", "subscriberA"), new[]
{
new MessageType("SomeMessage", "1.0.0")
});

var subscribers = storage.GetSubscriberAddressesForMessage(new[]
{
new MessageType("SomeMessage", "2.0.0")
});

Assert.AreEqual("subscriberA", subscribers.Single().Queue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace NServiceBus.Core.Tests.Persistence.Msmq
{
using System;
using System.Linq;
using System.Messaging;
using NServiceBus.Persistence.SubscriptionStorage;
using NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions;
using NUnit.Framework;
using MessageType = NServiceBus.Unicast.Subscriptions.MessageType;

public class MsmqSubscriptionStorageTests
{
[Test]
public void Should_ignore_message_version_on_subscriptions()
{
var testQueueName = "ShouldIgnoreMessageVersionOnSubscriptions";
var testQueueNativeAddress = Environment.MachineName + MsmqUtilities.PRIVATE + testQueueName;

if (MessageQueue.Exists(testQueueNativeAddress))
{
new MessageQueue(testQueueNativeAddress).Purge();
}
else
{
MessageQueue.Create(testQueueNativeAddress);
}

ISubscriptionStorage subscriptionStorage = new MsmqSubscriptionStorage
{
Queue = Address.Parse(testQueueName)
};

subscriptionStorage.Init();

subscriptionStorage.Subscribe(new Address("subscriberA", "server1"), new[] { new MessageType("SomeMessage", "1.0.0") });


var subscribers = subscriptionStorage.GetSubscriberAddressesForMessage(new[]
{
new MessageType("SomeMessage", "2.0.0")
});

Assert.AreEqual("subscriberA", subscribers.Single().Queue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ public MessageType(Type type)
}

/// <summary>
/// Initializes the message type from the given string.
/// Initializes the message type from the given string.
/// </summary>
public MessageType(string messageTypeString)
{
var parts = messageTypeString.Split(',');

Version = ParseVersion(messageTypeString);

Version = ParseVersion(messageTypeString);
TypeName = parts.First();
}

/// <summary>
/// Initializes the message type from the given string.
/// Initializes the message type from the given string.
/// </summary>
public MessageType(string typeName, string versionString)
{
Expand All @@ -39,20 +39,20 @@ public MessageType(string typeName, string versionString)
}

/// <summary>
/// Initializes the message type from the given string.
/// Initializes the message type from the given string.
/// </summary>
public MessageType(string typeName,Version version)
public MessageType(string typeName, Version version)
{
Version = version;
TypeName = typeName;
}

Version ParseVersion(string versionString)
{
const string version = "Version=";
var index = versionString.IndexOf(version);
if(index >= 0)

if (index >= 0)
versionString = versionString.Substring(index + version.Length)
.Split(',').First();
return Version.Parse(versionString);
Expand All @@ -62,7 +62,7 @@ Version ParseVersion(string versionString)
/// <summary>
/// TypeName of the message
/// </summary>
public string TypeName { get;private set; }
public string TypeName { get; private set; }

/// <summary>
/// Version of the message
Expand All @@ -84,7 +84,7 @@ public bool Equals(MessageType other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other.TypeName, TypeName) && other.Version.Major == Version.Major;
return Equals(other.TypeName, TypeName);
}

/// <summary>
Expand All @@ -94,19 +94,16 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (MessageType)) return false;
return Equals((MessageType) obj);
if (obj.GetType() != typeof(MessageType)) return false;
return Equals((MessageType)obj);
}

/// <summary>
/// Gets Hash Code
/// </summary>
public override int GetHashCode()
{
unchecked
{
return (TypeName.GetHashCode()*397) ^ Version.GetHashCode();
}
return TypeName.GetHashCode();
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/NServiceBus.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>



Expand Down