Skip to content

Commit 78e78cd

Browse files
Fix issue #62
1 parent c3c5afc commit 78e78cd

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

RabbitMQ.Stream.Client/StreamSpec.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace RabbitMQ.Stream.Client
55
{
66
public record StreamSpec
77
{
8-
private readonly IDictionary<string, string> args = new Dictionary<string, string>();
8+
private readonly IDictionary<string, string> args = new Dictionary<string, string>() {
9+
["queue-leader-locator"] = LeaderLocator.LeastLeaders.ToString()
10+
};
911

1012
public StreamSpec(string name)
1113
{
@@ -16,17 +18,17 @@ public StreamSpec(string name)
1618

1719
public TimeSpan MaxAge
1820
{
19-
set => Args.Add("max-age", $"{value.TotalSeconds}s");
21+
set => Args["max-age"] = $"{value.TotalSeconds}s";
2022
}
2123

2224
public int MaxLengthBytes
2325
{
24-
set => Args.Add("max-length-bytes", $"{value}");
26+
set => Args["max-length-bytes"] = $"{value}";
2527
}
2628

2729
public LeaderLocator LeaderLocator
2830
{
29-
set => Args.Add("queue-leader-locator", $"{value.ToString()}");
31+
set => Args["queue-leader-locator"] = $"{value.ToString()}";
3032
}
3133

3234
public IDictionary<string, string> Args => args;

Tests/StreamSpecTests.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using RabbitMQ.Stream.Client;
10+
using Xunit;
11+
using Xunit.Abstractions;
12+
using Xunit.Sdk;
13+
14+
namespace Tests
15+
{
16+
17+
18+
[Collection("Sequential")]
19+
public class StreamSpecTests
20+
{
21+
private readonly ITestOutputHelper testOutputHelper;
22+
23+
public StreamSpecTests(ITestOutputHelper testOutputHelper)
24+
{
25+
this.testOutputHelper = testOutputHelper;
26+
}
27+
28+
29+
[Fact]
30+
[WaitTestBeforeAfter]
31+
public void DefaultStreamSpecMustHaveAtLeastQueueLeaderLocator()
32+
{
33+
StreamSpec actualSpec = new StreamSpec("theStreamName");
34+
StreamSpec expectedSpec = new StreamSpec("theStreamName") {
35+
LeaderLocator = LeaderLocator.LeastLeaders
36+
};
37+
Assert.Equal(expectedSpec.Args, actualSpec.Args);
38+
39+
}
40+
41+
42+
[Fact]
43+
[WaitTestBeforeAfter]
44+
public void CanOverrideAnyStreamSpecAttributes()
45+
{
46+
StreamSpec spec = new StreamSpec("theStreamName");
47+
spec.MaxAge = TimeSpan.FromHours(3);
48+
spec.MaxLengthBytes = 10000;
49+
spec.LeaderLocator = LeaderLocator.Random; // this is an override because the spec has already a default value
50+
51+
// can override any settings being set
52+
spec.MaxAge = TimeSpan.FromHours(5);
53+
spec.MaxLengthBytes = 20000;
54+
55+
56+
StreamSpec expectedSpec = new StreamSpec("theStreamName") {
57+
LeaderLocator = LeaderLocator.Random,
58+
MaxLengthBytes = 20000,
59+
MaxAge = TimeSpan.FromHours(5)
60+
};
61+
Assert.Equal(expectedSpec.Args, spec.Args);
62+
}
63+
64+
}
65+
}

0 commit comments

Comments
 (0)