Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 776471e

Browse files
committed
Add Redis Sentinel integration tests
1 parent 052cd51 commit 776471e

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using NUnit.Framework;
2+
using ServiceStack.Text;
3+
4+
namespace ServiceStack.Redis.Tests
5+
{
6+
[Ignore("Reenable when CI has Sentinel")]
7+
[TestFixture, Category("Integration")]
8+
public class Redis3SentinelSetupTests
9+
: RedisClientTestsBase
10+
{
11+
static string[] SentinelHosts = new[]
12+
{
13+
"127.0.0.1:26380",
14+
"127.0.0.1:26381",
15+
"127.0.0.1:26382",
16+
};
17+
18+
[Test]
19+
public void Can_connect_to_3SentinelSetup()
20+
{
21+
var sentinel = new RedisSentinel(SentinelHosts);
22+
23+
var redisManager = sentinel.Start();
24+
25+
using (var client = redisManager.GetClient())
26+
{
27+
client.FlushAll();
28+
29+
client.SetEntry("Sentinel3Setup", "IntranetSentinel");
30+
31+
var result = client.GetEntry("Sentinel3Setup");
32+
Assert.That(result, Is.EqualTo("IntranetSentinel"));
33+
}
34+
}
35+
36+
static string[] GoogleCloudSentinelHosts = new[]
37+
{
38+
"146.148.77.31",
39+
"130.211.139.141",
40+
"107.178.218.53",
41+
};
42+
43+
[Test]
44+
public void Can_connect_directly_to_Redis_Instances()
45+
{
46+
foreach (var host in GoogleCloudSentinelHosts)
47+
{
48+
using (var client = new RedisClient(host, 6379))
49+
{
50+
"{0}:6379".Print(host);
51+
client.Info.PrintDump();
52+
}
53+
54+
using (var sentinel = new RedisClient(host, 26379))
55+
{
56+
"{0}:26379".Print(host);
57+
sentinel.Info.PrintDump();
58+
}
59+
}
60+
}
61+
62+
[Test]
63+
public void Can_connect_to_GoogleCloud_3SentinelSetup()
64+
{
65+
var sentinel = new RedisSentinel(GoogleCloudSentinelHosts, masterName: "master")
66+
{
67+
IpAddressMap = {
68+
{"10.240.34.152", "146.148.77.31"},
69+
{"10.240.203.193","130.211.139.141"},
70+
{"10.240.209.52", "107.178.218.53"},
71+
}
72+
};
73+
74+
var redisManager = sentinel.Start();
75+
76+
using (var client = redisManager.GetClient())
77+
{
78+
"{0}:{1}".Print(client.Host, client.Port);
79+
80+
client.FlushAll();
81+
82+
client.SetEntry("Sentinel3Setup", "GoogleCloud");
83+
84+
var result = client.GetEntry("Sentinel3Setup");
85+
86+
Assert.That(result, Is.EqualTo("GoogleCloud"));
87+
}
88+
}
89+
}
90+
}

tests/ServiceStack.Redis.Tests/ServiceStack.Redis.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
<Compile Include="ConfigTests.cs" />
185185
<Compile Include="CustomCommandTests.cs" />
186186
<Compile Include="Issues\RedisCharacterizationTests.cs" />
187+
<Compile Include="Redis3SentinelSetupTests.cs" />
187188
<Compile Include="RedisBatchTests.cs" />
188189
<Compile Include="RedisManagerPoolTests.cs" />
189190
<Compile Include="DiagnosticTests.cs" />

0 commit comments

Comments
 (0)