|
1 | | -using System.Linq; |
| 1 | +using System; |
| 2 | +using System.Linq; |
2 | 3 | using System.Text; |
| 4 | +using System.Threading; |
3 | 5 | using NUnit.Framework; |
| 6 | +using ServiceStack.Logging; |
| 7 | +using ServiceStack.Text; |
| 8 | +using Timer = System.Timers.Timer; |
4 | 9 |
|
5 | 10 | namespace ServiceStack.Redis.Tests |
6 | 11 | { |
@@ -112,5 +117,58 @@ public void Can_specify_db_on_RedisSentinel() |
112 | 117 | Assert.That(client.Db, Is.EqualTo(1)); |
113 | 118 | } |
114 | 119 | } |
| 120 | + |
| 121 | + [Test] |
| 122 | + public void Run_sentinel_for_10_minutes() |
| 123 | + { |
| 124 | + LogManager.LogFactory = new ConsoleLogFactory(debugEnabled:true); |
| 125 | + |
| 126 | + var sentinelHost = "{0}:{1}".Fmt(TestConfig.SentinelHost, TestConfig.RedisSentinelPort); |
| 127 | + var sentinel = new RedisSentinel(sentinelHost, TestConfig.MasterName) |
| 128 | + { |
| 129 | + OnFailover = manager => |
| 130 | + { |
| 131 | + "Redis Managers Failed Over to new hosts".Print(); |
| 132 | + }, |
| 133 | + OnWorkerError = ex => |
| 134 | + { |
| 135 | + "Worker error: {0}".Print(ex); |
| 136 | + }, |
| 137 | + OnSentinelMessageReceived = (channel, msg) => |
| 138 | + { |
| 139 | + "Received '{0}' on channel '{1}' from Sentinel".Print(channel, msg); |
| 140 | + }, |
| 141 | + }; |
| 142 | + |
| 143 | + var redisManager = sentinel.Start(); |
| 144 | + |
| 145 | + var aTimer = new Timer |
| 146 | + { |
| 147 | + Interval = 1000, |
| 148 | + Enabled = true |
| 149 | + }; |
| 150 | + aTimer.Elapsed += (sender, args) => |
| 151 | + { |
| 152 | + "Incrementing key".Print(); |
| 153 | + |
| 154 | + string key = null; |
| 155 | + using (var redis = redisManager.GetClient()) |
| 156 | + { |
| 157 | + var counter = redis.Increment("key", 1); |
| 158 | + key = "key" + counter; |
| 159 | + "Set key {0} in read/write client".Print(key); |
| 160 | + redis.SetEntry(key, "value" + 1); |
| 161 | + } |
| 162 | + |
| 163 | + using (var redis = redisManager.GetClient()) |
| 164 | + { |
| 165 | + "Get key {0} in read-only client...".Print(key); |
| 166 | + var value = redis.GetEntry(key); |
| 167 | + "{0} = {1}".Print(key, value); |
| 168 | + } |
| 169 | + }; |
| 170 | + |
| 171 | + Thread.Sleep(TimeSpan.FromMinutes(10)); |
| 172 | + } |
115 | 173 | } |
116 | 174 | } |
0 commit comments