Skip to content

Commit 33b8d0f

Browse files
author
John Simons
committed
Merge branch 'hotfix-1.1.3'
2 parents d6246ee + 5ca1dfa commit 33b8d0f

File tree

4 files changed

+189
-100
lines changed

4 files changed

+189
-100
lines changed

src/NServiceBus.RabbitMQ.Tests/NServiceBus.RabbitMQ.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<Compile Include="RabbitMqContext.cs" />
7676
<Compile Include="TestCategory.cs" />
7777
<Compile Include="When_consuming_messages.cs" />
78+
<Compile Include="When_stopping_endpoint.cs" />
7879
<Compile Include="When_running_concurrent_units_of_work_and_distributed_tx.cs" />
7980
<Compile Include="When_sending_a_message_over_rabbitmq.cs" />
8081
<Compile Include="TransportMessageBuilder.cs" />

src/NServiceBus.RabbitMQ.Tests/RabbitMqContext.cs

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Collections.Concurrent;
5+
using System.Diagnostics;
56
using Config;
67
using EasyNetQ;
78
using NUnit.Framework;
@@ -20,7 +21,7 @@ protected void MakeSureQueueAndExchangeExists(string queueName)
2021
//to make sure we kill old subscriptions
2122
DeleteExchange(queueName);
2223

23-
routingTopology.Initialize(channel,queueName);
24+
routingTopology.Initialize(channel, queueName);
2425
}
2526
}
2627

@@ -33,14 +34,18 @@ void DeleteExchange(string exchangeName)
3334
{
3435
channel.ExchangeDelete(exchangeName);
3536
}
36-
// ReSharper disable EmptyGeneralCatchClause
37+
// ReSharper disable EmptyGeneralCatchClause
3738
catch (Exception)
38-
// ReSharper restore EmptyGeneralCatchClause
39+
// ReSharper restore EmptyGeneralCatchClause
3940
{
4041
}
4142
}
4243
}
4344

45+
public virtual int MaximumConcurrency
46+
{
47+
get { return 1; }
48+
}
4449

4550
[SetUp]
4651
public void SetUp()
@@ -50,27 +55,39 @@ public void SetUp()
5055

5156
var config = new ConnectionConfiguration();
5257
config.ParseHosts("localhost:5672");
53-
58+
5459
var selectionStrategy = new DefaultClusterHostSelectionStrategy<ConnectionFactoryInfo>();
5560
var connectionFactory = new ConnectionFactoryWrapper(config, selectionStrategy);
5661
connectionManager = new RabbitMqConnectionManager(connectionFactory, config);
5762

58-
unitOfWork = new RabbitMqUnitOfWork { ConnectionManager = connectionManager,UsePublisherConfirms = true,MaxWaitTimeForConfirms = TimeSpan.FromSeconds(10) };
63+
unitOfWork = new RabbitMqUnitOfWork
64+
{
65+
ConnectionManager = connectionManager,
66+
UsePublisherConfirms = true,
67+
MaxWaitTimeForConfirms = TimeSpan.FromSeconds(10)
68+
};
69+
70+
sender = new RabbitMqMessageSender
71+
{
72+
UnitOfWork = unitOfWork,
73+
RoutingTopology = routingTopology
74+
};
5975

60-
sender = new RabbitMqMessageSender { UnitOfWork = unitOfWork, RoutingTopology = routingTopology };
6176

77+
dequeueStrategy = new RabbitMqDequeueStrategy
78+
{
79+
ConnectionManager = connectionManager,
80+
PurgeOnStartup = true
81+
};
6282

63-
dequeueStrategy = new RabbitMqDequeueStrategy { ConnectionManager = connectionManager, PurgeOnStartup = true };
64-
6583
MakeSureQueueAndExchangeExists(ReceiverQueue);
6684

67-
6885

6986
MessagePublisher = new RabbitMqMessagePublisher
70-
{
71-
UnitOfWork = unitOfWork,
72-
RoutingTopology = routingTopology
73-
};
87+
{
88+
UnitOfWork = unitOfWork,
89+
RoutingTopology = routingTopology
90+
};
7491
subscriptionManager = new RabbitMqSubscriptionManager
7592
{
7693
ConnectionManager = connectionManager,
@@ -84,20 +101,22 @@ public void SetUp()
84101
return true;
85102
}, (s, exception) => { });
86103

87-
dequeueStrategy.Start(1);
104+
dequeueStrategy.Start(MaximumConcurrency);
88105
}
89106

90107

91108
[TearDown]
92109
public void TearDown()
93110
{
94111
if (dequeueStrategy != null)
112+
{
95113
dequeueStrategy.Stop();
96-
114+
}
115+
97116
connectionManager.Dispose();
98117
}
99118

100-
protected virtual string ExchangeNameConvention(Address address,Type eventType)
119+
protected virtual string ExchangeNameConvention(Address address, Type eventType)
101120
{
102121
return "amq.topic";
103122
}
@@ -107,24 +126,25 @@ protected TransportMessage WaitForMessage()
107126
{
108127
var waitTime = TimeSpan.FromSeconds(1);
109128

110-
if (System.Diagnostics.Debugger.IsAttached)
129+
if (Debugger.IsAttached)
130+
{
111131
waitTime = TimeSpan.FromMinutes(10);
132+
}
112133

113134
TransportMessage message;
114135
receivedMessages.TryTake(out message, waitTime);
115136

116137
return message;
117-
118138
}
119139

140+
protected const string ReceiverQueue = "testreceiver";
141+
protected RabbitMqMessagePublisher MessagePublisher;
142+
protected RabbitMqConnectionManager connectionManager;
143+
protected RabbitMqDequeueStrategy dequeueStrategy;
120144
BlockingCollection<TransportMessage> receivedMessages;
121145

122146
protected ConventionalRoutingTopology routingTopology;
123-
protected const string ReceiverQueue = "testreceiver";
124-
protected RabbitMqDequeueStrategy dequeueStrategy;
125-
protected RabbitMqConnectionManager connectionManager;
126147
protected RabbitMqMessageSender sender;
127-
protected RabbitMqMessagePublisher MessagePublisher;
128148
protected RabbitMqSubscriptionManager subscriptionManager;
129149
protected RabbitMqUnitOfWork unitOfWork;
130150
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace NServiceBus.Transports.RabbitMQ.Tests
2+
{
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using NUnit.Framework;
6+
7+
[TestFixture]
8+
public class When_stopping_endpoint : RabbitMqContext
9+
{
10+
[SetUp]
11+
public new void SetUp()
12+
{
13+
MakeSureQueueAndExchangeExists(ReceiverQueue);
14+
}
15+
16+
[Test, Explicit]
17+
public void Should__gracefully_shutdown()
18+
{
19+
dequeueStrategy.Stop();
20+
21+
var address = Address.Parse(ReceiverQueue);
22+
23+
Parallel.For(0, 2000, i =>
24+
sender.Send(new TransportMessage(), address));
25+
26+
dequeueStrategy.PurgeOnStartup = false;
27+
dequeueStrategy.Start(50);
28+
Thread.Sleep(10);
29+
dequeueStrategy.Stop();
30+
connectionManager.Dispose();
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)