public void Test_Filter_Removed_Nodes(string oldConfigPath, string newConfigPath) { var oldConfig = ResourceHelper.ReadResource <BucketConfig>(oldConfigPath); var newConfig = ResourceHelper.ReadResource <BucketConfig>(newConfigPath); var configuration = new ClusterOptions(); var bucketNodes = new ConcurrentDictionary <IPEndPoint, IClusterNode>(); //load up the initial state after bootstrapping foreach (var server in oldConfig.NodesExt) { var endPoint = server.GetIpEndPoint(configuration); var clusterNode = new ClusterNode { EndPoint = endPoint }; configuration.GlobalNodes.Add(clusterNode); bucketNodes.TryAdd(endPoint, clusterNode); } foreach (var nodesExt in newConfig.NodesExt) { var endPoint = nodesExt.GetIpEndPoint(configuration); if (bucketNodes.ContainsKey(endPoint)) { continue; } var clusterNode = new ClusterNode { EndPoint = endPoint }; configuration.GlobalNodes.Add(clusterNode); bucketNodes.TryAdd(endPoint, clusterNode); } var removed = bucketNodes.Where(x => !newConfig.NodesExt.Any(y => x.Key.Equals(y.GetIpEndPoint(configuration)))); foreach (var valuePair in removed) { if (!bucketNodes.TryRemove(valuePair.Key, out var clusterNode)) { continue; } if (configuration.GlobalNodes.TryTake(out clusterNode)) { clusterNode.Dispose(); } } Assert.Equal(newConfig.NodesExt.Count, bucketNodes.Count); Assert.Equal(configuration.GlobalNodes.Count, bucketNodes.Count); }