Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using EasyNetQ.Management.Client.Model;
using System.Text.Json;

namespace EasyNetQ.Management.Client.IntegrationTests;

using JsonSerializer = System.Text.Json.JsonSerializer;

[Collection("RabbitMQ")]
public class ManagementClientTests
{
Expand Down Expand Up @@ -747,9 +750,9 @@ public async Task Should_be_able_to_get_a_list_of_bindings_between_an_exchange_a

var exchange = await EnsureExchangeExists(TestExchange);

var bindings = (await fixture.ManagementClient.GetQueueBindingsAsync(exchange, queue)).ToArray();
var bindings = await fixture.ManagementClient.GetQueueBindingsAsync(exchange, queue);

bindings.Length.Should().Be(0);
bindings.Should().BeEmpty();
}

[Fact]
Expand All @@ -760,7 +763,7 @@ public async Task Should_be_able_to_get_a_list_of_bindings_between_an_exchange_a

var bindings = await fixture.ManagementClient.GetExchangeBindingsAsync(exchange1, exchange2);

bindings.Count.Should().Be(0);
bindings.Should().BeEmpty();
}

[Fact]
Expand All @@ -787,9 +790,9 @@ public async Task Should_be_able_to_get_a_queue_by_name_with_all_detailed_inform
);

queue.Name.Should().Be(TestQueue);
queue.MessagesDetails.Samples.Count.Should().BeGreaterThan(0);
queue.MessagesReadyDetails.Samples.Count.Should().BeGreaterThan(0);
queue.MessagesUnacknowledgedDetails.Samples.Count.Should().BeGreaterThan(0);
queue.MessagesDetails.Samples.Should().NotBeNullOrEmpty();
queue.MessagesReadyDetails.Samples.Should().NotBeNullOrEmpty();
queue.MessagesUnacknowledgedDetails.Samples.Should().NotBeNullOrEmpty();
}

[Fact]
Expand All @@ -803,9 +806,9 @@ public async Task Should_be_able_to_get_a_queue_by_name_with_detailed_length_inf
var queue = await fixture.ManagementClient.GetQueueAsync(Vhost, TestQueue, new LengthsCriteria(age, increment));

queue.Name.Should().Be(TestQueue);
queue.MessagesDetails.Samples.Count.Should().BeGreaterThan(0);
queue.MessagesReadyDetails.Samples.Count.Should().BeGreaterThan(0);
queue.MessagesUnacknowledgedDetails.Samples.Count.Should().BeGreaterThan(0);
queue.MessagesDetails.Samples.Should().NotBeNullOrEmpty();
queue.MessagesReadyDetails.Samples.Should().NotBeNullOrEmpty();
queue.MessagesUnacknowledgedDetails.Samples.Should().NotBeNullOrEmpty();
}

[Fact]
Expand Down Expand Up @@ -1148,7 +1151,7 @@ public async Task Should_get_exchanges_with_pagination()
{
var page = await fixture.ManagementClient.GetExchangesByPageAsync(new PageCriteria(1, 7, "amq"));

page.Items.Count.Should().BeGreaterThan(0);
page.Items.Should().NotBeNullOrEmpty();
}

[Fact(Skip = "Requires at least an active federation")]
Expand Down Expand Up @@ -1222,6 +1225,53 @@ public async Task Should_get_queues()
}
}

[Fact]
public async Task Should_get_queues_with_pagination()
{
foreach (var queue in await fixture.ManagementClient.GetQueuesAsync())
await fixture.ManagementClient.DeleteQueueAsync(queue);

await CreateTestQueue("1");
await CreateTestQueue("2");

var firstPage = await fixture.ManagementClient.GetQueuesByPageAsync(new PageCriteria(1, 1));
firstPage.Items.Count.Should().Be(1);

var secondPage = await fixture.ManagementClient.GetQueuesByPageAsync(new PageCriteria(2, 1));
secondPage.Items.Count.Should().Be(1);
}

[Fact]
public async Task Should_get_queues_by_vhost()
{
await fixture.ManagementClient.CreateVhostAsync(TestVHost);
var vhost = await fixture.ManagementClient.GetVhostAsync(TestVHost);
vhost.Name.Should().Be(TestVHost);

await CreateTestQueueInVhost($"{TestVHost}_{TestQueue}", vhost);
(await fixture.ManagementClient.GetQueuesAsync(vhost)).Should().NotBeNullOrEmpty();
}

[Fact]
public async Task Should_get_queues_with_pagination_by_vhost()
{
await fixture.ManagementClient.CreateVhostAsync(TestVHost);
var vhost = await fixture.ManagementClient.GetVhostAsync(TestVHost);
vhost.Name.Should().Be(TestVHost);

foreach (var queue in await fixture.ManagementClient.GetQueuesAsync(TestVHost))
await fixture.ManagementClient.DeleteQueueAsync(queue);

await CreateTestQueueInVhost($"{TestVHost}_{TestQueue}_1", vhost);
await CreateTestQueueInVhost($"{TestVHost}_{TestQueue}_2", vhost);

var firstPage = await fixture.ManagementClient.GetQueuesByPageAsync(vhost, new PageCriteria(1, 1));
firstPage.Items.Count.Should().Be(1);

var secondPage = await fixture.ManagementClient.GetQueuesByPageAsync(vhost, new PageCriteria(2, 1));
secondPage.Items.Count.Should().Be(1);
}

[Fact]
public async Task Should_get_queues_without_stats()
{
Expand All @@ -1230,32 +1280,51 @@ public async Task Should_get_queues_without_stats()
queues.Should().NotBeNullOrEmpty();
}


[Fact]
public async Task Should_get_queues_with_pagination()
public async Task Should_get_queues_without_stats_with_pagination()
{
foreach (var queue in await fixture.ManagementClient.GetQueuesAsync())
await fixture.ManagementClient.DeleteQueueAsync(queue);

await CreateTestQueue("1");
await CreateTestQueue("2");

var firstPage = await fixture.ManagementClient.GetQueuesByPageAsync(new PageCriteria(1, 1));
var firstPage = await fixture.ManagementClient.GetQueuesWithoutStatsByPageAsync(new PageCriteria(1, 1));
firstPage.Items.Count.Should().Be(1);

var secondPage = await fixture.ManagementClient.GetQueuesByPageAsync(new PageCriteria(2, 1));
var secondPage = await fixture.ManagementClient.GetQueuesWithoutStatsByPageAsync(new PageCriteria(2, 1));
secondPage.Items.Count.Should().Be(1);
}

[Fact]
public async Task Should_get_queues_by_vhost()
public async Task Should_get_queues_without_stats_by_vhost()
{
await fixture.ManagementClient.CreateVhostAsync(TestVHost);
var vhost = await fixture.ManagementClient.GetVhostAsync(TestVHost);
vhost.Name.Should().Be(TestVHost);

await CreateTestQueueInVhost($"{TestVHost}_{TestQueue}", vhost);
(await fixture.ManagementClient.GetQueuesAsync(vhost)).Count.Should().BeGreaterThan(0);
(await fixture.ManagementClient.GetQueuesWithoutStatsAsync(vhost.Name)).Should().NotBeNullOrEmpty();
}

[Fact]
public async Task Should_get_queues_without_stats_with_pagination_by_vhost()
{
await fixture.ManagementClient.CreateVhostAsync(TestVHost);
var vhost = await fixture.ManagementClient.GetVhostAsync(TestVHost);
vhost.Name.Should().Be(TestVHost);

foreach (var queue in await fixture.ManagementClient.GetQueuesAsync(TestVHost))
await fixture.ManagementClient.DeleteQueueAsync(queue);

await CreateTestQueueInVhost($"{TestVHost}_{TestQueue}_1", vhost);
await CreateTestQueueInVhost($"{TestVHost}_{TestQueue}_2", vhost);

var firstPage = await fixture.ManagementClient.GetQueuesWithoutStatsByPageAsync(vhost.Name, new PageCriteria(1, 1));
firstPage.Items.Count.Should().Be(1);

var secondPage = await fixture.ManagementClient.GetQueuesWithoutStatsByPageAsync(vhost.Name, new PageCriteria(2, 1));
secondPage.Items.Count.Should().Be(1);
}

[Fact]
Expand Down Expand Up @@ -1301,30 +1370,39 @@ public async Task Should_be_able_to_create_shovel_parameter_on_queue()
var destUri = new AmqpUri($"{fixture.Endpoint.Host}-1", fixture.Endpoint.Port, fixture.User, fixture.Password);

var shovelName = "queue-shovel";

await fixture.ManagementClient.CreateShovelAsync(
vhostName: Vhost.Name,
shovelName,
new ParameterShovelValue
var parameterShovelValue = new ParameterShovelValue
(
SrcProtocol: AmqpProtocol.AMQP091,
SrcUri: srcUri.ToString(),
SrcQueue: "test-queue-src",
SrcExchange: null,
SrcExchangeKey: null,
SrcQueueArguments: new Dictionary<string, object?> { { "x-queue-mode", "lazy" } },
SrcDeleteAfter: "never",
SrcPrefetchCount: 10,
DestProtocol: AmqpProtocol.AMQP091,
DestUri: destUri.ToString(),
DestQueue: "test-queue-dest",
DestExchange: null,
DestQueueArguments: new Dictionary<string, object?> { { "x-queue-mode", "lazy" } },
DestAddForwardHeaders: false,
DestAddTimestampHeader: false,
AckMode: "on-confirm",
AddForwardHeaders: false
)
ReconnectDelay: 10
);

await fixture.ManagementClient.CreateShovelAsync(
vhostName: Vhost.Name,
shovelName,
parameterShovelValue
);

var parameter = await fixture.ManagementClient.GetShovelAsync(Vhost.Name, shovelName);

Assert.Equal(shovelName, parameter.Name);
parameter.Value.Should().BeOfType<JsonElement>();
if (parameter.Value is JsonElement jsonElement)
{
var actualParameterShovelValue = JsonSerializer.Deserialize<ParameterShovelValue>(jsonElement.GetRawText());
actualParameterShovelValue.Should().BeEquivalentTo(parameterShovelValue);
}
}

[Fact]
Expand All @@ -1334,30 +1412,39 @@ public async Task Should_be_able_to_create_shovel_parameter_on_exchange()
var destUri = new AmqpUri($"{fixture.Endpoint.Host}-1", fixture.Endpoint.Port, fixture.User, fixture.Password);

var shovelName = "exchange-shovel";

await fixture.ManagementClient.CreateShovelAsync(
vhostName: Vhost.Name,
shovelName,
new ParameterShovelValue
var parameterShovelValue = new ParameterShovelValue
(
SrcProtocol: AmqpProtocol.AMQP091,
SrcUri: srcUri.ToString(),
SrcExchange: "test-exchange-src",
SrcExchangeKey: null,
SrcQueue: null,
SrcExchangeKey: "aaa",
SrcDeleteAfter: "never",
SrcPrefetchCount: 10,
DestProtocol: AmqpProtocol.AMQP091,
DestUri: destUri.ToString(),
DestExchange: "test-exchange-dest",
DestQueue: null,
DestExchangeKey: "bbb",
DestAddForwardHeaders: false,
DestAddTimestampHeader: false,
AckMode: "on-confirm",
AddForwardHeaders: false
)
ReconnectDelay: 10
);

await fixture.ManagementClient.CreateShovelAsync(
vhostName: Vhost.Name,
shovelName,
parameterShovelValue
);

var parameters = await fixture.ManagementClient.GetParametersAsync();
var parameter = await fixture.ManagementClient.GetShovelAsync(Vhost.Name, shovelName);

Assert.Contains(parameters, p => p.Name == shovelName);
Assert.Equal(shovelName, parameter.Name);
parameter.Value.Should().BeOfType<JsonElement>();
if (parameter.Value is JsonElement jsonElement)
{
var actualParameterShovelValue = JsonSerializer.Deserialize<ParameterShovelValue>(jsonElement.GetRawText());
actualParameterShovelValue.Should().BeEquivalentTo(parameterShovelValue);
}
}

[Fact]
Expand Down Expand Up @@ -1391,7 +1478,7 @@ await fixture.ManagementClient.CreateShovelAsync(
DestExchange: "test-exchange-dest",
DestQueue: null,
AckMode: "on-confirm",
AddForwardHeaders: false
DestAddForwardHeaders: false
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public void Should_deserialize()
Node: "rabbit@localhost",
Protocol: "amqp",
IpAddress: "127.0.0.1",
Port: 5672
Port: 5672,
SocketOpts: new SocketOpts(Backlog: 128, Nodelay: true, ExitOnClose: false)
),
new(
Node: "rabbit@localhost",
Expand All @@ -72,25 +73,29 @@ public void Should_deserialize()
Node: "rabbit@localhost",
Protocol: "http",
IpAddress: "::",
Port: 15672
Port: 15672,
SocketOpts: new SocketOpts()
),
new(
Node: "rabbit@localhost",
Protocol: "mqtt",
IpAddress: "::",
Port: 1883
Port: 1883,
SocketOpts: new SocketOpts(Backlog: 128, Nodelay: true)
),
new(
Node: "rabbit@localhost",
Protocol: "stomp",
IpAddress: "::",
Port: 61613
Port: 61613,
SocketOpts: new SocketOpts(Backlog: 128, Nodelay: true)
),
new(
Node: "rabbit@localhost",
Protocol: "stream",
IpAddress: "::",
Port: 5552
Port: 5552,
SocketOpts: new SocketOpts(Backlog: 128, Nodelay: true)
)
},
Contexts: Array.Empty<Context>()
Expand Down Expand Up @@ -138,7 +143,8 @@ public void Should_deserialize()
Node: "rabbit@localhost",
Protocol: "amqp",
IpAddress: "127.0.0.1",
Port: 5672
Port: 5672,
SocketOpts: new SocketOpts(Backlog: 128, Nodelay: true, ExitOnClose: false)
),
new(
Node: "rabbit@localhost",
Expand All @@ -150,25 +156,29 @@ public void Should_deserialize()
Node: "rabbit@localhost",
Protocol: "http",
IpAddress: "::",
Port: 15672
Port: 15672,
SocketOpts: new SocketOpts()
),
new(
Node: "rabbit@localhost",
Protocol: "mqtt",
IpAddress: "::",
Port: 1883
Port: 1883,
SocketOpts: new SocketOpts(Backlog: 128, Nodelay: true)
),
new(
Node: "rabbit@localhost",
Protocol: "stomp",
IpAddress: "::",
Port: 61613
Port: 61613,
SocketOpts: new SocketOpts(Backlog: 128, Nodelay: true)
),
new(
Node: "rabbit@localhost",
Protocol: "stream",
IpAddress: "::",
Port: 5552
Port: 5552,
SocketOpts: new SocketOpts(Backlog: 128, Nodelay: true)
)
},
Contexts: new Context[]
Expand All @@ -181,7 +191,14 @@ public void Should_deserialize()
)
}
)
}
},
options => options
.Excluding(o => o.ExtensionData)
.Excluding(o => o.JsonExtensionData)
.For(o => o.Listeners).Exclude(l => l.ExtensionData)
.For(o => o.Listeners).Exclude(l => l.JsonExtensionData)
.For(o => o.Listeners).Exclude(l => l.SocketOpts.ExtensionData)
.For(o => o.Listeners).Exclude(l => l.SocketOpts.JsonExtensionData)
);
}
}
Loading