Skip to content

Commit

Permalink
Merge branch 'hotfix-4.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
indualagarsamy committed Dec 15, 2013
2 parents 21092c7 + 16f87d2 commit 792cd5c
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 72 deletions.
Expand Up @@ -8,16 +8,20 @@

public class When_publishing_an_event_using_a_broker_transport_with_centralized_routing : NServiceBusAcceptanceTest
{
[Test, Ignore("Not reliable!")]
[Test, Ignore] // Ignore because, test this test is unreliable. Passed on the build server without the core fix!
public void Should_be_delivered_to_allsubscribers_without_the_need_for_config()
{
Scenario.Define<Context>()
.WithEndpoint<CentralizedPublisher>(b => b.When(c => c.EndpointsStarted, (bus, context) =>
{
bus.Publish(new MyEvent());
}))
.WithEndpoint<CentralizedSubscriber1>()
.WithEndpoint<CentralizedSubscriber2>()
.WithEndpoint<CentralizedPublisher>
(b => b.When(c => c.IsSubscriptionProcessedForSub1 && c.IsSubscriptionProcessedForSub2, bus => bus.Publish(new MyEvent())))
.WithEndpoint<CentralizedSubscriber1>(b => b.Given((bus, context) =>
{
context.IsSubscriptionProcessedForSub1 = true;
}))
.WithEndpoint<CentralizedSubscriber2>(b => b.Given((bus, context) =>
{
context.IsSubscriptionProcessedForSub2 = true;
}))
.Done(c => c.Subscriber1GotTheEvent && c.Subscriber2GotTheEvent)
.Repeat(r => r.For<AllTransportsWithCentralizedPubSubSupport>())
.Should(c =>
Expand All @@ -32,8 +36,10 @@ public void Should_be_delivered_to_allsubscribers_without_the_need_for_config()
public class Context : ScenarioContext
{
public bool Subscriber1GotTheEvent { get; set; }

public bool Subscriber2GotTheEvent { get; set; }

public bool IsSubscriptionProcessedForSub1 { get; set; }
public bool IsSubscriptionProcessedForSub2 { get; set; }
}

public class CentralizedPublisher : EndpointConfigurationBuilder
Expand Down
Expand Up @@ -46,6 +46,39 @@ public class Context : ScenarioContext
public bool IsEventSubscriptionReceived { get; set; }
}


[Test]
public void Should_start_the_saga_when_set_up_to_start_for_the_base_event()
{
Scenario.Define<SagaContext>()
.WithEndpoint<SagaThatPublishesAnEvent>(b =>
b.Given(
(bus, context) =>
Subscriptions.OnEndpointSubscribed(s =>
{
if (s.SubscriberReturnAddress.Queue.Contains("SagaThatIsStartedByABaseEvent"))
{
context.IsEventSubscriptionReceived = true;
}
}))
.When(c => c.IsEventSubscriptionReceived,
bus =>
bus.Publish<SomethingHappenedEvent>(m=> { m.DataId = Guid.NewGuid(); }))
)
.WithEndpoint<SagaThatIsStartedByABaseEvent>(
b => b.Given((bus, context) => bus.Subscribe<BaseEvent>()))
.Done(c => c.DidSagaComplete)
.Repeat(r => r.For(Transports.Default))
.Should(c => Assert.True(c.DidSagaComplete))
.Run();
}

public class SagaContext : ScenarioContext
{
public bool IsEventSubscriptionReceived { get; set; }
public bool DidSagaComplete { get; set; }
}

public class SagaThatPublishesAnEvent : EndpointConfigurationBuilder
{
public SagaThatPublishesAnEvent()
Expand Down Expand Up @@ -125,13 +158,45 @@ public class Saga2Timeout
}
}

public class SagaThatIsStartedByABaseEvent : EndpointConfigurationBuilder
{
public SagaThatIsStartedByABaseEvent()
{
EndpointSetup<DefaultServer>(c => Configure.Features.Disable<AutoSubscribe>())
.AddMapping<BaseEvent>(typeof(SagaThatPublishesAnEvent));
}

public class SagaStartedByBaseEvent : Saga<SagaStartedByBaseEvent.SagaData>, IAmStartedByMessages<BaseEvent>
{
public SagaContext Context { get; set; }

public void Handle(BaseEvent message)
{
Data.DataId = message.DataId;
MarkAsComplete();
Context.DidSagaComplete = true;
}

public class SagaData : ContainSagaData
{
[Unique]
public virtual Guid DataId { get; set; }
}
}
}

[Serializable]
public class StartSaga : ICommand
{
public Guid DataId { get; set; }
}

public interface SomethingHappenedEvent : IEvent
public interface SomethingHappenedEvent : BaseEvent
{

}

public interface BaseEvent : IEvent
{
Guid DataId { get; set; }
}
Expand Down
@@ -0,0 +1,13 @@
namespace NServiceBus.Core.Tests.Fakes
{
using Transports;

public class FakeCentralizedPubSubTransportDefinition : TransportDefinition
{
public FakeCentralizedPubSubTransportDefinition()
{
HasNativePubSubSupport = true;
HasSupportForCentralizedPubSub = true;
}
}
}
1 change: 1 addition & 0 deletions src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj
Expand Up @@ -132,6 +132,7 @@
<Compile Include="Config\When_users_override_the_configuration_source.cs" />
<Compile Include="Config\When_using_convention_based_messages.cs" />
<Compile Include="Conventions\MessageConventionSpecs.cs" />
<Compile Include="Fakes\FakeCentralizedPubSubTransportDefinition.cs" />
<Compile Include="Licensing\LicenseDeserializerTests.cs" />
<Compile Include="Licensing\LicenseDowngraderTests.cs" />
<Compile Include="Licensing\NServiceBusVersionTests.cs" />
Expand Down
Expand Up @@ -53,14 +53,15 @@ public class using_a_configured_unicastBus
protected StaticMessageRouter router;

protected MessageHandlerRegistry handlerRegistry;
protected TransportDefinition transportDefinition;

PipelineFactory pipelineFactory;

[SetUp]
public void SetUp()
{


transportDefinition = new Msmq();
LicenseManager.Verify();
HandlerInvocationCache.Clear();

Expand Down Expand Up @@ -134,6 +135,8 @@ public void SetUp()

FuncBuilder.Register<CreatePhysicalMessageBehavior>(() => new CreatePhysicalMessageBehavior());
FuncBuilder.Register<PipelineFactory>(() => pipelineFactory);
FuncBuilder.Register<TransportDefinition>(() => transportDefinition);


var messagePublisher = new StorageDrivenPublisher
{
Expand Down
33 changes: 27 additions & 6 deletions src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs
Expand Up @@ -2,8 +2,9 @@ namespace NServiceBus.Unicast.Tests
{
using System;
using Contexts;
using Core.Tests.Fakes;
using NUnit.Framework;

[TestFixture]
public class When_subscribing_to_messages : using_the_unicastBus
{
Expand All @@ -16,6 +17,7 @@ public new void SetUp()
{
router.RegisterMessageRoute(typeof(TestMessage), addressToOwnerOfTestMessage);
}

[Test]
public void Should_send_the_assemblyQualified_name_as_subscription_type()
{
Expand All @@ -38,24 +40,43 @@ public void Should_set_the_message_intent_to_subscribe()
}

[TestFixture]
public class When_subscribing_to_a_message_that_has_no_configured_address : using_the_unicastBus
public class When_using_a_non_centralized_pub_sub_transport : using_the_unicastBus
{
[Test]
public void Should_throw()
public void Should_throw_when_subscribing_to_a_message_that_has_no_configured_address()
{
Assert.Throws<InvalidOperationException>(() => bus.Subscribe<EventMessage>());
}

[Test]
public void Should_throw_when_unsubscribing_to_a_message_that_has_no_configured_address()
{
Assert.Throws<InvalidOperationException>(() => bus.Unsubscribe<EventMessage>());
}
}

[TestFixture]
public class When_unsubscribing_to_a_message_that_has_no_configured_address : using_the_unicastBus
public class When_using_a_centralized_pub_sub_transport : using_the_unicastBus
{
[SetUp]
public new void SetUp()
{
transportDefinition = new FakeCentralizedPubSubTransportDefinition();
}

[Test]
public void Should_throw()
public void Should_not_throw_when_subscribing_to_a_message_that_has_no_configured_address()
{
Assert.Throws<InvalidOperationException>(() => bus.Unsubscribe<EventMessage>());
Assert.DoesNotThrow(() => bus.Subscribe<EventMessage>());
}

[Test]
public void Should_not_throw_When_unsubscribing_to_a_message_that_has_no_configured_address()
{
Assert.DoesNotThrow(() => bus.Unsubscribe<EventMessage>());
}
}

[TestFixture]
public class When_subscribing_to_command_messages : using_the_unicastBus
{
Expand Down
8 changes: 7 additions & 1 deletion src/NServiceBus.Core/ConfigureQueueCreation.cs
@@ -1,5 +1,7 @@
namespace NServiceBus
{
using System.ComponentModel;

/// <summary>
/// Contains extension methods to NServiceBus.Configure.
/// </summary>
Expand All @@ -15,6 +17,10 @@ public static Configure DoNotCreateQueues(this Configure config)
return config;
}

internal static bool DontCreateQueues { get; private set; }
/// <summary>
/// Gets whether or not queues should be created
/// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static bool DontCreateQueues { get; private set; }
}
}
8 changes: 7 additions & 1 deletion src/NServiceBus.Core/Licensing/LicenseExpiredForm.cs
Expand Up @@ -12,7 +12,13 @@ partial class LicenseExpiredForm : Form
static ILog Logger = LogManager.GetLogger(typeof(LicenseExpiredForm));
public LicenseExpiredForm()
{
InitializeComponent();
InitializeComponent();
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Visible = true;
}

void browseButton_Click(object sender, EventArgs e)
Expand Down
6 changes: 3 additions & 3 deletions src/NServiceBus.Core/Licensing/LicenseExpiredForm.resx
Expand Up @@ -118,11 +118,11 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="richTextBox1.Text" xml:space="preserve">
<value>Your license has enxpired and a new license is needed to continue
<value>Your license has expired and a new license is needed to continue.

Please purchase a license online or browse for a license file
Please purchase a license online or browse for a license file.

If you close this dialog NServiceBus will fall back to running in basic mode</value>
If you close this dialog NServiceBus will fall back to running in basic mode.</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Expand Down
1 change: 1 addition & 0 deletions src/NServiceBus.Core/NServiceBus.Core.csproj
Expand Up @@ -149,6 +149,7 @@
<Compile Include="MessageMutator\ApplyIncomingTransportMessageMutatorsBehavior.cs" />
<Compile Include="Audit\AuditBehavior.cs" />
<Compile Include="Sagas\SagaSendBehavior.cs" />
<Compile Include="Transports\ConfigureTransport.cs" />
<Compile Include="TypesToBeRemovedInVersion5.cs" />
<Compile Include="Unicast\Behaviors\CallbackInvocationBehavior.cs" />
<Compile Include="Unicast\Behaviors\ForwardBehavior.cs" />
Expand Down
6 changes: 5 additions & 1 deletion src/NServiceBus.Core/Sagas/Sagas.cs
Expand Up @@ -122,13 +122,17 @@ public static bool ShouldMessageStartSaga(Type sagaType, Type messageType)
if (messageTypes == null)
return false;

return messageTypes.Contains(messageType);
if (messageTypes.Contains(messageType))
return true;

return messageTypes.Any(msgTypeHandleBySaga => msgTypeHandleBySaga.IsAssignableFrom(messageType));
}

/// <summary>
/// Gets the saga type to instantiate and invoke if an existing saga couldn't be found by
/// the given finder using the given message.
/// </summary>
[ObsoleteEx(RemoveInVersion = "5.0", TreatAsErrorFromVersion = "4.4")]
public static Type GetSagaTypeToStartIfMessageNotFoundByFinder(object message, IFinder finder)
{
Type sagaEntityType;
Expand Down
53 changes: 53 additions & 0 deletions src/NServiceBus.Core/Transports/ConfigureTransport.cs
@@ -0,0 +1,53 @@
namespace NServiceBus.Transports
{
using System;
using Features;
using Settings;
using Unicast.Transport;

public abstract class ConfigureTransport<T> : Feature, IConfigureTransport<T> where T : TransportDefinition
{
public void Configure(Configure config)
{
var connectionString = TransportConnectionString.GetConnectionStringOrNull();

if (connectionString == null && RequiresConnectionString)
{
throw new InvalidOperationException(String.Format(Message, GetConfigFileIfExists(), typeof(T).Name, ExampleConnectionStringForErrorMessage));
}

SettingsHolder.Set("NServiceBus.Transport.ConnectionString", connectionString);

var selectedTransportDefinition = Activator.CreateInstance<T>();
SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", selectedTransportDefinition);
config.Configurer.RegisterSingleton<TransportDefinition>(selectedTransportDefinition);
InternalConfigure(config);
}

protected abstract void InternalConfigure(Configure config);

protected abstract string ExampleConnectionStringForErrorMessage { get; }

protected virtual bool RequiresConnectionString
{
get { return true; }
}


static string GetConfigFileIfExists()
{
return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile ?? "App.config";
}

const string Message =
@"No default connection string found in your config file ({0}) for the {1} Transport.
To run NServiceBus with {1} Transport you need to specify the database connectionstring.
Here is an example of what is required:
<connectionStrings>
<add name=""NServiceBus/Transport"" connectionString=""{2}"" />
</connectionStrings>";

}
}

0 comments on commit 792cd5c

Please sign in to comment.