-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathTestConfig.cs
131 lines (108 loc) · 4.78 KB
/
TestConfig.cs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Threading;
using Newtonsoft.Json;
namespace StackExchange.Redis.Tests;
public static class TestConfig
{
private const string FileName = "TestConfig.json";
public static Config Current { get; }
private static int _db = 17;
public static int GetDedicatedDB(IConnectionMultiplexer? conn = null)
{
int db = Interlocked.Increment(ref _db);
if (conn != null) Skip.IfMissingDatabase(conn, db);
return db;
}
static TestConfig()
{
Current = new Config();
try
{
using (var stream = typeof(TestConfig).Assembly.GetManifestResourceStream("StackExchange.Redis.Tests." + FileName))
{
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
Current = JsonConvert.DeserializeObject<Config>(reader.ReadToEnd()) ?? new Config();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error Deserializing TestConfig.json: " + ex);
}
}
public static bool IsServerRunning(string? host, int port)
{
if (host.IsNullOrEmpty())
{
return false;
}
try
{
using var client = new TcpClient(host, port);
return true;
}
catch (SocketException)
{
return false;
}
}
public class Config
{
public bool UseSharedConnection { get; set; } = true;
public bool RunLongRunning { get; set; }
public bool LogToConsole { get; set; }
public string PrimaryServer { get; set; } = "127.0.0.1";
public int PrimaryPort { get; set; } = 6379;
public string PrimaryServerAndPort => PrimaryServer + ":" + PrimaryPort.ToString();
public string ReplicaServer { get; set; } = "127.0.0.1";
public int ReplicaPort { get; set; } = 6380;
public string ReplicaServerAndPort => ReplicaServer + ":" + ReplicaPort.ToString();
public string SecureServer { get; set; } = "127.0.0.1";
public int SecurePort { get; set; } = 6381;
public string SecurePassword { get; set; } = "changeme";
public string SecureServerAndPort => SecureServer + ":" + SecurePort.ToString();
// Separate servers for failover tests, so they don't wreak havoc on all others
public string FailoverPrimaryServer { get; set; } = "127.0.0.1";
public int FailoverPrimaryPort { get; set; } = 6382;
public string FailoverPrimaryServerAndPort => FailoverPrimaryServer + ":" + FailoverPrimaryPort.ToString();
public string FailoverReplicaServer { get; set; } = "127.0.0.1";
public int FailoverReplicaPort { get; set; } = 6383;
public string FailoverReplicaServerAndPort => FailoverReplicaServer + ":" + FailoverReplicaPort.ToString();
public string IPv4Server { get; set; } = "127.0.0.1";
public int IPv4Port { get; set; } = 6379;
public string IPv6Server { get; set; } = "::1";
public int IPv6Port { get; set; } = 6379;
public string RemoteServer { get; set; } = "127.0.0.1";
public int RemotePort { get; set; } = 6379;
public string RemoteServerAndPort => RemoteServer + ":" + RemotePort.ToString();
public string SentinelServer { get; set; } = "127.0.0.1";
public int SentinelPortA { get; set; } = 26379;
public int SentinelPortB { get; set; } = 26380;
public int SentinelPortC { get; set; } = 26381;
public string SentinelSeviceName { get; set; } = "myprimary";
public string ClusterServer { get; set; } = "127.0.0.1";
public int ClusterStartPort { get; set; } = 7000;
public int ClusterServerCount { get; set; } = 6;
public string ClusterServersAndPorts => string.Join(",", Enumerable.Range(ClusterStartPort, ClusterServerCount).Select(port => ClusterServer + ":" + port));
public string? SslServer { get; set; } = "127.0.0.1";
public int SslPort { get; set; } = 6384;
public string SslServerAndPort => SslServer + ":" + SslPort.ToString();
public string? RedisLabsSslServer { get; set; }
public int RedisLabsSslPort { get; set; } = 6379;
public string? RedisLabsPfxPath { get; set; }
public string? AzureCacheServer { get; set; }
public string? AzureCachePassword { get; set; }
public string? SSDBServer { get; set; }
public int SSDBPort { get; set; } = 8888;
public string ProxyServer { get; set; } = "127.0.0.1";
public int ProxyPort { get; set; } = 7015;
public string ProxyServerAndPort => ProxyServer + ":" + ProxyPort.ToString();
}
}