Skip to content

Commit

Permalink
Merge pull request #48 from jarikp/master
Browse files Browse the repository at this point in the history
suggested fix for "PRECONDITION_FAILED - invalid arg 'x-expires' for queue '...'…
  • Loading branch information
mookid8000 authored Mar 15, 2019
2 parents e068b29 + b7008f4 commit a58c450
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 7 deletions.
82 changes: 82 additions & 0 deletions Rebus.RabbitMq.Tests/RabbitMqCreateQueueTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using NUnit.Framework;
using Rebus.Activation;
using Rebus.Config;
using Rebus.Tests.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Rebus.RabbitMq.Tests
{
[TestFixture]
public class RabbitMqCreateQueueTest : FixtureBase
{
readonly string _testQueue1 = TestConfig.GetName("test_queue_1");

protected override void SetUp()
{
RabbitMqTransportFactory.DeleteQueue(_testQueue1);
}

[Test]
public void Test_CreateQueue_WHEN_InputQueueOptions_AutoDelete_False_AND_TTL0_THEN_BusCanStart()
{
var activator = Using(new BuiltinHandlerActivator());
var configurer = Configure.With(activator)
.Transport(t =>
{
t.UseRabbitMq(RabbitMqTransportFactory.ConnectionString, _testQueue1)
.InputQueueOptions(o => o.SetAutoDelete(false))
.AddClientProperties(new Dictionary<string, string> {
{ "description", "CreateQueue_With_AutoDelete test in RabbitMqCreateQueueTest.cs" }
});
});
var bus = configurer.Start();

Assert.IsTrue(bus.Advanced.Workers.Count > 0);
}


[Test]
public void Test_CreateQueue_WHEN_InputQueueOptions_AutoDelete_True_AND_TTL_Positive_THEN_BusCanStart()
{
var activator = Using(new BuiltinHandlerActivator());
var configurer = Configure.With(activator)
.Transport(t =>
{
t.UseRabbitMq(RabbitMqTransportFactory.ConnectionString, _testQueue1)
.InputQueueOptions(o => o.SetAutoDelete(true, 1))
.AddClientProperties(new Dictionary<string, string> {
{ "description", "CreateQueue_With_AutoDelete test in RabbitMqCreateQueueTest.cs" }
});
});

var bus = configurer.Start();

Assert.IsTrue(bus.Advanced.Workers.Count > 0);
}

[Test]
public void Test_CreateQueue_WHEN_InputQueueOptions_AutoDelete_True_AND_TTL_0_THEN_ArgumentExceptionThrown()
{
var activator = Using(new BuiltinHandlerActivator());

Assert.Throws<ArgumentException>(() =>
{
var configurer = Configure.With(activator)
.Transport(t =>
{
t.UseRabbitMq(RabbitMqTransportFactory.ConnectionString, _testQueue1)
.InputQueueOptions(o => o.SetAutoDelete(true, 0))
.AddClientProperties(new Dictionary<string, string> {
{ "description", "CreateQueue_With_AutoDelete test in RabbitMqCreateQueueTest.cs" }
});
});
}
, "Time must be in milliseconds and greater than 0");
}
}
}
13 changes: 6 additions & 7 deletions Rebus.RabbitMq/Config/RabbitMqQueueOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ public RabbitMqQueueOptionsBuilder SetExclusive(bool exclusive)
/// </summary>
public RabbitMqQueueOptionsBuilder SetAutoDelete(bool autoDelete, long ttlInMs = 0)
{
if (ttlInMs < 0)
{
AutoDelete = autoDelete;

if (AutoDelete && ttlInMs <= 0)
throw new ArgumentException("Time must be in milliseconds and greater than 0", nameof(ttlInMs));
}
else
{

if (AutoDelete)
Arguments.Add("x-expires", ttlInMs);
}
AutoDelete = autoDelete;

return this;
}

Expand Down

0 comments on commit a58c450

Please sign in to comment.