public void PruneNodes_Does_Not_Remove_Single_Service_Nodes()
        {
            //Arrange

            var config = ResourceHelper.ReadResource(@"Documents\Configs\rev-36310-service-per-node.json",
                                                     InternalSerializationContext.Default.BucketConfig);
            var context = new ClusterContext();

            var hosts = new List <string> {
                "10.143.194.101", "10.143.194.102", "10.143.194.103", "10.143.194.104"
            };

            hosts.ForEach(x => context.AddNode(CreateMockedNode(x, 11210)));

            //Act

            context.PruneNodes(config);

            //Assert

            foreach (var host in hosts)
            {
                var removed = new HostEndpointWithPort(host, 11210);

                Assert.Contains(context.Nodes, node => node.EndPoint.Equals(removed));
            }
        }
Пример #2
0
        public async Task Test_Filter_Removed_Nodes(string oldConfigPath, string newConfigPath)
        {
            var oldConfig = ResourceHelper.ReadResource(oldConfigPath, InternalSerializationContext.Default.BucketConfig);
            var newConfig = ResourceHelper.ReadResource(newConfigPath, InternalSerializationContext.Default.BucketConfig);

            var options     = new ClusterOptions();
            var bucketNodes = new ConcurrentDictionary <HostEndpointWithPort, IClusterNode>();
            var context     = new ClusterContext(new CancellationTokenSource(), options);

            var ipEndpointService = context.ServiceProvider.GetRequiredService <IIpEndPointService>();

            //load up the initial state after bootstrapping
            foreach (var server in oldConfig.GetNodes())
            {
                var endPoint    = HostEndpointWithPort.Create(server, options);
                var clusterNode = new ClusterNode(context, new Mock <IConnectionPoolFactory>().Object,
                                                  new Mock <ILogger <ClusterNode> >().Object,
                                                  new DefaultObjectPool <OperationBuilder>(new OperationBuilderPoolPolicy()),
                                                  new Mock <ICircuitBreaker>().Object,
                                                  new Mock <ISaslMechanismFactory>().Object,
                                                  new TypedRedactor(RedactionLevel.None),
                                                  endPoint,
                                                  server,
                                                  NoopRequestTracer.Instance);

                context.AddNode(clusterNode);
                bucketNodes.TryAdd(endPoint, clusterNode);
            }

            foreach (var nodesExt in newConfig.GetNodes())
            {
                var endPoint = HostEndpointWithPort.Create(nodesExt, options);
                if (bucketNodes.ContainsKey(endPoint))
                {
                    continue;
                }

                var clusterNode = new ClusterNode(context, new Mock <IConnectionPoolFactory>().Object,
                                                  new Mock <ILogger <ClusterNode> >().Object,
                                                  new DefaultObjectPool <OperationBuilder>(new OperationBuilderPoolPolicy()),
                                                  new Mock <ICircuitBreaker>().Object, new Mock <ISaslMechanismFactory>().Object,
                                                  new TypedRedactor(RedactionLevel.None), endPoint, nodesExt,
                                                  NoopRequestTracer.Instance);

                context.AddNode(clusterNode);
                bucketNodes.TryAdd(endPoint, clusterNode);
            }

            context.PruneNodes(newConfig);

            Assert.Equal(newConfig.NodesExt.Count, context.Nodes.Count);
        }
        public void PruneNodes_Removes_Rebalanced_Node()
        {
            //Arrange

            var config = ResourceHelper.ReadResource(@"Documents\Configs\config-error.json",
                                                     InternalSerializationContext.Default.BucketConfig);
            var context = new ClusterContext();

            var hosts = new List <string> {
                "10.143.194.101", "10.143.194.102", "10.143.194.103", "10.143.194.104"
            };

            hosts.ForEach(x => context.AddNode(CreateMockedNode(x, 11210)));

            //Act

            context.PruneNodes(config);

            //Assert

            var removed = new HostEndpointWithPort("10.143.194.102", 11210);

            Assert.DoesNotContain(context.Nodes, node => node.EndPoint.Equals(removed));
        }