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

Commit da1c675

Browse files
committed
adding sentinel tests
1 parent 9d55712 commit da1c675

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NUnit.Framework;
6+
7+
namespace ServiceStack.Redis.Tests
8+
{
9+
[TestFixture, Category("Integration")]
10+
public class RedisSentinelTests
11+
: RedisClientTestsBase
12+
{
13+
protected RedisClient RedisSentinel;
14+
15+
16+
public override void OnBeforeEachTest()
17+
{
18+
base.OnBeforeEachTest();
19+
20+
RedisSentinel = new RedisClient(TestConfig.SingleHost, TestConfig.RedisSentinelPort);
21+
}
22+
23+
24+
public override void TearDown()
25+
{
26+
base.TearDown();
27+
28+
RedisSentinel.Dispose();
29+
}
30+
31+
32+
[Test]
33+
public void Can_Ping_Sentinel()
34+
{
35+
Assert.True(RedisSentinel.Ping());
36+
}
37+
38+
[Test]
39+
public void Can_Get_Sentinel_Masters()
40+
{
41+
object[] masters = RedisSentinel.Sentinel("masters");
42+
43+
Assert.AreEqual(masters.Count(), TestConfig.MasterHosts.Count());
44+
}
45+
46+
[Test]
47+
public void Can_Get_Sentinel_Slaves()
48+
{
49+
object[] slaves = RedisSentinel.Sentinel("slaves", TestConfig.MasterName);
50+
51+
Assert.AreEqual(slaves.Count(), TestConfig.SlaveHosts.Count());
52+
}
53+
54+
[Test]
55+
public void Can_Get_Master_Addr()
56+
{
57+
object[] addr = RedisSentinel.Sentinel("get-master-addr-by-name", TestConfig.MasterName);
58+
59+
string host = Encoding.UTF8.GetString((byte[])addr[0]);
60+
string port = Encoding.UTF8.GetString((byte[])addr[1]);
61+
62+
Assert.AreEqual(host, "127.0.0.1"); // IP of localhost
63+
Assert.AreEqual(port, TestConfig.RedisPort.ToString());
64+
}
65+
}
66+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
<Compile Include="Properties\AssemblyInfo.cs" />
233233
<Compile Include="RedisClientTestsBase.cs" />
234234
<Compile Include="RedisPubSubTests.cs" />
235+
<Compile Include="RedisSentinelTests.cs" />
235236
<Compile Include="RedisTransactionCommonTests.cs" />
236237
<Compile Include="RedisTransactionTests.cs" />
237238
<Compile Include="RedisUtilTests.cs" />

tests/ServiceStack.Redis.Tests/TestConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ static TestConfig()
1313
public const bool IgnoreLongTests = true;
1414

1515
public const string SingleHost = "localhost";
16+
public const string MasterName = "mymaster";
1617
public static readonly string[] MasterHosts = new[] { "localhost" };
1718
public static readonly string[] SlaveHosts = new[] { "localhost" };
1819

1920
public const int RedisPort = 6379;
21+
public const int RedisSentinelPort = 26379;
2022

2123
public static string SingleHostConnectionString
2224
{

0 commit comments

Comments
 (0)