Beispiel #1
0
        public void Encoder_should_read_the_previously_written_message(
            CompressorType compressorType,
            object compressionOption)
        {
            var message = CreateMessage(1, 2);

            var compressedMessage = GetCompressedMessage(message, compressorType);

            using (compressedMessage.OriginalMessageStream)
            {
                CompressorConfiguration compressionProperty = new CompressorConfiguration(compressorType);
                if (compressionOption != null)
                {
                    compressionProperty.Properties.Add("Level", compressionOption);
                }

                using (var memoryStream = new MemoryStream())
                {
                    var subject = CreateSubject(memoryStream, compressionProperty);

                    subject.WriteMessage(compressedMessage);
                    memoryStream.Position = 0;
                    var result = subject.ReadMessage();

                    result.ShouldBeEquivalentTo(
                        compressedMessage,
                        options =>
                        options
                        .Excluding(p => p.OriginalMessageStream));
                }
            }
        }
Beispiel #2
0
        public void Encoder_should_read_the_previously_written_message_or_throw_the_exception_if_the_current_platform_is_not_supported(
            CompressorType compressorType)
        {
            var message = CreateMessage(1, 2);

            var compressedMessage = GetCompressedMessage(message, compressorType);

            using (compressedMessage.OriginalMessageStream)
            {
                CompressorConfiguration compressionProperty = new CompressorConfiguration(compressorType);

                using (var memoryStream = new MemoryStream())
                {
                    var subject = CreateSubject(memoryStream, compressionProperty);
#if NET452 || NETSTANDARD2_0
                    subject.WriteMessage(compressedMessage);
                    memoryStream.Position = 0;
                    var result = subject.ReadMessage();

                    result.ShouldBeEquivalentTo(
                        compressedMessage,
                        options =>
                        options
                        .Excluding(p => p.OriginalMessageStream));
#else
                    var exception = Record.Exception(() => { subject.WriteMessage(compressedMessage); });

                    exception.Should().BeOfType <NotSupportedException>();
#endif
                }
            }
        }
        private ICompressor CreateCompressor(CompressorConfiguration compressorConfiguration)
        {
            switch (compressorConfiguration.Type)
            {
            case CompressorType.Noop:
                return(new NoopCompressor());

            case CompressorType.Snappy:
                return(new SnappyCompressor());

            case CompressorType.Zlib:
            {
                int?zlibCompressionLevel = null;
                if (compressorConfiguration.Properties.ContainsKey("Level"))
                {
                    zlibCompressionLevel = (int)compressorConfiguration.Properties["Level"];
                }

                return(new ZlibCompressor(zlibCompressionLevel));
            }

            case CompressorType.ZStandard:
                return(new ZstandardCompressor());
            }

            throw new NotSupportedException($"The compressor {compressorConfiguration.Type} is not supported.");
        }
        public void Equals_should_return_false_if_obj_is_null()
        {
            var subject = new CompressorConfiguration(CompressorType.Noop);

            var result = subject.Equals(null);

            result.Should().BeFalse();
        }
        public void constructor_should_initialize_instance(CompressorType type)
        {
            var subject = new CompressorConfiguration(type);

            subject.Type.Should().Be(type);
            subject.Properties.Should().NotBeNull();
            subject.Properties.Count.Should().Be(0);
        }
        public void Equals_should_return_false_if_obj_is_wrong_type()
        {
            var subject = new CompressorConfiguration(CompressorType.Noop);
            var obj     = new object();

            var result    = subject.Equals(new object());
            var hashCode1 = subject.GetHashCode();
            var hashCode2 = obj.GetHashCode();

            result.Should().BeFalse();
            hashCode2.Should().NotBe(hashCode1);
        }
Beispiel #7
0
 private static void ParseAndAppendCompressorOptions(StringBuilder builder, CompressorConfiguration compressorConfiguration)
 {
     switch (compressorConfiguration.Type)
     {
     case CompressorType.Zlib:
     {
         if (compressorConfiguration.Properties.TryGetValue("Level", out var zlibCompressionLevel))
         {
             builder.AppendFormat("zlibCompressionLevel={0};", zlibCompressionLevel);
         }
     }
     break;
     }
 }
        public void Equals_should_return_true_if_all_fields_are_equal(CompressorType type)
        {
            var subject1 = new CompressorConfiguration(type);
            var subject2 = new CompressorConfiguration(type);

            subject1.Properties.Add("x", 1);
            subject2.Properties.Add("x", 1);

            var result    = subject1.Equals(subject2);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            result.Should().BeTrue();
            hashCode2.Should().Be(hashCode1);
        }
        public void Equals_should_return_false_if_any_field_is_not_equal(string fieldName)
        {
            var type     = CompressorType.Snappy;
            var key      = "x";
            var subject1 = new CompressorConfiguration(type);

            subject1.Properties.Add(key, 1);
            switch (fieldName)
            {
            case "Properties": key = "y"; break;

            case "Type": type = CompressorType.Zlib; break;
            }
            var subject2 = new CompressorConfiguration(type);

            subject2.Properties.Add(key, 1);

            var result    = subject1.Equals(subject2);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            result.Should().BeFalse();
            hashCode2.Should().NotBe(hashCode1);
        }
        internal ClusterKey CreateSubjectWith(
            Dictionary <string, IReadOnlyDictionary <string, object> > kmsProvidersValue = null,
            Dictionary <string, BsonDocument> schemaMapValue = null,
#pragma warning disable CS0618 // Type or member is obsolete
            ConnectionModeSwitch connectionModeSwitch = ConnectionModeSwitch.UseConnectionMode)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            var allowInsecureTls    = true;
            var applicationName     = "app1";
            var clusterConfigurator = new Action <ClusterBuilder>(b => { });
            var compressors         = new CompressorConfiguration[0];

#pragma warning disable CS0618 // Type or member is obsolete
            var connectionMode = connectionModeSwitch != ConnectionModeSwitch.UseConnectionMode ? ConnectionMode.Automatic : ConnectionMode.Direct;
#pragma warning restore CS0618 // Type or member is obsolete
            var connectTimeout = TimeSpan.FromSeconds(1);
#pragma warning disable 618
            var credentials = new List <MongoCredential> {
                MongoCredential.CreateMongoCRCredential("source", "username", "password")
            };
#pragma warning restore 618
            bool?directConnection  = null;
            var  heartbeatInterval = TimeSpan.FromSeconds(7);
            var  heartbeatTimeout  = TimeSpan.FromSeconds(8);
            var  ipv6                   = false;
            var  kmsProviders           = kmsProvidersValue ?? new Dictionary <string, IReadOnlyDictionary <string, object> >();
            var  localThreshold         = TimeSpan.FromMilliseconds(20);
            var  maxConnectionIdleTime  = TimeSpan.FromSeconds(2);
            var  maxConnectionLifeTime  = TimeSpan.FromSeconds(3);
            var  maxConnectionPoolSize  = 50;
            var  minConnectionPoolSize  = 5;
            var  receiveBufferSize      = 1;
            var  replicaSetName         = "abc";
            var  schemaMap              = schemaMapValue ?? new Dictionary <string, BsonDocument>();
            var  scheme                 = ConnectionStringScheme.MongoDB;
            var  sdamLogFileName        = "stdout";
            var  sendBufferSize         = 1;
            var  servers                = new[] { new MongoServerAddress("localhost") };
            var  serverSelectionTimeout = TimeSpan.FromSeconds(6);
            var  socketTimeout          = TimeSpan.FromSeconds(4);
            var  sslSettings            = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols        = SslProtocols.Tls
            };
            var useTls           = false;
            var waitQueueSize    = 20;
            var waitQueueTimeout = TimeSpan.FromSeconds(5);

            return(new ClusterKey(
                       allowInsecureTls,
                       applicationName,
                       clusterConfigurator,
                       compressors,
                       connectionMode,
                       connectionModeSwitch,
                       connectTimeout,
                       credentials,
                       directConnection,
                       heartbeatInterval,
                       heartbeatTimeout,
                       ipv6,
                       kmsProviders,
                       localThreshold,
                       maxConnectionIdleTime,
                       maxConnectionLifeTime,
                       maxConnectionPoolSize,
                       minConnectionPoolSize,
                       receiveBufferSize,
                       replicaSetName,
                       schemaMap,
                       scheme,
                       sdamLogFileName,
                       sendBufferSize,
                       servers,
                       serverSelectionTimeout,
                       socketTimeout,
                       sslSettings,
                       useTls,
                       waitQueueSize,
                       waitQueueTimeout));
        }
        // private methods
        private ClusterKey CreateSubject(string notEqualFieldName = null)
        {
            var allowInsecureTls    = true;
            var applicationName     = "app1";
            var clusterConfigurator = new Action <ClusterBuilder>(b => { });

#pragma warning disable CS0618 // Type or member is obsolete
            var connectionModeSwitch = ConnectionModeSwitch.UseConnectionMode;
#pragma warning restore CS0618 // Type or member is obsolete
            var compressors = new CompressorConfiguration[0];
#pragma warning disable CS0618 // Type or member is obsolete
            var connectionMode = ConnectionMode.Direct;
#pragma warning restore CS0618 // Type or member is obsolete
            var connectTimeout = TimeSpan.FromSeconds(1);
#pragma warning disable 618
            var credentials = new List <MongoCredential> {
                MongoCredential.CreateMongoCRCredential("source", "username", "password")
            };
#pragma warning restore 618
            bool?directConnection  = null;
            var  heartbeatInterval = TimeSpan.FromSeconds(7);
            var  heartbeatTimeout  = TimeSpan.FromSeconds(8);
            var  ipv6                   = false;
            var  kmsProviders           = new Dictionary <string, IReadOnlyDictionary <string, object> >();
            var  localThreshold         = TimeSpan.FromMilliseconds(20);
            var  maxConnectionIdleTime  = TimeSpan.FromSeconds(2);
            var  maxConnectionLifeTime  = TimeSpan.FromSeconds(3);
            var  maxConnectionPoolSize  = 50;
            var  minConnectionPoolSize  = 5;
            var  receiveBufferSize      = 1;
            var  replicaSetName         = "abc";
            var  schemaMap              = new Dictionary <string, BsonDocument>();
            var  scheme                 = ConnectionStringScheme.MongoDB;
            var  sdamLogFileName        = "stdout";
            var  sendBufferSize         = 1;
            var  servers                = new[] { new MongoServerAddress("localhost") };
            var  serverSelectionTimeout = TimeSpan.FromSeconds(6);
            var  socketTimeout          = TimeSpan.FromSeconds(4);
            var  sslSettings            = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols        = SslProtocols.Tls
            };
            var useTls           = false;
            var waitQueueSize    = 20;
            var waitQueueTimeout = TimeSpan.FromSeconds(5);

            if (notEqualFieldName != null)
            {
                switch (notEqualFieldName)
                {
                case "AllowInsecureTls": allowInsecureTls = !allowInsecureTls; break;

                case "ApplicationName": applicationName = "app2"; break;

                case "ClusterConfigurator": clusterConfigurator = new Action <ClusterBuilder>(b => { }); break;

                case "Compressors": compressors = new[] { new CompressorConfiguration(CompressorType.Zlib) }; break;

#pragma warning disable CS0618 // Type or member is obsolete
                case "ConnectionMode":
                {
                    connectionMode       = ConnectionMode.ReplicaSet;
                    connectionModeSwitch = ConnectionModeSwitch.UseConnectionMode;
                    directConnection     = null;     // reset
                } break;

#pragma warning restore CS0618 // Type or member is obsolete
                case "ConnectTimeout": connectTimeout = TimeSpan.FromSeconds(99); break;

#pragma warning disable CS0618 // Type or member is obsolete
                case "Credentials": credentials = new List <MongoCredential> {
                        MongoCredential.CreateMongoCRCredential("different", "different", "different")
                }; break;

                case "DirectConnection":
                {
                    directConnection     = true;
                    connectionModeSwitch = ConnectionModeSwitch.UseDirectConnection;
                    connectionMode       = ConnectionMode.Automatic; // reset
#pragma warning restore CS0618                                       // Type or member is obsolete
                }
                break;

                case "HeartbeatInterval": heartbeatInterval = TimeSpan.FromSeconds(99); break;

                case "HeartbeatTimeout": heartbeatTimeout = TimeSpan.FromSeconds(99); break;

                case "IPv6": ipv6 = !ipv6; break;

                case "KmsProviders": kmsProviders.Add("local", new Dictionary <string, object>()
                    {
                        { "key", "test" }
                    }); break;

                case "LocalThreshold": localThreshold = TimeSpan.FromMilliseconds(99); break;

                case "MaxConnectionIdleTime": maxConnectionIdleTime = TimeSpan.FromSeconds(99); break;

                case "MaxConnectionLifeTime": maxConnectionLifeTime = TimeSpan.FromSeconds(99); break;

                case "MaxConnectionPoolSize": maxConnectionPoolSize = 99; break;

                case "MinConnectionPoolSize": minConnectionPoolSize = 99; break;

                case "ReceiveBufferSize": receiveBufferSize = 2; break;

                case "ReplicaSetName": replicaSetName = "different"; break;

                case "SchemaMap": schemaMap.Add("db.coll", new BsonDocument()); break;

                case "Scheme": scheme = ConnectionStringScheme.MongoDBPlusSrv; break;

                case "SdamLogFileName": sdamLogFileName = "different"; break;

                case "SendBufferSize": sendBufferSize = 2; break;

                case "Servers": servers = new[] { new MongoServerAddress("different") }; break;

                case "ServerSelectionTimeout": serverSelectionTimeout = TimeSpan.FromSeconds(98); break;

                case "SocketTimeout": socketTimeout = TimeSpan.FromSeconds(99); break;

                case "SslSettings": sslSettings.CheckCertificateRevocation = !sslSettings.CheckCertificateRevocation; break;

                case "UseTls": useTls = !useTls; break;

                case "WaitQueueSize": waitQueueSize = 99; break;

                case "WaitQueueTimeout": waitQueueTimeout = TimeSpan.FromSeconds(99); break;

                default: throw new ArgumentException($"Invalid field name: \"{notEqualFieldName}\".", nameof(notEqualFieldName));
                }
            }

            return(new ClusterKey(
                       allowInsecureTls,
                       applicationName,
                       clusterConfigurator,
                       compressors,
                       connectionMode,
                       connectionModeSwitch,
                       connectTimeout,
                       credentials,
                       directConnection,
                       heartbeatInterval,
                       heartbeatTimeout,
                       ipv6,
                       kmsProviders,
                       localThreshold,
                       maxConnectionIdleTime,
                       maxConnectionLifeTime,
                       maxConnectionPoolSize,
                       minConnectionPoolSize,
                       receiveBufferSize,
                       replicaSetName,
                       schemaMap,
                       scheme,
                       sdamLogFileName,
                       sendBufferSize,
                       servers,
                       serverSelectionTimeout,
                       socketTimeout,
                       sslSettings,
                       useTls,
                       waitQueueSize,
                       waitQueueTimeout));
        }
Beispiel #12
0
        public void TestAll()
        {
            var readPreference          = new ReadPreference(ReadPreferenceMode.Secondary, new[] { new TagSet(new[] { new Tag("dc", "1") }) }, TimeSpan.FromSeconds(11));
            var authMechanismProperties = new Dictionary <string, string>
            {
                { "SERVICE_NAME", "other" },
                { "CANONICALIZE_HOST_NAME", "true" }
            };

            var zlibCompressor = new CompressorConfiguration(CompressorType.Zlib);

            zlibCompressor.Properties.Add("Level", 4);

            var built = new MongoUrlBuilder()
            {
                AllowInsecureTls                  = true,
                ApplicationName                   = "app",
                AuthenticationMechanism           = "GSSAPI",
                AuthenticationMechanismProperties = authMechanismProperties,
                AuthenticationSource              = "db",
                Compressors       = new[] { zlibCompressor },
                ConnectionMode    = ConnectionMode.ReplicaSet,
                ConnectTimeout    = TimeSpan.FromSeconds(1),
                DatabaseName      = "database",
                FSync             = true,
                HeartbeatInterval = TimeSpan.FromSeconds(11),
                HeartbeatTimeout  = TimeSpan.FromSeconds(12),
                IPv6    = true,
                Journal = true,
                MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
                MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
                MaxConnectionPoolSize = 4,
                MinConnectionPoolSize = 5,
                Password               = "******",
                ReadConcernLevel       = ReadConcernLevel.Majority,
                ReadPreference         = readPreference,
                ReplicaSetName         = "name",
                RetryReads             = false,
                RetryWrites            = true,
                LocalThreshold         = TimeSpan.FromSeconds(6),
                Server                 = new MongoServerAddress("host"),
                ServerSelectionTimeout = TimeSpan.FromSeconds(10),
                SocketTimeout          = TimeSpan.FromSeconds(7),
                Username               = "******",
                UseTls                 = true,
                W = 2,
#pragma warning disable 618
                WaitQueueSize = 123,
#pragma warning restore 618
                WaitQueueTimeout = TimeSpan.FromSeconds(8),
                WTimeout         = TimeSpan.FromSeconds(9)
            };

#pragma warning disable 618
            if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
            {
                built.GuidRepresentation = GuidRepresentation.PythonLegacy;
            }
#pragma warning restore 618

            var connectionString = "mongodb://*****:*****@host/database?" + string.Join(";", new[] {
                "authMechanism=GSSAPI",
                "authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true",
                "authSource=db",
                "appname=app",
                "ipv6=true",
                "tls=true", // UseTls
                "tlsInsecure=true",
                "compressors=zlib",
                "zlibCompressionLevel=4",
                "connect=replicaSet",
                "replicaSet=name",
                "readConcernLevel=majority",
                "readPreference=secondary;readPreferenceTags=dc:1;maxStaleness=11s",
                "fsync=true",
                "journal=true",
                "w=2",
                "wtimeout=9s",
                "connectTimeout=1s",
                "heartbeatInterval=11s",
                "heartbeatTimeout=12s",
                "maxIdleTime=2s",
                "maxLifeTime=3s",
                "maxPoolSize=4",
                "minPoolSize=5",
                "localThreshold=6s",
                "serverSelectionTimeout=10s",
                "socketTimeout=7s",
                "waitQueueSize=123",
                "waitQueueTimeout=8s",
                "retryReads=false",
                "retryWrites=true"
            });
#pragma warning disable 618
            if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
            {
                var index = connectionString.IndexOf("retryReads=false;");
                connectionString = connectionString.Insert(index, "uuidRepresentation=pythonLegacy;");
            }
#pragma warning restore 618

            foreach (var url in EnumerateBuiltAndParsedUrls(built, connectionString))
            {
                Assert.Equal(true, url.AllowInsecureTls);
                Assert.Equal("app", url.ApplicationName);
                Assert.Equal("GSSAPI", url.AuthenticationMechanism);
                Assert.Equal(authMechanismProperties, url.AuthenticationMechanismProperties);
                Assert.Equal("db", url.AuthenticationSource);
                Assert.Contains(url.Compressors, x => x.Type == CompressorType.Zlib);
#pragma warning disable 618
                Assert.Equal(123, url.ComputedWaitQueueSize);
#pragma warning restore 618
                Assert.Equal(ConnectionMode.ReplicaSet, url.ConnectionMode);
                Assert.Equal(TimeSpan.FromSeconds(1), url.ConnectTimeout);
                Assert.Equal("database", url.DatabaseName);
                Assert.Equal(true, url.FSync);
#pragma warning disable 618
                if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
                {
                    Assert.Equal(GuidRepresentation.PythonLegacy, url.GuidRepresentation);
                }
#pragma warning restore 618
                Assert.Equal(TimeSpan.FromSeconds(11), url.HeartbeatInterval);
                Assert.Equal(TimeSpan.FromSeconds(12), url.HeartbeatTimeout);
                Assert.Equal(true, url.IPv6);
                Assert.Equal(true, url.IsResolved);
                Assert.Equal(true, url.Journal);
                Assert.Equal(TimeSpan.FromSeconds(2), url.MaxConnectionIdleTime);
                Assert.Equal(TimeSpan.FromSeconds(3), url.MaxConnectionLifeTime);
                Assert.Equal(4, url.MaxConnectionPoolSize);
                Assert.Equal(5, url.MinConnectionPoolSize);
                Assert.Equal("password", url.Password);
                Assert.Equal(ReadConcernLevel.Majority, url.ReadConcernLevel);
                Assert.Equal(readPreference, url.ReadPreference);
                Assert.Equal("name", url.ReplicaSetName);
                Assert.Equal(false, url.RetryReads);
                Assert.Equal(true, url.RetryWrites);
                Assert.Equal(TimeSpan.FromSeconds(6), url.LocalThreshold);
                Assert.Equal(ConnectionStringScheme.MongoDB, url.Scheme);
                Assert.Equal(new MongoServerAddress("host", 27017), url.Server);
                Assert.Equal(TimeSpan.FromSeconds(10), url.ServerSelectionTimeout);
                Assert.Equal(TimeSpan.FromSeconds(7), url.SocketTimeout);
                url.TlsDisableCertificateRevocationCheck.Should().Be(false);
                Assert.Equal("username", url.Username);
#pragma warning disable 618
                Assert.Equal(true, url.UseSsl);
#pragma warning restore 618
                Assert.Equal(true, url.UseTls);
#pragma warning disable 618
                Assert.Equal(false, url.VerifySslCertificate);
#pragma warning restore 618
                Assert.Equal(2, ((WriteConcern.WCount)url.W).Value);
#pragma warning disable 618
                Assert.Equal(0.0, url.WaitQueueMultiple);
                Assert.Equal(123, url.WaitQueueSize);
#pragma warning restore 618
                Assert.Equal(TimeSpan.FromSeconds(8), url.WaitQueueTimeout);
                Assert.Equal(TimeSpan.FromSeconds(9), url.WTimeout);
                var expectedConnectionString = connectionString;
#pragma warning disable 618
                if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
                {
                    var defaultGuidRepresentation = BsonDefaults.GuidRepresentation;
                    if (url.GuidRepresentation == defaultGuidRepresentation)
                    {
                        expectedConnectionString = expectedConnectionString.Replace("uuidRepresentation=pythonLegacy;", "");
                    }
                }
#pragma warning restore 618
                Assert.Equal(expectedConnectionString, url.ToString());
            }
        }
Beispiel #13
0
        private ClusterKey CreateSubject(string notEqualFieldName = null)
        {
            var applicationName     = "app1";
            var clusterConfigurator = new Action <ClusterBuilder>(b => { });
            var compressors         = new CompressorConfiguration[0];
            var connectionMode      = ConnectionMode.Direct;
            var connectTimeout      = TimeSpan.FromSeconds(1);

#pragma warning disable 618
            var credentials = new List <MongoCredential> {
                MongoCredential.CreateMongoCRCredential("source", "username", "password")
            };
#pragma warning restore 618
            var heartbeatInterval = TimeSpan.FromSeconds(7);
            var heartbeatTimeout  = TimeSpan.FromSeconds(8);
            var ipv6                   = false;
            var localThreshold         = TimeSpan.FromMilliseconds(20);
            var maxConnectionIdleTime  = TimeSpan.FromSeconds(2);
            var maxConnectionLifeTime  = TimeSpan.FromSeconds(3);
            var maxConnectionPoolSize  = 50;
            var minConnectionPoolSize  = 5;
            var receiveBufferSize      = 1;
            var replicaSetName         = "abc";
            var scheme                 = ConnectionStringScheme.MongoDB;
            var sdamLogFileName        = "stdout";
            var sendBufferSize         = 1;
            var servers                = new[] { new MongoServerAddress("localhost") };
            var serverSelectionTimeout = TimeSpan.FromSeconds(6);
            var socketTimeout          = TimeSpan.FromSeconds(4);
            var sslSettings            = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols        = SslProtocols.Tls
            };
            var useSsl = false;
            var verifySslCertificate = false;
            var waitQueueSize        = 20;
            var waitQueueTimeout     = TimeSpan.FromSeconds(5);

            if (notEqualFieldName != null)
            {
                switch (notEqualFieldName)
                {
                case "ApplicationName": applicationName = "app2"; break;

                case "ClusterConfigurator": clusterConfigurator = new Action <ClusterBuilder>(b => { }); break;

                case "Compressors": compressors = new[] { new CompressorConfiguration(CompressorType.Zlib) }; break;

                case "ConnectionMode": connectionMode = ConnectionMode.ReplicaSet; break;

                case "ConnectTimeout": connectTimeout = TimeSpan.FromSeconds(99); break;

#pragma warning disable 618
                case "Credentials": credentials = new List <MongoCredential> {
                        MongoCredential.CreateMongoCRCredential("different", "different", "different")
                }; break;

#pragma warning restore 618
                case "HeartbeatInterval": heartbeatInterval = TimeSpan.FromSeconds(99); break;

                case "HeartbeatTimeout": heartbeatTimeout = TimeSpan.FromSeconds(99); break;

                case "IPv6": ipv6 = !ipv6; break;

                case "LocalThreshold": localThreshold = TimeSpan.FromMilliseconds(99); break;

                case "MaxConnectionIdleTime": maxConnectionIdleTime = TimeSpan.FromSeconds(99); break;

                case "MaxConnectionLifeTime": maxConnectionLifeTime = TimeSpan.FromSeconds(99); break;

                case "MaxConnectionPoolSize": maxConnectionPoolSize = 99; break;

                case "MinConnectionPoolSize": minConnectionPoolSize = 99; break;

                case "ReceiveBufferSize": receiveBufferSize = 2; break;

                case "ReplicaSetName": replicaSetName = "different"; break;

                case "Scheme": scheme = ConnectionStringScheme.MongoDBPlusSrv; break;

                case "SdamLogFileName": sdamLogFileName = "different"; break;

                case "SendBufferSize": sendBufferSize = 2; break;

                case "Servers": servers = new[] { new MongoServerAddress("different") }; break;

                case "ServerSelectionTimeout": serverSelectionTimeout = TimeSpan.FromSeconds(98); break;

                case "SocketTimeout": socketTimeout = TimeSpan.FromSeconds(99); break;

                case "SslSettings": sslSettings.CheckCertificateRevocation = !sslSettings.CheckCertificateRevocation; break;

                case "UseSsl": useSsl = !useSsl; break;

                case "VerifySslCertificate": verifySslCertificate = !verifySslCertificate; break;

                case "WaitQueueSize": waitQueueSize = 99; break;

                case "WaitQueueTimeout": waitQueueTimeout = TimeSpan.FromSeconds(99); break;

                default: throw new ArgumentException($"Invalid field name: \"{notEqualFieldName}\".", nameof(notEqualFieldName));
                }
            }

            return(new ClusterKey(
                       applicationName,
                       clusterConfigurator,
                       compressors,
                       connectionMode,
                       connectTimeout,
                       credentials,
                       heartbeatInterval,
                       heartbeatTimeout,
                       ipv6,
                       localThreshold,
                       maxConnectionIdleTime,
                       maxConnectionLifeTime,
                       maxConnectionPoolSize,
                       minConnectionPoolSize,
                       receiveBufferSize,
                       replicaSetName,
                       scheme,
                       sdamLogFileName,
                       sendBufferSize,
                       servers,
                       serverSelectionTimeout,
                       socketTimeout,
                       sslSettings,
                       useSsl,
                       verifySslCertificate,
                       waitQueueSize,
                       waitQueueTimeout));
        }