-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathKeyPrefixedSubscriberTests.cs
More file actions
76 lines (62 loc) · 2.58 KB
/
KeyPrefixedSubscriberTests.cs
File metadata and controls
76 lines (62 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.Collections.Generic;
using System.Threading.Tasks;
using StackExchange.Redis.KeyspaceIsolation;
using Xunit;
using Xunit.Abstractions;
namespace StackExchange.Redis.Tests
{
public class KeyPrefixedSubscriberTests : TestBase
{
public KeyPrefixedSubscriberTests(ITestOutputHelper output) : base(output)
{}
[Fact]
public async Task UsePrefixForChannel()
{
using (var client = Create(allowAdmin: true))
{
const string prefix1 = "(p1)-";
const string prefix2 = "(p2)-";
var s1 = client.GetSubscriber().WithChannelPrefix(prefix1);
var s12 = client.GetSubscriber().WithChannelPrefix(prefix1);
var s2 = client.GetSubscriber().WithChannelPrefix(prefix2);
var s = client.GetSubscriber();
var l1 = new List<string>();
var l12 = new List<string>();
var l2 = new List<string>();
var l = new List<string>();
var lAll = new List<string>();
var lT1 = new List<string>();
var c1 = new List<string>();
const string channelName = "test-channel";
s1.Subscribe(channelName, (channel, value) =>
{
c1.Add(channel!);
l1.Add(value!);
});
s12.Subscribe(channelName, (_channel, value) => l12.Add(value!));
s2.Subscribe(channelName, (_channel, value) => l2.Add(value!));
s.Subscribe(channelName, (_channel, value) => l.Add(value!));
s.Subscribe("*" + channelName, (_channel, value) => lAll.Add(value!));
s.Subscribe(prefix1 + channelName, (_channel, value) => lT1.Add(value!));
s1.Publish(channelName, "value1");
s.Publish(channelName, "value");
// Give some time to pub-sub
await Task.Delay(500);
Assert.Single(l1);
Assert.Equal("value1",l1[0]);
Assert.Single(l12);
Assert.Equal("value1",l12[0]);
Assert.Empty(l2);
Assert.Single(l);
Assert.Equal("value",l[0]);
Assert.Equal(2, lAll.Count);
Assert.Contains("value", lAll);
Assert.Contains("value1", lAll);
Assert.Single(lT1);
Assert.Equal("value1",lT1[0]);
Assert.Single(c1);
Assert.Equal(channelName,c1[0]);
}
}
}
}