示例#1
0
        public PSClusterKey(ClusterKey clusterKey)
        {
            if (clusterKey == null)
            {
                return;
            }

            Name    = clusterKey.Name;
            OrderBy = clusterKey.OrderBy;
        }
示例#2
0
        public void Constructor_with_MongoServerSettings_parameter_should_copy_relevant_values()
        {
            var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
            var servers     = new[] { new MongoServerAddress("localhost") };

            var sslSettings = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols        = SslProtocols.Ssl3
            };

            var serverSettings = new MongoServerSettings
            {
                ConnectionMode     = ConnectionMode.Direct,
                ConnectTimeout     = TimeSpan.FromSeconds(1),
                Credentials        = credentials,
                GuidRepresentation = GuidRepresentation.Standard,
                IPv6 = true,
                MaxConnectionIdleTime      = TimeSpan.FromSeconds(2),
                MaxConnectionLifeTime      = TimeSpan.FromSeconds(3),
                MaxConnectionPoolSize      = 10,
                MinConnectionPoolSize      = 5,
                ReplicaSetName             = "rs",
                SecondaryAcceptableLatency = TimeSpan.FromMilliseconds(20),
                Servers              = servers,
                SocketTimeout        = TimeSpan.FromSeconds(4),
                SslSettings          = sslSettings,
                UseSsl               = true,
                VerifySslCertificate = true,
                WaitQueueSize        = 20,
                WaitQueueTimeout     = TimeSpan.FromSeconds(5)
            };

            var subject = new ClusterKey(serverSettings);

            subject.ConnectionMode.Should().Be(serverSettings.ConnectionMode);
            subject.ConnectTimeout.Should().Be(serverSettings.ConnectTimeout);
            subject.Credentials.Should().Equal(serverSettings.Credentials);
            subject.IPv6.Should().Be(serverSettings.IPv6);
            subject.MaxConnectionIdleTime.Should().Be(serverSettings.MaxConnectionIdleTime);
            subject.MaxConnectionLifeTime.Should().Be(serverSettings.MaxConnectionLifeTime);
            subject.MaxConnectionPoolSize.Should().Be(serverSettings.MaxConnectionPoolSize);
            subject.MinConnectionPoolSize.Should().Be(serverSettings.MinConnectionPoolSize);
            subject.ReplicaSetName.Should().Be(serverSettings.ReplicaSetName);
            subject.SecondaryAcceptableLatency.Should().Be(serverSettings.SecondaryAcceptableLatency);
            subject.Servers.Should().Equal(serverSettings.Servers);
            subject.SocketTimeout.Should().Be(serverSettings.SocketTimeout);
            subject.SslSettings.Should().Be(serverSettings.SslSettings);
            subject.UseSsl.Should().Be(serverSettings.UseSsl);
            subject.VerifySslCertificate.Should().Be(serverSettings.VerifySslCertificate);
            subject.WaitQueueSize.Should().Be(serverSettings.WaitQueueSize);
            subject.WaitQueueTimeout.Should().Be(serverSettings.WaitQueueTimeout);
        }
        public void Constructor_with_MongoClientSettings_parameter_should_copy_relevant_values()
        {
            var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
            var servers = new[] { new MongoServerAddress("localhost") };

            var certificates = new[] { new X509Certificate() };
            var sslSettings = new SslSettings
            {
                CheckCertificateRevocation = true,
                ClientCertificates = certificates,
                EnabledSslProtocols = SslProtocols.Tls12
            };

            var clientSettings = new MongoClientSettings
            {
                ConnectionMode = ConnectionMode.Direct,
                ConnectTimeout = TimeSpan.FromSeconds(1),
                Credentials = credentials,
                GuidRepresentation = GuidRepresentation.Standard,
                IPv6 = true,
                MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
                MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
                MaxConnectionPoolSize = 10,
                MinConnectionPoolSize = 5,
                ReplicaSetName = "rs",
                Servers = servers,
                SocketTimeout = TimeSpan.FromSeconds(4),
                SslSettings = sslSettings,
                UseSsl = true,
                VerifySslCertificate = true,
                WaitQueueSize = 20,
                WaitQueueTimeout = TimeSpan.FromSeconds(5)
            };

            var subject = new ClusterKey(clientSettings);

            subject.ConnectionMode.Should().Be(clientSettings.ConnectionMode);
            subject.ConnectTimeout.Should().Be(clientSettings.ConnectTimeout);
            subject.Credentials.Should().Equal(clientSettings.Credentials);
            subject.IPv6.Should().Be(clientSettings.IPv6);
            subject.MaxConnectionIdleTime.Should().Be(clientSettings.MaxConnectionIdleTime);
            subject.MaxConnectionLifeTime.Should().Be(clientSettings.MaxConnectionLifeTime);
            subject.MaxConnectionPoolSize.Should().Be(clientSettings.MaxConnectionPoolSize);
            subject.MinConnectionPoolSize.Should().Be(clientSettings.MinConnectionPoolSize);
            subject.ReplicaSetName.Should().Be(clientSettings.ReplicaSetName);
            subject.Servers.Should().Equal(clientSettings.Servers);
            subject.SocketTimeout.Should().Be(clientSettings.SocketTimeout);
            subject.SslSettings.Should().Be(clientSettings.SslSettings);
            subject.UseSsl.Should().Be(clientSettings.UseSsl);
            subject.VerifySslCertificate.Should().Be(clientSettings.VerifySslCertificate);
            subject.WaitQueueSize.Should().Be(clientSettings.WaitQueueSize);
            subject.WaitQueueTimeout.Should().Be(clientSettings.WaitQueueTimeout);
        }
示例#4
0
 public PSClusterKey(ClusterKey clusterKey)
 {
     Name    = clusterKey.Name;
     OrderBy = clusterKey.OrderBy;
 }
示例#5
0
        public void GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings()
        {
            var clusterConfigurator = new Action <ClusterBuilder>(b => { });

#pragma warning disable 618
            var credentials = new List <MongoCredential> {
                MongoCredential.CreateMongoCRCredential("source", "username", "password")
            };
#pragma warning restore 618
            var servers     = new[] { new MongoServerAddress("localhost"), new MongoServerAddress("127.0.0.1", 30000), new MongoServerAddress("[::1]", 27018) };
            var sslSettings = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols        = SslProtocols.Tls
            };
            var kmsProviders = new Dictionary <string, IReadOnlyDictionary <string, object> >()
            {
                { "local", new Dictionary <string, object>()
                  {
                      { "key", "test" }
                  } }
            };
            var schemaMap = new Dictionary <string, BsonDocument>()
            {
                { "db.coll", new BsonDocument() }
            };

            var clusterKey = new ClusterKey(
                allowInsecureTls: false,
                applicationName: "app1",
                clusterConfigurator: clusterConfigurator,
                compressors: new[] { new CompressorConfiguration(CompressorType.Zlib) },
                connectionMode: ConnectionMode.ReplicaSet,
                connectTimeout: TimeSpan.FromSeconds(1),
                credentials: credentials,
                heartbeatInterval: TimeSpan.FromSeconds(2),
                heartbeatTimeout: TimeSpan.FromSeconds(3),
                ipv6: true,
                kmsProviders: kmsProviders,
                localThreshold: TimeSpan.FromSeconds(4),
                maxConnectionIdleTime: TimeSpan.FromSeconds(5),
                maxConnectionLifeTime: TimeSpan.FromSeconds(6),
                maxConnectionPoolSize: 7,
                minConnectionPoolSize: 8,
                receiveBufferSize: 9,
                replicaSetName: "rs",
                schemaMap: schemaMap,
                scheme: ConnectionStringScheme.MongoDB,
                sdamLogFilename: "sdam.log",
                sendBufferSize: 10,
                servers: servers,
                serverSelectionTimeout: TimeSpan.FromSeconds(11),
                socketTimeout: TimeSpan.FromSeconds(12),
                sslSettings: sslSettings,
                useTls: true,
                waitQueueSize: 13,
                waitQueueTimeout: TimeSpan.FromSeconds(14));

            var subject = new ClusterRegistry();

            using (var cluster = subject.GetOrCreateCluster(clusterKey))
            {
                var expectedEndPoints = new EndPoint[]
                {
                    new DnsEndPoint("localhost", 27017),
                    new IPEndPoint(IPAddress.Parse("127.0.0.1"), 30000),
                    new IPEndPoint(IPAddress.Parse("[::1]"), 27018)
                };
                cluster.Settings.ConnectionMode.Should().Be(clusterKey.ConnectionMode.ToCore());
                cluster.Settings.KmsProviders.Should().BeEquivalentTo(kmsProviders);
                cluster.Settings.EndPoints.Should().Equal(expectedEndPoints);
                cluster.Settings.MaxServerSelectionWaitQueueSize.Should().Be(clusterKey.WaitQueueSize);
                cluster.Settings.ReplicaSetName.Should().Be(clusterKey.ReplicaSetName);
                cluster.Settings.SchemaMap.Should().BeEquivalentTo(schemaMap);
                cluster.Settings.Scheme.Should().Be(clusterKey.Scheme);
                cluster.Settings.ServerSelectionTimeout.Should().Be(clusterKey.ServerSelectionTimeout);

                cluster.Description.Servers.Select(s => s.EndPoint).Should().BeEquivalentTo(expectedEndPoints);

                // TODO: don't know how to test the rest of the settings because they are all private to the cluster
            }
        }