public void Can_failover_MqServer_at_runtime() { const int iterations = 100; var failoverHost = "redis-failover:6379"; var localClient = new RedisClient("localhost:6379"); localClient.FlushDb(); var failoverClient = new RedisClient(failoverHost); failoverClient.FlushDb(); var clientManager = new PooledRedisClientManager(new[] { "localhost" }); var mqHost = new RedisMqServer(clientManager); var map = new Dictionary<string, int>(); var received = 0; mqHost.RegisterHandler<Msg>(c => { var dto = c.GetBody(); received++; int count; map.TryGetValue(dto.Host, out count); map[dto.Host] = count + 1; lock (clientManager) { "Received #{0} from {1}".Print(received, dto.Host); if (received == iterations) Monitor.Pulse(clientManager); } return null; }); mqHost.Start(); RunMqInLoop(mqHost, iterations: iterations, callback: () => { lock (clientManager) "{0} msgs were published.".Print(iterations); }); Thread.Sleep(500); clientManager.FailoverTo(failoverHost); lock (clientManager) Monitor.Wait(clientManager); "localclient inq: {0}, outq: {1}".Print( localClient.GetListCount("mq:Msg.inq"), localClient.GetListCount("mq:Msg.outq")); "failoverClient inq: {0}, outq: {1}".Print( failoverClient.GetListCount("mq:Msg.inq"), failoverClient.GetListCount("mq:Msg.outq")); Assert.That(received, Is.EqualTo(100)); Assert.That(map.Count, Is.EqualTo(2)); var msgsFromAllHosts = 0; foreach (var count in map.Values) { Assert.That(count, Is.GreaterThan(0)); msgsFromAllHosts += count; } Assert.That(msgsFromAllHosts, Is.EqualTo(iterations)); }
public void Can_failover_at_runtime() { var failoverHost = "redis-failover:6379"; string key = "test:failover"; var localClient = new RedisClient("localhost"); localClient.Remove(key); var failoverClient = new RedisClient(failoverHost); failoverClient.Remove(key); var clientManager = new PooledRedisClientManager(new[] { "localhost" }); RunInLoop(clientManager, callback:() => { lock (clientManager) Monitor.Pulse(clientManager); }); Thread.Sleep(100); clientManager.FailoverTo(failoverHost); lock (clientManager) Monitor.Wait(clientManager); var localIncr = localClient.Get<int>(key); var failoverIncr = failoverClient.Get<int>(key); Assert.That(localIncr, Is.GreaterThan(0)); Assert.That(failoverIncr, Is.GreaterThan(0)); Assert.That(localIncr + failoverIncr, Is.EqualTo(100)); }