Exemplo n.º 1
0
        public ClusterController(ClientConfiguration clientConfig,
                                 Func <IConnectionPool, IIOService> ioServiceFactory,
                                 Func <PoolConfiguration, IPEndPoint, IConnectionPool> connectionPoolFactory,
                                 Func <string, string, IConnectionPool, ITypeTranscoder, ISaslMechanism> saslFactory,
                                 IByteConverter converter,
                                 ITypeTranscoder transcoder)
        {
            _clientConfig          = clientConfig;
            _ioServiceFactory      = ioServiceFactory;
            _connectionPoolFactory = connectionPoolFactory;
            _saslFactory           = saslFactory;
            Converter  = converter;
            Transcoder = transcoder;
            Initialize();

            if (clientConfig.EnableDeadServiceUriPing)
            {
                _clusterMonitor = new ClusterMonitor(this);
                _clusterMonitor.StartMonitoring();
            }

            LastConfigCheckedTime = DateTime.Now;
            if (Configuration.EnableConfigHeartBeat)
            {
                _configMonitor = new ConfigMonitor(this);
                _configMonitor.StartMonitoring();
            }

            _configThread = new Thread(ProcessConfig)
            {
                Name         = "CT",
                IsBackground = true
            };
            _configThread.Start();
        }
        public async Task Test_StartMonitoring()
        {
            var clientConfig = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri("http://10.111.160.101:8091"),
                    new Uri("http://10.111.160.102:8091"),
                    new Uri("http://10.111.160.104:8091")
                },
                BucketConfigs = new Dictionary <string, BucketConfiguration>
                {
                    {
                        "default", new BucketConfiguration
                        {
                            BucketName = "default",
                            Username   = "******",
                            Password   = ""
                        }
                    },
                    {
                        "travel-sample", new BucketConfiguration
                        {
                            BucketName = "travel-sample",
                            Username   = "******",
                            Password   = ""
                        }
                    },
                },
                HeartbeatConfigInterval        = 500,
                OperationTracingEnabled        = false,
                OrphanedResponseLoggingEnabled = false
            };

            clientConfig.Initialize();
            var configProvider = new Mock <IConfigProvider>();
            var controller     = new Mock <IClusterController>();

            controller.Setup(x => x.Configuration).Returns(clientConfig);
            controller.Setup(x => x.ConfigProviders).Returns(new List <IConfigProvider> {
                configProvider.Object
            });

            var cts     = new CancellationTokenSource();
            var monitor = new ConfigMonitor(controller.Object, cts);

            monitor.StartMonitoring();

            await Task.Delay(3000);

            controller.Verify(x => x.LastConfigCheckedTime, Times.AtLeast(1));
            monitor.Dispose();
        }
        public void Test_Dispose()
        {
            var clientConfig = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri("http://10.111.160.101:8091"),
                    new Uri("http://10.111.160.102:8091"),
                    new Uri("http://10.111.160.104:8091")
                },
                BucketConfigs = new Dictionary <string, BucketConfiguration>
                {
                    {
                        "default", new BucketConfiguration
                        {
                            BucketName = "default",
                            Username   = "******",
                            Password   = ""
                        }
                    },
                    {
                        "travel-sample", new BucketConfiguration
                        {
                            BucketName = "travel-sample",
                            Username   = "******",
                            Password   = ""
                        }
                    }
                },
                HeartbeatConfigInterval = 1000
            };

            clientConfig.Initialize();
            var configProvider = new Mock <IConfigProvider>();
            var controller     = new Mock <IClusterController>();

            controller.Setup(x => x.Configuration).Returns(clientConfig);
            controller.Setup(x => x.ConfigProviders).Returns(new List <IConfigProvider> {
                configProvider.Object
            });

            var cts     = new CancellationTokenSource();
            var monitor = new ConfigMonitor(controller.Object, cts);

            monitor.StartMonitoring();
            Thread.Sleep(1500);
            monitor.Dispose();
            Assert.IsTrue(cts.IsCancellationRequested);
        }