Skip to content

Commit 15a87c0

Browse files
Saibamenlukebakken
authored andcommitted
Back-port #1616 to 6.x
Fixes #1617 Update RecordedConsumer.cs Update RecordedExchange.cs Update RecordedQueue.cs Update projects/RabbitMQ.Client/client/impl/RecordedBinding.cs Update projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs Update projects/RabbitMQ.Client/client/impl/RecordedExchange.cs Update projects/RabbitMQ.Client/client/impl/RecordedQueue.cs Update projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs Update projects/RabbitMQ.Client/client/impl/RecordedBinding.cs Update projects/RabbitMQ.Client/client/impl/RecordedExchange.cs Update projects/RabbitMQ.Client/client/impl/RecordedQueue.cs Update `TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePassedDown` Update projects/Unit/TestConnectionRecovery.cs Port test from `main`
1 parent 8f32ba3 commit 15a87c0

File tree

5 files changed

+94
-9
lines changed

5 files changed

+94
-9
lines changed

projects/RabbitMQ.Client/client/impl/RecordedBinding.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ public override string ToString()
8585

8686
public RecordedBinding WithArguments(IDictionary<string, object> value)
8787
{
88-
Arguments = value;
88+
if (value is null)
89+
{
90+
Arguments = null;
91+
}
92+
else
93+
{
94+
Arguments = new Dictionary<string, object>(value);
95+
}
96+
8997
return this;
9098
}
9199

projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,15 @@ public string Recover(IModel channelToUse)
9797

9898
public RecordedConsumer WithArguments(IDictionary<string, object> value)
9999
{
100-
Arguments = value;
100+
if (value is null)
101+
{
102+
Arguments = null;
103+
}
104+
else
105+
{
106+
Arguments = new Dictionary<string, object>(value);
107+
}
108+
101109
return this;
102110
}
103111

projects/RabbitMQ.Client/client/impl/RecordedExchange.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ public override string ToString()
5757

5858
public RecordedExchange WithArguments(IDictionary<string, object> value)
5959
{
60-
Arguments = value;
60+
if (value is null)
61+
{
62+
Arguments = null;
63+
}
64+
else
65+
{
66+
Arguments = new Dictionary<string, object>(value);
67+
}
68+
6169
return this;
6270
}
6371

projects/RabbitMQ.Client/client/impl/RecordedQueue.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ protected string NameToUseForRecovery
6666

6767
public RecordedQueue WithArguments(IDictionary<string, object> value)
6868
{
69-
Arguments = value;
69+
if (value is null)
70+
{
71+
Arguments = null;
72+
}
73+
else
74+
{
75+
Arguments = new Dictionary<string, object>(value);
76+
}
77+
7078
return this;
7179
}
7280

projects/Unit/TestConnectionRecovery.cs

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,17 @@ public void TestRecoveringConsumerHandlerOnConnection()
744744
[Test]
745745
public void TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePassedDown()
746746
{
747-
var myArgs = new Dictionary<string, object> { { "first-argument", "some-value" } };
747+
const string key = "first-argument";
748+
const string value = "some-value";
749+
750+
IDictionary<string, object> arguments = new Dictionary<string, object>
751+
{
752+
{ key, value }
753+
};
754+
748755
string q = Model.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName;
749756
var cons = new EventingBasicConsumer(Model);
750-
string expectedCTag = Model.BasicConsume(cons, q, arguments: myArgs);
757+
string expectedCTag = Model.BasicConsume(cons, q, arguments: arguments);
751758

752759
bool ctagMatches = false;
753760
bool consumerArgumentMatches = false;
@@ -757,14 +764,15 @@ public void TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePassedDow
757764
// passed to a CallbackExceptionHandler, instead of failing the test. Instead, we have to do this trick
758765
// and assert in the test function.
759766
ctagMatches = args.ConsumerTag == expectedCTag;
760-
consumerArgumentMatches = (string)args.ConsumerArguments["first-argument"] == "some-value";
761-
args.ConsumerArguments["first-argument"] = "event-handler-set-this-value";
767+
consumerArgumentMatches = (string)args.ConsumerArguments[key] == value;
762768
};
763769

764770
CloseAndWaitForRecovery();
765771
Assert.That(ctagMatches, Is.True, "expected consumer tag to match");
766772
Assert.That(consumerArgumentMatches, Is.True, "expected consumer arguments to match");
767-
Assert.That(myArgs, Does.ContainKey("first-argument").WithValue("event-handler-set-this-value"));
773+
Assert.That(arguments.ContainsKey(key), Is.True);
774+
string actualVal = (string)arguments[key];
775+
Assert.That(actualVal, Is.EqualTo(value));
768776
}
769777

770778
[Test]
@@ -1687,6 +1695,51 @@ void MessageReceived(object sender, BasicDeliverEventArgs e)
16871695
}
16881696
}
16891697

1698+
[Test]
1699+
public void TestQueueRecoveryWithDlxArgument_RabbitMQUsers_hk5pJ4cKF0c()
1700+
{
1701+
string tdiWaitExchangeName = GenerateExchangeName();
1702+
string tdiRetryExchangeName = GenerateExchangeName();
1703+
string testRetryQueueName = GenerateQueueName();
1704+
string testQueueName = GenerateQueueName();
1705+
1706+
Model.ExchangeDeclare(exchange: tdiWaitExchangeName,
1707+
type: ExchangeType.Topic, durable: true, autoDelete: false, arguments: null);
1708+
Model.ExchangeDeclare(exchange: tdiRetryExchangeName,
1709+
type: ExchangeType.Topic, durable: true, autoDelete: false, arguments: null);
1710+
1711+
var arguments = new Dictionary<string, object>
1712+
{
1713+
{ "x-dead-letter-exchange", "tdi.retry.exchange" },
1714+
{ "x-dead-letter-routing-key", "QueueTest" }
1715+
};
1716+
1717+
Model.QueueDeclare(testRetryQueueName, durable: false, exclusive: false, autoDelete: false, arguments);
1718+
1719+
arguments["x-dead-letter-exchange"] = "tdi.wait.exchange";
1720+
arguments["x-dead-letter-routing-key"] = "QueueTest";
1721+
1722+
Model.QueueDeclare(testQueueName, durable: false, exclusive: false, autoDelete: false, arguments);
1723+
1724+
arguments.Remove("x-dead-letter-exchange");
1725+
arguments.Remove("x-dead-letter-routing-key");
1726+
1727+
Model.QueueBind(testRetryQueueName, tdiWaitExchangeName, testQueueName);
1728+
1729+
Model.QueueBind(testQueueName, tdiRetryExchangeName, testQueueName);
1730+
1731+
var consumerAsync = new EventingBasicConsumer(Model);
1732+
Model.BasicConsume(queue: testQueueName, autoAck: false, consumer: consumerAsync);
1733+
1734+
CloseAndWaitForRecovery();
1735+
1736+
QueueDeclareOk q0 = Model.QueueDeclarePassive(testRetryQueueName);
1737+
Assert.AreEqual(testRetryQueueName, q0.QueueName);
1738+
1739+
QueueDeclareOk q1 = Model.QueueDeclarePassive(testQueueName);
1740+
Assert.AreEqual(testQueueName, q1.QueueName);
1741+
}
1742+
16901743
internal bool SendAndConsumeMessage(string queue, string exchange, string routingKey)
16911744
{
16921745
using (var ch = Conn.CreateModel())

0 commit comments

Comments
 (0)