Skip to content

Commit

Permalink
Fix issue #62
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcialRosales committed Feb 11, 2022
1 parent c3c5afc commit 78e78cd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
10 changes: 6 additions & 4 deletions RabbitMQ.Stream.Client/StreamSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace RabbitMQ.Stream.Client
{
public record StreamSpec
{
private readonly IDictionary<string, string> args = new Dictionary<string, string>();
private readonly IDictionary<string, string> args = new Dictionary<string, string>() {
["queue-leader-locator"] = LeaderLocator.LeastLeaders.ToString()
};

public StreamSpec(string name)
{
Expand All @@ -16,17 +18,17 @@ public StreamSpec(string name)

public TimeSpan MaxAge
{
set => Args.Add("max-age", $"{value.TotalSeconds}s");
set => Args["max-age"] = $"{value.TotalSeconds}s";
}

public int MaxLengthBytes
{
set => Args.Add("max-length-bytes", $"{value}");
set => Args["max-length-bytes"] = $"{value}";
}

public LeaderLocator LeaderLocator
{
set => Args.Add("queue-leader-locator", $"{value.ToString()}");
set => Args["queue-leader-locator"] = $"{value.ToString()}";
}

public IDictionary<string, string> Args => args;
Expand Down
65 changes: 65 additions & 0 deletions Tests/StreamSpecTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using RabbitMQ.Stream.Client;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Tests
{


[Collection("Sequential")]
public class StreamSpecTests
{
private readonly ITestOutputHelper testOutputHelper;

public StreamSpecTests(ITestOutputHelper testOutputHelper)
{
this.testOutputHelper = testOutputHelper;
}


[Fact]
[WaitTestBeforeAfter]
public void DefaultStreamSpecMustHaveAtLeastQueueLeaderLocator()
{
StreamSpec actualSpec = new StreamSpec("theStreamName");
StreamSpec expectedSpec = new StreamSpec("theStreamName") {
LeaderLocator = LeaderLocator.LeastLeaders
};
Assert.Equal(expectedSpec.Args, actualSpec.Args);

}


[Fact]
[WaitTestBeforeAfter]
public void CanOverrideAnyStreamSpecAttributes()
{
StreamSpec spec = new StreamSpec("theStreamName");
spec.MaxAge = TimeSpan.FromHours(3);
spec.MaxLengthBytes = 10000;
spec.LeaderLocator = LeaderLocator.Random; // this is an override because the spec has already a default value

// can override any settings being set
spec.MaxAge = TimeSpan.FromHours(5);
spec.MaxLengthBytes = 20000;


StreamSpec expectedSpec = new StreamSpec("theStreamName") {
LeaderLocator = LeaderLocator.Random,
MaxLengthBytes = 20000,
MaxAge = TimeSpan.FromHours(5)
};
Assert.Equal(expectedSpec.Args, spec.Args);
}

}
}

0 comments on commit 78e78cd

Please sign in to comment.