Skip to content

Commit 792cd5c

Browse files
author
indualagarsamy
committed
Merge branch 'hotfix-4.3.1'
2 parents 21092c7 + 16f87d2 commit 792cd5c

15 files changed

+227
-72
lines changed

src/NServiceBus.AcceptanceTests/PubSub/When_publishing_an_event_using_a_broker_transport_with_centralized_routing.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
public class When_publishing_an_event_using_a_broker_transport_with_centralized_routing : NServiceBusAcceptanceTest
1010
{
11-
[Test, Ignore("Not reliable!")]
11+
[Test, Ignore] // Ignore because, test this test is unreliable. Passed on the build server without the core fix!
1212
public void Should_be_delivered_to_allsubscribers_without_the_need_for_config()
1313
{
1414
Scenario.Define<Context>()
15-
.WithEndpoint<CentralizedPublisher>(b => b.When(c => c.EndpointsStarted, (bus, context) =>
16-
{
17-
bus.Publish(new MyEvent());
18-
}))
19-
.WithEndpoint<CentralizedSubscriber1>()
20-
.WithEndpoint<CentralizedSubscriber2>()
15+
.WithEndpoint<CentralizedPublisher>
16+
(b => b.When(c => c.IsSubscriptionProcessedForSub1 && c.IsSubscriptionProcessedForSub2, bus => bus.Publish(new MyEvent())))
17+
.WithEndpoint<CentralizedSubscriber1>(b => b.Given((bus, context) =>
18+
{
19+
context.IsSubscriptionProcessedForSub1 = true;
20+
}))
21+
.WithEndpoint<CentralizedSubscriber2>(b => b.Given((bus, context) =>
22+
{
23+
context.IsSubscriptionProcessedForSub2 = true;
24+
}))
2125
.Done(c => c.Subscriber1GotTheEvent && c.Subscriber2GotTheEvent)
2226
.Repeat(r => r.For<AllTransportsWithCentralizedPubSubSupport>())
2327
.Should(c =>
@@ -32,8 +36,10 @@ public void Should_be_delivered_to_allsubscribers_without_the_need_for_config()
3236
public class Context : ScenarioContext
3337
{
3438
public bool Subscriber1GotTheEvent { get; set; }
35-
3639
public bool Subscriber2GotTheEvent { get; set; }
40+
41+
public bool IsSubscriptionProcessedForSub1 { get; set; }
42+
public bool IsSubscriptionProcessedForSub2 { get; set; }
3743
}
3844

3945
public class CentralizedPublisher : EndpointConfigurationBuilder

src/NServiceBus.AcceptanceTests/Sagas/When_a_saga_is_started_by_an_event_published_by_another_saga.cs

+66-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,39 @@ public class Context : ScenarioContext
4646
public bool IsEventSubscriptionReceived { get; set; }
4747
}
4848

49+
50+
[Test]
51+
public void Should_start_the_saga_when_set_up_to_start_for_the_base_event()
52+
{
53+
Scenario.Define<SagaContext>()
54+
.WithEndpoint<SagaThatPublishesAnEvent>(b =>
55+
b.Given(
56+
(bus, context) =>
57+
Subscriptions.OnEndpointSubscribed(s =>
58+
{
59+
if (s.SubscriberReturnAddress.Queue.Contains("SagaThatIsStartedByABaseEvent"))
60+
{
61+
context.IsEventSubscriptionReceived = true;
62+
}
63+
}))
64+
.When(c => c.IsEventSubscriptionReceived,
65+
bus =>
66+
bus.Publish<SomethingHappenedEvent>(m=> { m.DataId = Guid.NewGuid(); }))
67+
)
68+
.WithEndpoint<SagaThatIsStartedByABaseEvent>(
69+
b => b.Given((bus, context) => bus.Subscribe<BaseEvent>()))
70+
.Done(c => c.DidSagaComplete)
71+
.Repeat(r => r.For(Transports.Default))
72+
.Should(c => Assert.True(c.DidSagaComplete))
73+
.Run();
74+
}
75+
76+
public class SagaContext : ScenarioContext
77+
{
78+
public bool IsEventSubscriptionReceived { get; set; }
79+
public bool DidSagaComplete { get; set; }
80+
}
81+
4982
public class SagaThatPublishesAnEvent : EndpointConfigurationBuilder
5083
{
5184
public SagaThatPublishesAnEvent()
@@ -125,13 +158,45 @@ public class Saga2Timeout
125158
}
126159
}
127160

161+
public class SagaThatIsStartedByABaseEvent : EndpointConfigurationBuilder
162+
{
163+
public SagaThatIsStartedByABaseEvent()
164+
{
165+
EndpointSetup<DefaultServer>(c => Configure.Features.Disable<AutoSubscribe>())
166+
.AddMapping<BaseEvent>(typeof(SagaThatPublishesAnEvent));
167+
}
168+
169+
public class SagaStartedByBaseEvent : Saga<SagaStartedByBaseEvent.SagaData>, IAmStartedByMessages<BaseEvent>
170+
{
171+
public SagaContext Context { get; set; }
172+
173+
public void Handle(BaseEvent message)
174+
{
175+
Data.DataId = message.DataId;
176+
MarkAsComplete();
177+
Context.DidSagaComplete = true;
178+
}
179+
180+
public class SagaData : ContainSagaData
181+
{
182+
[Unique]
183+
public virtual Guid DataId { get; set; }
184+
}
185+
}
186+
}
187+
128188
[Serializable]
129189
public class StartSaga : ICommand
130190
{
131191
public Guid DataId { get; set; }
132192
}
133193

134-
public interface SomethingHappenedEvent : IEvent
194+
public interface SomethingHappenedEvent : BaseEvent
195+
{
196+
197+
}
198+
199+
public interface BaseEvent : IEvent
135200
{
136201
Guid DataId { get; set; }
137202
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace NServiceBus.Core.Tests.Fakes
2+
{
3+
using Transports;
4+
5+
public class FakeCentralizedPubSubTransportDefinition : TransportDefinition
6+
{
7+
public FakeCentralizedPubSubTransportDefinition()
8+
{
9+
HasNativePubSubSupport = true;
10+
HasSupportForCentralizedPubSub = true;
11+
}
12+
}
13+
}

src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<Compile Include="Config\When_users_override_the_configuration_source.cs" />
133133
<Compile Include="Config\When_using_convention_based_messages.cs" />
134134
<Compile Include="Conventions\MessageConventionSpecs.cs" />
135+
<Compile Include="Fakes\FakeCentralizedPubSubTransportDefinition.cs" />
135136
<Compile Include="Licensing\LicenseDeserializerTests.cs" />
136137
<Compile Include="Licensing\LicenseDowngraderTests.cs" />
137138
<Compile Include="Licensing\NServiceBusVersionTests.cs" />

src/NServiceBus.Core.Tests/Unicast/Contexts/using_the_unicastbus.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ public class using_a_configured_unicastBus
5353
protected StaticMessageRouter router;
5454

5555
protected MessageHandlerRegistry handlerRegistry;
56+
protected TransportDefinition transportDefinition;
5657

5758
PipelineFactory pipelineFactory;
5859

5960
[SetUp]
6061
public void SetUp()
6162
{
6263

63-
64+
transportDefinition = new Msmq();
6465
LicenseManager.Verify();
6566
HandlerInvocationCache.Clear();
6667

@@ -134,6 +135,8 @@ public void SetUp()
134135

135136
FuncBuilder.Register<CreatePhysicalMessageBehavior>(() => new CreatePhysicalMessageBehavior());
136137
FuncBuilder.Register<PipelineFactory>(() => pipelineFactory);
138+
FuncBuilder.Register<TransportDefinition>(() => transportDefinition);
139+
137140

138141
var messagePublisher = new StorageDrivenPublisher
139142
{

src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs

+27-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ namespace NServiceBus.Unicast.Tests
22
{
33
using System;
44
using Contexts;
5+
using Core.Tests.Fakes;
56
using NUnit.Framework;
6-
7+
78
[TestFixture]
89
public class When_subscribing_to_messages : using_the_unicastBus
910
{
@@ -16,6 +17,7 @@ public class When_subscribing_to_messages : using_the_unicastBus
1617
{
1718
router.RegisterMessageRoute(typeof(TestMessage), addressToOwnerOfTestMessage);
1819
}
20+
1921
[Test]
2022
public void Should_send_the_assemblyQualified_name_as_subscription_type()
2123
{
@@ -38,24 +40,43 @@ public void Should_set_the_message_intent_to_subscribe()
3840
}
3941

4042
[TestFixture]
41-
public class When_subscribing_to_a_message_that_has_no_configured_address : using_the_unicastBus
43+
public class When_using_a_non_centralized_pub_sub_transport : using_the_unicastBus
4244
{
4345
[Test]
44-
public void Should_throw()
46+
public void Should_throw_when_subscribing_to_a_message_that_has_no_configured_address()
4547
{
4648
Assert.Throws<InvalidOperationException>(() => bus.Subscribe<EventMessage>());
4749
}
50+
51+
[Test]
52+
public void Should_throw_when_unsubscribing_to_a_message_that_has_no_configured_address()
53+
{
54+
Assert.Throws<InvalidOperationException>(() => bus.Unsubscribe<EventMessage>());
55+
}
4856
}
4957

5058
[TestFixture]
51-
public class When_unsubscribing_to_a_message_that_has_no_configured_address : using_the_unicastBus
59+
public class When_using_a_centralized_pub_sub_transport : using_the_unicastBus
5260
{
61+
[SetUp]
62+
public new void SetUp()
63+
{
64+
transportDefinition = new FakeCentralizedPubSubTransportDefinition();
65+
}
66+
5367
[Test]
54-
public void Should_throw()
68+
public void Should_not_throw_when_subscribing_to_a_message_that_has_no_configured_address()
5569
{
56-
Assert.Throws<InvalidOperationException>(() => bus.Unsubscribe<EventMessage>());
70+
Assert.DoesNotThrow(() => bus.Subscribe<EventMessage>());
71+
}
72+
73+
[Test]
74+
public void Should_not_throw_When_unsubscribing_to_a_message_that_has_no_configured_address()
75+
{
76+
Assert.DoesNotThrow(() => bus.Unsubscribe<EventMessage>());
5777
}
5878
}
79+
5980
[TestFixture]
6081
public class When_subscribing_to_command_messages : using_the_unicastBus
6182
{

src/NServiceBus.Core/ConfigureQueueCreation.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace NServiceBus
22
{
3+
using System.ComponentModel;
4+
35
/// <summary>
46
/// Contains extension methods to NServiceBus.Configure.
57
/// </summary>
@@ -15,6 +17,10 @@ public static Configure DoNotCreateQueues(this Configure config)
1517
return config;
1618
}
1719

18-
internal static bool DontCreateQueues { get; private set; }
20+
/// <summary>
21+
/// Gets whether or not queues should be created
22+
/// </summary>
23+
[EditorBrowsable(EditorBrowsableState.Advanced)]
24+
public static bool DontCreateQueues { get; private set; }
1925
}
2026
}

src/NServiceBus.Core/Licensing/LicenseExpiredForm.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ partial class LicenseExpiredForm : Form
1212
static ILog Logger = LogManager.GetLogger(typeof(LicenseExpiredForm));
1313
public LicenseExpiredForm()
1414
{
15-
InitializeComponent();
15+
InitializeComponent();
16+
}
17+
18+
protected override void OnLoad(EventArgs e)
19+
{
20+
base.OnLoad(e);
21+
Visible = true;
1622
}
1723

1824
void browseButton_Click(object sender, EventArgs e)

src/NServiceBus.Core/Licensing/LicenseExpiredForm.resx

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<data name="richTextBox1.Text" xml:space="preserve">
121-
<value>Your license has enxpired and a new license is needed to continue
121+
<value>Your license has expired and a new license is needed to continue.
122122

123-
Please purchase a license online or browse for a license file
123+
Please purchase a license online or browse for a license file.
124124

125-
If you close this dialog NServiceBus will fall back to running in basic mode</value>
125+
If you close this dialog NServiceBus will fall back to running in basic mode.</value>
126126
</data>
127127
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
128128
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

src/NServiceBus.Core/NServiceBus.Core.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<Compile Include="MessageMutator\ApplyIncomingTransportMessageMutatorsBehavior.cs" />
150150
<Compile Include="Audit\AuditBehavior.cs" />
151151
<Compile Include="Sagas\SagaSendBehavior.cs" />
152+
<Compile Include="Transports\ConfigureTransport.cs" />
152153
<Compile Include="TypesToBeRemovedInVersion5.cs" />
153154
<Compile Include="Unicast\Behaviors\CallbackInvocationBehavior.cs" />
154155
<Compile Include="Unicast\Behaviors\ForwardBehavior.cs" />

src/NServiceBus.Core/Sagas/Sagas.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ public static bool ShouldMessageStartSaga(Type sagaType, Type messageType)
122122
if (messageTypes == null)
123123
return false;
124124

125-
return messageTypes.Contains(messageType);
125+
if (messageTypes.Contains(messageType))
126+
return true;
127+
128+
return messageTypes.Any(msgTypeHandleBySaga => msgTypeHandleBySaga.IsAssignableFrom(messageType));
126129
}
127130

128131
/// <summary>
129132
/// Gets the saga type to instantiate and invoke if an existing saga couldn't be found by
130133
/// the given finder using the given message.
131134
/// </summary>
135+
[ObsoleteEx(RemoveInVersion = "5.0", TreatAsErrorFromVersion = "4.4")]
132136
public static Type GetSagaTypeToStartIfMessageNotFoundByFinder(object message, IFinder finder)
133137
{
134138
Type sagaEntityType;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
namespace NServiceBus.Transports
2+
{
3+
using System;
4+
using Features;
5+
using Settings;
6+
using Unicast.Transport;
7+
8+
public abstract class ConfigureTransport<T> : Feature, IConfigureTransport<T> where T : TransportDefinition
9+
{
10+
public void Configure(Configure config)
11+
{
12+
var connectionString = TransportConnectionString.GetConnectionStringOrNull();
13+
14+
if (connectionString == null && RequiresConnectionString)
15+
{
16+
throw new InvalidOperationException(String.Format(Message, GetConfigFileIfExists(), typeof(T).Name, ExampleConnectionStringForErrorMessage));
17+
}
18+
19+
SettingsHolder.Set("NServiceBus.Transport.ConnectionString", connectionString);
20+
21+
var selectedTransportDefinition = Activator.CreateInstance<T>();
22+
SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", selectedTransportDefinition);
23+
config.Configurer.RegisterSingleton<TransportDefinition>(selectedTransportDefinition);
24+
InternalConfigure(config);
25+
}
26+
27+
protected abstract void InternalConfigure(Configure config);
28+
29+
protected abstract string ExampleConnectionStringForErrorMessage { get; }
30+
31+
protected virtual bool RequiresConnectionString
32+
{
33+
get { return true; }
34+
}
35+
36+
37+
static string GetConfigFileIfExists()
38+
{
39+
return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile ?? "App.config";
40+
}
41+
42+
const string Message =
43+
@"No default connection string found in your config file ({0}) for the {1} Transport.
44+
45+
To run NServiceBus with {1} Transport you need to specify the database connectionstring.
46+
Here is an example of what is required:
47+
48+
<connectionStrings>
49+
<add name=""NServiceBus/Transport"" connectionString=""{2}"" />
50+
</connectionStrings>";
51+
52+
}
53+
}

0 commit comments

Comments
 (0)