Skip to content

Commit

Permalink
Add missing policies to PolicyDefinition (#281)
Browse files Browse the repository at this point in the history
* Update PolicyDefinition.cs

* Create Overflow.cs

* Update Overflow.cs

* Update Overflow.cs

* Create HaPromote.cs

* Create QueueLocator.cs

* Create DeadLetterStrategy.cs

* Update ManagementClientTests.cs

* Update RabbitMQFixture.cs

* Update PolicyDefinition.cs

* Create JsonStringEnumConverterEx

* Update ManagementClientTests.cs

* Create dsd

* Delete Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

* Rename dsd to ManagementClientTests.cs

* Rename JsonStringEnumConverterEx to JsonStringEnumConverterEx.cs

* Update JsonStringEnumConverterEx.cs

* Update JsonStringEnumConverterEx.cs

internal class JsonStringEnumConverterEx

* Create QueueVersion.cs

* Create JsonNumberEnumConverter.cs

* Update PolicyDefinition.cs

* Update ManagementClientTests.cs

* Update EasyNetQ.Management.Client.approved.txt

* Update EasyNetQ.Management.Client.approved.txt - remove last EOL

* Update EasyNetQ.Management.Client.approved.txt - EOL

* Create .gitattributes

* Update EasyNetQ.Management.Client.approved.txt

* Update .gitattributes

* Update EasyNetQ.Management.Client.approved.txt

* Update .gitattributes

* Update EasyNetQ.Management.Client.approved.txt

* remove eof eol

* delete .gitattributes
  • Loading branch information
inikulshin authored Dec 11, 2023
1 parent bb54ff6 commit 7ca648c
Show file tree
Hide file tree
Showing 11 changed files with 391 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,13 @@ namespace EasyNetQ.Management.Client.Model
public int Credit { get; init; }
public bool Drain { get; init; }
}
public enum DeadLetterStrategy
{
[System.Runtime.Serialization.EnumMember(Value="at-most-once")]
AtMostOnce = 0,
[System.Runtime.Serialization.EnumMember(Value="at-least-once")]
AtLeastOnce = 1,
}
public class Definitions : System.IEquatable<EasyNetQ.Management.Client.Model.Definitions>
{
public Definitions(string RabbitVersion, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.User> Users, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.Vhost> Vhosts, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.Permission> Permissions, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.Queue> Queues, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.Exchange> Exchanges, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.Binding> Bindings) { }
Expand Down Expand Up @@ -625,6 +632,13 @@ namespace EasyNetQ.Management.Client.Model
public long? ExactlyCount { get; init; }
public System.Collections.Generic.IReadOnlyList<string>? Nodes { get; init; }
}
public enum HaPromote
{
[System.Runtime.Serialization.EnumMember(Value="when-synced")]
WhenSynced = 0,
[System.Runtime.Serialization.EnumMember(Value="always")]
Always = 1,
}
public enum HaSyncMode
{
Manual = 0,
Expand Down Expand Up @@ -813,6 +827,15 @@ namespace EasyNetQ.Management.Client.Model
public int Exchanges { get; init; }
public int Queues { get; init; }
}
public enum Overflow
{
[System.Runtime.Serialization.EnumMember(Value="drop-head")]
DropHead = 0,
[System.Runtime.Serialization.EnumMember(Value="reject-publish")]
RejectPublish = 1,
[System.Runtime.Serialization.EnumMember(Value="reject-publish-dlx")]
RejectPublishDlx = 2,
}
public class Overview : System.IEquatable<EasyNetQ.Management.Client.Model.Overview>
{
public Overview(string ManagementVersion, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.ExchangeTypeSpec> ExchangeTypes, string RabbitmqVersion, string ErlangVersion, EasyNetQ.Management.Client.Model.MessageStats MessageStats, EasyNetQ.Management.Client.Model.QueueTotals QueueTotals, EasyNetQ.Management.Client.Model.ObjectTotals ObjectTotals, string Node, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.Listener> Listeners, System.Collections.Generic.IReadOnlyList<EasyNetQ.Management.Client.Model.Context> Contexts) { }
Expand Down Expand Up @@ -931,13 +954,45 @@ namespace EasyNetQ.Management.Client.Model
}
public class PolicyDefinition : System.IEquatable<EasyNetQ.Management.Client.Model.PolicyDefinition>
{
public PolicyDefinition(EasyNetQ.Management.Client.Model.HaMode? HaMode = default, EasyNetQ.Management.Client.Model.HaParams? HaParams = null, EasyNetQ.Management.Client.Model.HaSyncMode? HaSyncMode = default, int? HaSyncBatchSize = default, string? FederationUpstream = null, string? FederationUpstreamSet = null, string? AlternateExchange = null, string? DeadLetterExchange = null, string? DeadLetterRoutingKey = null, string? QueueMode = null, uint? MessageTtl = default, uint? Expires = default, uint? MaxLength = default) { }
public PolicyDefinition(
uint? MaxLength = default,
long? MaxLengthBytes = default,
EasyNetQ.Management.Client.Model.Overflow? Overflow = default,
uint? Expires = default,
string? DeadLetterExchange = null,
string? DeadLetterRoutingKey = null,
uint? MessageTtl = default,
uint? ConsumerTimeout = default,
EasyNetQ.Management.Client.Model.HaMode? HaMode = default,
EasyNetQ.Management.Client.Model.HaParams? HaParams = null,
EasyNetQ.Management.Client.Model.HaSyncMode? HaSyncMode = default,
int? HaSyncBatchSize = default,
EasyNetQ.Management.Client.Model.HaPromote? HaPromoteOnShutdown = default,
EasyNetQ.Management.Client.Model.HaPromote? HaPromoteOnFailure = default,
EasyNetQ.Management.Client.Model.QueueVersion? QueueVersion = default,
EasyNetQ.Management.Client.Model.QueueLocator? QueueMasterLocator = default,
uint? DeliveryLimit = default,
EasyNetQ.Management.Client.Model.DeadLetterStrategy? DeadLetterStrategy = default,
EasyNetQ.Management.Client.Model.QueueLocator? QueueLeaderLocator = default,
string? MaxAge = null,
uint? StreamMaxSegmentSizeBytes = default,
string? AlternateExchange = null,
string? FederationUpstream = null,
string? FederationUpstreamSet = null,
string? QueueMode = null) { }
[System.Text.Json.Serialization.JsonPropertyName("alternate-exchange")]
public string? AlternateExchange { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("consumer-timeout")]
public uint? ConsumerTimeout { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("dead-letter-exchange")]
public string? DeadLetterExchange { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("dead-letter-routing-key")]
public string? DeadLetterRoutingKey { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(EasyNetQ.Management.Client.Serialization.JsonStringEnumConverterEx<EasyNetQ.Management.Client.Model.DeadLetterStrategy>?))]
[System.Text.Json.Serialization.JsonPropertyName("dead-letter-strategy")]
public EasyNetQ.Management.Client.Model.DeadLetterStrategy? DeadLetterStrategy { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("delivery-limit")]
public uint? DeliveryLimit { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("expires")]
public uint? Expires { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("federation-upstream-set")]
Expand All @@ -948,16 +1003,40 @@ namespace EasyNetQ.Management.Client.Model
public EasyNetQ.Management.Client.Model.HaMode? HaMode { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("ha-params")]
public EasyNetQ.Management.Client.Model.HaParams? HaParams { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(EasyNetQ.Management.Client.Serialization.JsonStringEnumConverterEx<EasyNetQ.Management.Client.Model.HaPromote>?))]
[System.Text.Json.Serialization.JsonPropertyName("ha-promote-on-failure")]
public EasyNetQ.Management.Client.Model.HaPromote? HaPromoteOnFailure { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(EasyNetQ.Management.Client.Serialization.JsonStringEnumConverterEx<EasyNetQ.Management.Client.Model.HaPromote>?))]
[System.Text.Json.Serialization.JsonPropertyName("ha-promote-on-shutdown")]
public EasyNetQ.Management.Client.Model.HaPromote? HaPromoteOnShutdown { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("ha-sync-batch-size")]
public int? HaSyncBatchSize { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("ha-sync-mode")]
public EasyNetQ.Management.Client.Model.HaSyncMode? HaSyncMode { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("max-age")]
public string? MaxAge { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("max-length-bytes")]
public long? MaxLengthBytes { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("max-length")]
public uint? MaxLength { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("message-ttl")]
public uint? MessageTtl { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(EasyNetQ.Management.Client.Serialization.JsonStringEnumConverterEx<EasyNetQ.Management.Client.Model.Overflow>?))]
[System.Text.Json.Serialization.JsonPropertyName("overflow")]
public EasyNetQ.Management.Client.Model.Overflow? Overflow { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(EasyNetQ.Management.Client.Serialization.JsonStringEnumConverterEx<EasyNetQ.Management.Client.Model.QueueLocator>?))]
[System.Text.Json.Serialization.JsonPropertyName("queue-leader-locator")]
public EasyNetQ.Management.Client.Model.QueueLocator? QueueLeaderLocator { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(EasyNetQ.Management.Client.Serialization.JsonStringEnumConverterEx<EasyNetQ.Management.Client.Model.QueueLocator>?))]
[System.Text.Json.Serialization.JsonPropertyName("queue-master-locator")]
public EasyNetQ.Management.Client.Model.QueueLocator? QueueMasterLocator { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("queue-mode")]
public string? QueueMode { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonNumberEnumConverter<EasyNetQ.Management.Client.Model.QueueVersion>?))]
[System.Text.Json.Serialization.JsonPropertyName("queue-version")]
public EasyNetQ.Management.Client.Model.QueueVersion? QueueVersion { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("stream-max-segment-size-bytes")]
public uint? StreamMaxSegmentSizeBytes { get; init; }
}
public class PolicyInfo : System.IEquatable<EasyNetQ.Management.Client.Model.PolicyInfo>
{
Expand Down Expand Up @@ -1047,6 +1126,13 @@ namespace EasyNetQ.Management.Client.Model
public bool Durable { get; init; }
public string Name { get; init; }
}
public enum QueueLocator
{
[System.Runtime.Serialization.EnumMember(Value="client-local")]
ClientLocal = 0,
[System.Runtime.Serialization.EnumMember(Value="balanced")]
Balanced = 1,
}
public class QueueName : System.IEquatable<EasyNetQ.Management.Client.Model.QueueName>
{
public QueueName(string Name, string Vhost) { }
Expand All @@ -1063,6 +1149,11 @@ namespace EasyNetQ.Management.Client.Model
public long MessagesUnacknowledged { get; init; }
public long Messages { get; init; }
}
public enum QueueVersion
{
V1 = 1,
V2 = 2,
}
public class RatesCriteria : System.IEquatable<EasyNetQ.Management.Client.Model.RatesCriteria>
{
public RatesCriteria(int MsgRatesAge, int MsgRatesIncr) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EasyNetQ.Management.Client.Model;
using EasyNetQ.Management.Client.Model;

namespace EasyNetQ.Management.Client.IntegrationTests;

Expand Down Expand Up @@ -216,12 +216,24 @@ public async Task Should_be_able_to_create_all_the_definitions_in_a_policy()
const int priority = 999;
const HaMode haMode = HaMode.All;
const HaSyncMode haSyncMode = HaSyncMode.Automatic;
const HaPromote haPromoteOnFailure = HaPromote.Always;
const HaPromote haPromoteOnShutdown = HaPromote.WhenSynced;
QueueVersion queueVersion = fixture.RabbitmqVersion >= new Version("3.12") ? QueueVersion.V2 : QueueVersion.V1;
const QueueLocator queueMasterLocator = QueueLocator.ClientLocal;
const uint deliveryLimit = 3;
const Model.DeadLetterStrategy deadLetterStrategy = Model.DeadLetterStrategy.AtLeastOnce;
const QueueLocator queueLeaderLocator = QueueLocator.Balanced;
const string maxAge = "1h";
const uint streamMaxSegmentSizeBytes = 50000;
const string alternateExchange = "a-sample-alternate-exchange";
const string deadLetterExchange = "a-sample-dead-letter-exchange";
const string deadLetterRoutingKey = "a-sample-dead-letter-exchange-key";
const uint messageTtl = 5000;
const uint expires = 10000;
const uint maxLength = 500;
const long maxLengthBytes = 5000;
const Overflow overflow = Overflow.RejectPublish;
uint? consumerTimeout = fixture.RabbitmqVersion >= new Version("3.12") ? 3600000 : null;

await fixture.ManagementClient.CreatePolicyAsync(
new Policy(
Expand All @@ -231,12 +243,28 @@ await fixture.ManagementClient.CreatePolicyAsync(
Definition: new PolicyDefinition(
HaMode: haMode,
HaSyncMode: haSyncMode,
HaPromoteOnFailure: haPromoteOnFailure,
HaPromoteOnShutdown: haPromoteOnShutdown,
QueueVersion: queueVersion,
QueueMasterLocator: queueMasterLocator,

DeliveryLimit: deliveryLimit,
DeadLetterStrategy: deadLetterStrategy,
QueueLeaderLocator: queueLeaderLocator,

MaxAge: maxAge,
StreamMaxSegmentSizeBytes: streamMaxSegmentSizeBytes,

AlternateExchange: alternateExchange,

DeadLetterExchange: deadLetterExchange,
DeadLetterRoutingKey: deadLetterRoutingKey,
MessageTtl: messageTtl,
Expires: expires,
MaxLength: maxLength
MaxLength: maxLength,
MaxLengthBytes: maxLengthBytes,
Overflow: overflow,
ConsumerTimeout: consumerTimeout
),
Priority: priority
)
Expand All @@ -247,12 +275,24 @@ await fixture.ManagementClient.CreatePolicyAsync(
&& p.Priority == priority
&& p.Definition.HaMode == haMode
&& p.Definition.HaSyncMode == haSyncMode
&& p.Definition.HaPromoteOnFailure == haPromoteOnFailure
&& p.Definition.HaPromoteOnShutdown == haPromoteOnShutdown
&& p.Definition.QueueVersion == queueVersion
&& p.Definition.QueueMasterLocator == queueMasterLocator
&& p.Definition.DeliveryLimit == deliveryLimit
&& p.Definition.DeadLetterStrategy == deadLetterStrategy
&& p.Definition.QueueLeaderLocator == queueLeaderLocator
&& p.Definition.MaxAge == maxAge
&& p.Definition.StreamMaxSegmentSizeBytes == streamMaxSegmentSizeBytes
&& p.Definition.AlternateExchange == alternateExchange
&& p.Definition.DeadLetterExchange == deadLetterExchange
&& p.Definition.DeadLetterRoutingKey == deadLetterRoutingKey
&& p.Definition.MessageTtl == messageTtl
&& p.Definition.Expires == expires
&& p.Definition.MaxLength == maxLength)
&& p.Definition.MaxLength == maxLength
&& p.Definition.MaxLengthBytes == maxLengthBytes
&& p.Definition.Overflow == overflow
&& p.Definition.ConsumerTimeout == consumerTimeout)
);
}

Expand Down Expand Up @@ -437,6 +477,55 @@ await fixture.ManagementClient.CreatePolicyAsync(
);
}

[Fact]
public async Task Should_be_able_to_create_max_length_bytes_policy()
{
const string policyName = "a-sample-max-length-bytes";
const uint maxLengthBytes = 500;
await fixture.ManagementClient.CreatePolicyAsync(
new Policy(
Name: policyName,
Pattern: "averyuncommonpattern",
Vhost: Vhost.Name,
Definition: new PolicyDefinition(
MaxLengthBytes: maxLengthBytes
)
)
);
Assert.Equal(1, (await fixture.ManagementClient.GetPoliciesAsync()).Count(
p => p.Name == policyName
&& p.Vhost == Vhost.Name
&& p.Definition.MaxLengthBytes == maxLengthBytes)
);
}

[Fact]
public async Task Should_be_able_to_create_overflow_policy()
{
foreach (Overflow overflow in Enum.GetValues(typeof(Overflow)))
{
const string policyName = "a-sample-overflow";
const uint maxLengthBytes = 500;
await fixture.ManagementClient.CreatePolicyAsync(
new Policy(
Name: policyName,
Pattern: "averyuncommonpattern",
Vhost: Vhost.Name,
Definition: new PolicyDefinition(
MaxLengthBytes: maxLengthBytes,
Overflow: overflow
)
)
);
Assert.Equal(1, (await fixture.ManagementClient.GetPoliciesAsync()).Count(
p => p.Name == policyName
&& p.Vhost == Vhost.Name
&& p.Definition.MaxLengthBytes == maxLengthBytes
&& p.Definition.Overflow == overflow)
);
}
}

[Fact]
public async Task Should_be_able_to_create_message_ttl_policy()
{
Expand Down Expand Up @@ -1187,7 +1276,7 @@ public async Task Should_throw_when_trying_to_close_unknown_connection()

[Fact]
public async Task Should_be_able_to_create_shovel_parameter_on_queue()
{
{
var srcUri = new AmqpUri(fixture.Endpoint.Host, fixture.Endpoint.Port, fixture.User, fixture.Password);
var destUri = new AmqpUri($"{fixture.Endpoint.Host}-1", fixture.Endpoint.Port, fixture.User, fixture.Password);

Expand Down Expand Up @@ -1220,10 +1309,10 @@ await fixture.ManagementClient.CreateShovelAsync(

[Fact]
public async Task Should_be_able_to_create_shovel_parameter_on_exchange()
{
{
var srcUri = new AmqpUri(fixture.Endpoint.Host, fixture.Endpoint.Port, fixture.User, fixture.Password);
var destUri = new AmqpUri($"{fixture.Endpoint.Host}-1", fixture.Endpoint.Port, fixture.User, fixture.Password);

var destUri = new AmqpUri($"{fixture.Endpoint.Host}-1", fixture.Endpoint.Port, fixture.User, fixture.Password);

var shovelName = "exchange-shovel";

await fixture.ManagementClient.CreateShovelAsync(
Expand Down Expand Up @@ -1256,8 +1345,8 @@ public async Task Should_be_able_to_throw_on_non_existant_shovel()
{
await Assert.ThrowsAsync<UnexpectedHttpStatusCodeException>(async ()
=> await fixture.ManagementClient.GetShovelAsync(Vhost.Name, "non-existant-shovel"));
}

}

[Fact]
public async Task Should_be_able_to_get_existant_shovel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public RabbitMqFixture()

public IManagementClient ManagementClient { get; private set; }

public Version RabbitmqVersion { get; private set; }

public async Task InitializeAsync()
{
using var cts = new CancellationTokenSource(InitializationTimeout);
Expand All @@ -45,6 +47,9 @@ public async Task InitializeAsync()

ManagementClient = new ManagementClient(Endpoint, User, Password);
await WaitForRabbitMqReadyAsync(cts.Token);

var overview = await ManagementClient.GetOverviewAsync();
RabbitmqVersion = new Version(overview.RabbitmqVersion);
}

public async Task DisposeAsync()
Expand Down
11 changes: 11 additions & 0 deletions Source/EasyNetQ.Management.Client/Model/DeadLetterStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Runtime.Serialization;

namespace EasyNetQ.Management.Client.Model;

public enum DeadLetterStrategy
{
[EnumMember(Value = "at-most-once")]
AtMostOnce,
[EnumMember(Value = "at-least-once")]
AtLeastOnce
}
11 changes: 11 additions & 0 deletions Source/EasyNetQ.Management.Client/Model/HaPromote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Runtime.Serialization;

namespace EasyNetQ.Management.Client.Model;

public enum HaPromote
{
[EnumMember(Value = "when-synced")]
WhenSynced,
[EnumMember(Value = "always")]
Always
}
Loading

0 comments on commit 7ca648c

Please sign in to comment.