public async Task falls_back_to_first_alive_node_if_a_preferred_node_is_not_found(bool useHttps) { var gossip = new ClusterMessages.ClusterInfo { Members = new[] { new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Leader, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 1111), IsAlive = false, }, new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Follower, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 2222), IsAlive = true, }, } }; var sut = new GossipBasedEndpointDiscoverer( new EventStoreClientConnectivitySettings { MaxDiscoverAttempts = 1, GossipTimeout = System.Threading.Timeout.InfiniteTimeSpan, Insecure = !useHttps, DiscoveryInterval = TimeSpan.Zero, NodePreference = NodePreference.Leader, DnsGossipSeeds = new[] { _gossipSeed } }, new CallbackTestGossipClient(gossip)); var result = await sut.DiscoverAsync(); Assert.Equal(result.GetPort(), gossip.Members.Last(x => x.State == ClusterMessages.VNodeState.Follower).EndPoint.Port); }
public async Task should_issue_gossip_to_gossip_seed(bool useHttps) { var endPoint = new DnsEndPoint(IPAddress.Any.ToString(), 4444); var gossip = new ClusterMessages.ClusterInfo { Members = new[] { new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Leader, InstanceId = Guid.NewGuid(), EndPoint = endPoint, IsAlive = true, }, } }; var sut = new GossipBasedEndpointDiscoverer( new EventStoreClientConnectivitySettings { MaxDiscoverAttempts = 1, GossipTimeout = System.Threading.Timeout.InfiniteTimeSpan, Insecure = !useHttps, DiscoveryInterval = TimeSpan.Zero, NodePreference = NodePreference.Leader, DnsGossipSeeds = new[] { _gossipSeed } }, new CallbackTestGossipClient(gossip)); var result = await sut.DiscoverAsync(); Assert.Equal(result, endPoint); }
internal async Task should_not_be_able_to_pick_invalid_node(bool useHttps, ClusterMessages.VNodeState invalidState) { var gossip = new ClusterMessages.ClusterInfo { Members = new[] { new ClusterMessages.MemberInfo { State = invalidState, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 4444), IsAlive = true, }, } }; var sut = new GossipBasedEndpointDiscoverer( new EventStoreClientConnectivitySettings { MaxDiscoverAttempts = 1, GossipTimeout = System.Threading.Timeout.InfiniteTimeSpan, Insecure = !useHttps, DiscoveryInterval = TimeSpan.Zero, NodePreference = NodePreference.Leader, DnsGossipSeeds = new[] { _gossipSeed } }, new CallbackTestGossipClient(gossip)); var ex = await Assert.ThrowsAsync <DiscoveryException>(async() => await sut.DiscoverAsync()); Assert.Equal(1, ex.MaxDiscoverAttempts); }
public async Task should_be_able_to_discover_twice(bool useHttps) { var firstGossip = new ClusterMessages.ClusterInfo { Members = new[] { new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Leader, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 1111), IsAlive = true, }, new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Follower, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 2222), IsAlive = true, }, } }; var secondGossip = new ClusterMessages.ClusterInfo { Members = new[] { new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Leader, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 1111), IsAlive = false, }, new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Leader, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 2222), IsAlive = true, }, } }; var sut = new GossipBasedEndpointDiscoverer( new EventStoreClientConnectivitySettings { MaxDiscoverAttempts = 5, GossipTimeout = System.Threading.Timeout.InfiniteTimeSpan, Insecure = !useHttps, DiscoveryInterval = TimeSpan.Zero, NodePreference = NodePreference.Leader, DnsGossipSeeds = new[] { _gossipSeed } }, new MultiGossipCallback(firstGossip, secondGossip)); var result = await sut.DiscoverAsync(); var expected = firstGossip.Members.First(x => x.EndPoint.Port == 1111); Assert.Equal(expected.EndPoint.Host, result.GetHost()); Assert.Equal(expected.EndPoint.Port, result.GetPort()); result = await sut.DiscoverAsync(); expected = secondGossip.Members.First(x => x.EndPoint.Port == 2222); Assert.Equal(expected.EndPoint.Host, result.GetHost()); Assert.Equal(expected.EndPoint.Port, result.GetPort()); }
internal async Task should_pick_node_based_on_preference(bool useHttps, NodePreference preference, ClusterMessages.VNodeState expectedState) { var gossip = new ClusterMessages.ClusterInfo { Members = new[] { new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Leader, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 1111), IsAlive = true, }, new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Follower, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 2222), IsAlive = true, }, new ClusterMessages.MemberInfo { State = expectedState == ClusterMessages.VNodeState.ReadOnlyLeaderless ? expectedState : ClusterMessages.VNodeState.ReadOnlyReplica, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 3333), IsAlive = true, }, new ClusterMessages.MemberInfo { State = ClusterMessages.VNodeState.Manager, InstanceId = Guid.NewGuid(), EndPoint = new DnsEndPoint(IPAddress.Any.ToString(), 4444), IsAlive = true, }, } }; var sut = new GossipBasedEndpointDiscoverer( new EventStoreClientConnectivitySettings { MaxDiscoverAttempts = 1, GossipTimeout = System.Threading.Timeout.InfiniteTimeSpan, Insecure = !useHttps, DiscoveryInterval = TimeSpan.Zero, NodePreference = preference, DnsGossipSeeds = new[] { _gossipSeed } }, new CallbackTestGossipClient(gossip)); var result = await sut.DiscoverAsync(); Assert.Equal(result.GetPort(), gossip.Members.Last(x => x.State == expectedState).EndPoint.Port); }