예제 #1
0
        public void With_authenticators_should_return_expected_result()
        {
            var oldAuthenticators = new[] { new MongoDBCRAuthenticator(new UsernamePasswordCredential("source", "username1", "password1")) };
            var newAuthenticators = new[] { new MongoDBCRAuthenticator(new UsernamePasswordCredential("source", "username2", "password2")) };
            var subject           = new ConnectionSettings(authenticators: oldAuthenticators);

            var result = subject.With(authenticators: newAuthenticators);

            result.Authenticators.Should().Equal(newAuthenticators);
            result.MaxIdleTime.Should().Be(subject.MaxIdleTime);
            result.MaxLifeTime.Should().Be(subject.MaxLifeTime);
        }
예제 #2
0
        public void With_maxLifeTime_should_return_expected_result()
        {
            var oldMaxLifeTime = TimeSpan.FromSeconds(1);
            var newMaxLifeTime = TimeSpan.FromSeconds(2);
            var subject        = new ConnectionSettings(maxLifeTime: oldMaxLifeTime);

            var result = subject.With(maxLifeTime: newMaxLifeTime);

            result.Authenticators.Should().Equal(subject.Authenticators);
            result.MaxIdleTime.Should().Be(subject.MaxIdleTime);
            result.MaxLifeTime.Should().Be(newMaxLifeTime);
        }
        public void With_applicationName_should_return_expected_result()
        {
            var oldApplicationName = "app1";
            var newApplicationName = "app2";
            var subject            = new ConnectionSettings(applicationName: oldApplicationName);

            var result = subject.With(applicationName: newApplicationName);

            result.ApplicationName.Should().Be(newApplicationName);
            result.Authenticators.Should().Equal(subject.Authenticators);
            result.MaxIdleTime.Should().Be(subject.MaxIdleTime);
            result.MaxLifeTime.Should().Be(subject.MaxLifeTime);
        }
        public void With_compressors_should_return_expected_result()
        {
            var oldCompressors = new[] { new CompressorConfiguration(CompressorType.Zlib) };
            var newCompressors = new[] { new CompressorConfiguration(CompressorType.Snappy) };
            var subject        = new ConnectionSettings(compressors: oldCompressors);

            var result = subject.With(compressors: newCompressors);

            result.ApplicationName.Should().Be(subject.ApplicationName);
            result.AuthenticatorFactories.Should().Equal(subject.AuthenticatorFactories);
            result.Compressors.Should().Equal(newCompressors);
            result.MaxIdleTime.Should().Be(subject.MaxIdleTime);
            result.MaxLifeTime.Should().Be(subject.MaxLifeTime);
        }
        public void With_authenticatorFactories_should_return_expected_result()
        {
            var oldAuthenticatorFactories = new[] { new AuthenticatorFactory(() => null) };
            var newAuthenticatorFactories = new[] { new AuthenticatorFactory(() => null) };

            var subject = new ConnectionSettings(authenticatorFactories: oldAuthenticatorFactories);

            var result = subject.With(authenticatorFactories: newAuthenticatorFactories);

            result.ApplicationName.Should().Be(subject.ApplicationName);
            result.AuthenticatorFactories.Should().Equal(newAuthenticatorFactories);
            subject.Compressors.Should().Equal(subject.Compressors);
            result.MaxIdleTime.Should().Be(subject.MaxIdleTime);
            result.MaxLifeTime.Should().Be(subject.MaxLifeTime);
        }
예제 #6
0
        // methods
        /// <summary>
        /// Builds the cluster.
        /// </summary>
        /// <returns>A cluster.</returns>
        public ICluster BuildCluster()
        {
            IStreamFactory streamFactory = new TcpStreamFactory(_tcpStreamSettings);

            if (_sslStreamSettings != null)
            {
                streamFactory = new SslStreamFactory(_sslStreamSettings, streamFactory);
            }

            streamFactory = _streamFactoryWrapper(streamFactory);

            var connectionFactory = new BinaryConnectionFactory(
                _connectionSettings,
                streamFactory,
                _eventAggregator);

            var connectionPoolFactory = new ExclusiveConnectionPoolFactory(
                _connectionPoolSettings,
                connectionFactory,
                _eventAggregator);

            var serverMonitorConnectionSettings = _connectionSettings.With(authenticators: new IAuthenticator[] { });
            var serverMonitorConnectionFactory  = new BinaryConnectionFactory(
                serverMonitorConnectionSettings,
                streamFactory,
                new EventAggregator());
            var serverMonitorFactory = new ServerMonitorFactory(
                _serverSettings,
                serverMonitorConnectionFactory,
                _eventAggregator);

            var serverFactory = new ServerFactory(
                _clusterSettings.ConnectionMode,
                _serverSettings,
                connectionPoolFactory,
                serverMonitorFactory,
                _eventAggregator);

            var clusterFactory = new ClusterFactory(
                _clusterSettings,
                serverFactory,
                _eventAggregator);

            return(clusterFactory.CreateCluster());
        }
        private IServerMonitorFactory CreateServerMonitorFactory()
        {
            var serverMonitorConnectionSettings = _connectionSettings
                                                  .With(authenticatorFactories: new IAuthenticatorFactory[] { });

            var heartbeatConnectTimeout = _tcpStreamSettings.ConnectTimeout;

            if (heartbeatConnectTimeout == TimeSpan.Zero || heartbeatConnectTimeout == Timeout.InfiniteTimeSpan)
            {
                heartbeatConnectTimeout = TimeSpan.FromSeconds(30);
            }
            var heartbeatSocketTimeout = _serverSettings.HeartbeatTimeout;

            if (heartbeatSocketTimeout == TimeSpan.Zero || heartbeatSocketTimeout == Timeout.InfiniteTimeSpan)
            {
                heartbeatSocketTimeout = heartbeatConnectTimeout;
            }
            var serverMonitorTcpStreamSettings = new TcpStreamSettings(_tcpStreamSettings)
                                                 .With(
                connectTimeout: heartbeatConnectTimeout,
                readTimeout: heartbeatSocketTimeout,
                writeTimeout: heartbeatSocketTimeout
                );

            var serverMonitorStreamFactory = CreateTcpStreamFactory(serverMonitorTcpStreamSettings);
            var serverMonitorSettings      = new ServerMonitorSettings(
                connectTimeout: serverMonitorTcpStreamSettings.ConnectTimeout,
                heartbeatInterval: _serverSettings.HeartbeatInterval);

            var serverMonitorConnectionFactory = new BinaryConnectionFactory(
                serverMonitorConnectionSettings,
                serverMonitorStreamFactory,
                new EventAggregator(),
                _clusterSettings.ServerApi);

            return(new ServerMonitorFactory(
                       serverMonitorSettings,
                       serverMonitorConnectionFactory,
                       _eventAggregator,
                       _clusterSettings.ServerApi));
        }
 private ConnectionSettings ConfigureConnection(ConnectionSettings settings, ClusterKey clusterKey)
 {
     var authenticators = clusterKey.Credentials.Select(c => c.ToAuthenticator());
     return settings.With(
         authenticators: Optional.Enumerable(authenticators),
         maxIdleTime: clusterKey.MaxConnectionIdleTime,
         maxLifeTime: clusterKey.MaxConnectionLifeTime,
         applicationName: clusterKey.ApplicationName);
 }
예제 #9
0
        public void With_maxLifeTime_should_return_expected_result()
        {
            var oldMaxLifeTime = TimeSpan.FromSeconds(1);
            var newMaxLifeTime = TimeSpan.FromSeconds(2);
            var subject = new ConnectionSettings(maxLifeTime: oldMaxLifeTime);

            var result = subject.With(maxLifeTime: newMaxLifeTime);

            result.Authenticators.Should().Equal(subject.Authenticators);
            result.MaxIdleTime.Should().Be(subject.MaxIdleTime);
            result.MaxLifeTime.Should().Be(newMaxLifeTime);
        }
예제 #10
0
        public void With_authenticators_should_return_expected_result()
        {
            var oldAuthenticators = new[] { new MongoDBCRAuthenticator(new UsernamePasswordCredential("source", "username1", "password1")) };
            var newAuthenticators = new[] { new MongoDBCRAuthenticator(new UsernamePasswordCredential("source", "username2", "password2")) };
            var subject = new ConnectionSettings(authenticators: oldAuthenticators);

            var result = subject.With(authenticators: newAuthenticators);

            result.Authenticators.Should().Equal(newAuthenticators);
            result.MaxIdleTime.Should().Be(subject.MaxIdleTime);
            result.MaxLifeTime.Should().Be(subject.MaxLifeTime);
        }
        public void With_applicationName_should_return_expected_result()
        {
            var oldApplicationName = "app1";
            var newApplicationName = "app2";
            var subject = new ConnectionSettings(applicationName: oldApplicationName);

            var result = subject.With(applicationName: newApplicationName);

            result.ApplicationName.Should().Be(newApplicationName);
            result.Authenticators.Should().Equal(subject.Authenticators);
            result.MaxIdleTime.Should().Be(subject.MaxIdleTime);
            result.MaxLifeTime.Should().Be(subject.MaxLifeTime);
        }