public void Test_Filter_Removed_Nodes(string oldConfigPath, string newConfigPath) { var oldConfig = ResourceHelper.ReadResource <BucketConfig>(oldConfigPath); var newConfig = ResourceHelper.ReadResource <BucketConfig>(newConfigPath); var options = new ClusterOptions(); var bucketNodes = new ConcurrentDictionary <IPEndPoint, IClusterNode>(); var context = new ClusterContext(null, options); //load up the initial state after bootstrapping foreach (var server in oldConfig.NodesExt) { var endPoint = server.GetIpEndPoint(options); var clusterNode = new ClusterNode(context, new Mock <IConnectionFactory>().Object, new Mock <ILogger <ClusterNode> >().Object, new Mock <ITypeTranscoder>().Object, new Mock <ICircuitBreaker>().Object, new Mock <ISaslMechanismFactory>().Object) { EndPoint = endPoint }; context.AddNode(clusterNode); bucketNodes.TryAdd(endPoint, clusterNode); } foreach (var nodesExt in newConfig.NodesExt) { var endPoint = nodesExt.GetIpEndPoint(options); if (bucketNodes.ContainsKey(endPoint)) { continue; } var clusterNode = new ClusterNode(context, new Mock <IConnectionFactory>().Object, new Mock <ILogger <ClusterNode> >().Object, new Mock <ITypeTranscoder>().Object, new Mock <ICircuitBreaker>().Object, new Mock <ISaslMechanismFactory>().Object) { EndPoint = endPoint }; context.AddNode(clusterNode); bucketNodes.TryAdd(endPoint, clusterNode); } var removed = bucketNodes.Where(x => !newConfig.NodesExt.Any(y => x.Key.Equals(y.GetIpEndPoint(options)))); foreach (var valuePair in removed) { if (!bucketNodes.TryRemove(valuePair.Key, out var clusterNode)) { continue; } context.RemoveNode(clusterNode); } Assert.Equal(newConfig.NodesExt.Count, bucketNodes.Count); Assert.Equal(context.Nodes.Count, bucketNodes.Count); }