예제 #1
0
        public Sentinel(ITestOutputHelper output) : base(output)
        {
            ConnectionLog = new StringWriter();

            Skip.IfNoConfig(nameof(TestConfig.Config.SentinelServer), TestConfig.Current.SentinelServer);
            Skip.IfNoConfig(nameof(TestConfig.Config.SentinelSeviceName), TestConfig.Current.SentinelSeviceName);

            var options = ServiceOptions.Clone();

            options.EndPoints.Add(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortA);
            options.EndPoints.Add(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortB);
            options.EndPoints.Add(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortC);

            Conn = ConnectionMultiplexer.SentinelConnect(options, ConnectionLog);
            for (var i = 0; i < 150; i++)
            {
                Thread.Sleep(20);
                if (Conn.IsConnected && Conn.GetSentinelMasterConnection(options).IsConnected)
                {
                    break;
                }
            }
            Assert.True(Conn.IsConnected);
            SentinelServerA  = Conn.GetServer(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortA);
            SentinelServerB  = Conn.GetServer(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortB);
            SentinelServerC  = Conn.GetServer(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortC);
            SentinelsServers = new[] { SentinelServerA, SentinelServerB, SentinelServerC };

            // wait until we are in a state of a single master and replica
            WaitForReady();
        }
예제 #2
0
        public async Task InitializeAsync()
        {
            var options = ServiceOptions.Clone();

            options.EndPoints.Add(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortA);
            options.EndPoints.Add(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortB);
            options.EndPoints.Add(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortC);
            Conn = ConnectionMultiplexer.SentinelConnect(options, Writer);

            for (var i = 0; i < 150; i++)
            {
                await Task.Delay(100).ForAwait();

                if (Conn.IsConnected)
                {
                    using var checkConn = Conn.GetSentinelMasterConnection(options, Writer);
                    if (checkConn.IsConnected)
                    {
                        break;
                    }
                }
            }
            Assert.True(Conn.IsConnected);
            SentinelServerA  = Conn.GetServer(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortA);
            SentinelServerB  = Conn.GetServer(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortB);
            SentinelServerC  = Conn.GetServer(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortC);
            SentinelsServers = new[] { SentinelServerA, SentinelServerB, SentinelServerC };

            // wait until we are in a state of a single master and replica
            await WaitForReadyAsync();
        }
예제 #3
0
        public void SentinelConnectTest()
        {
            var options = ServiceOptions.Clone();

            options.EndPoints.Add(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPortA);

            var conn = ConnectionMultiplexer.SentinelConnect(options);
            var db   = conn.GetDatabase();

            var test = db.Ping();

            Log("ping to sentinel {0}:{1} took {2} ms", TestConfig.Current.SentinelServer,
                TestConfig.Current.SentinelPortA, test.TotalMilliseconds);
        }