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(); }
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(); }
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); }