本文整理汇总了C#中MongoDB.Driver.MongoClientSettings.ToClusterKey方法的典型用法代码示例。如果您正苦于以下问题:C# MongoClientSettings.ToClusterKey方法的具体用法?C# MongoClientSettings.ToClusterKey怎么用?C# MongoClientSettings.ToClusterKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoClientSettings
的用法示例。
在下文中一共展示了MongoClientSettings.ToClusterKey方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings
public void GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings()
{
var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
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 clientSettings = new MongoClientSettings
{
ApplicationName = "app1",
ConnectionMode = ConnectionMode.ReplicaSet,
ConnectTimeout = TimeSpan.FromSeconds(1),
Credentials = credentials,
GuidRepresentation = GuidRepresentation.Standard,
HeartbeatInterval = TimeSpan.FromSeconds(7),
HeartbeatTimeout = TimeSpan.FromSeconds(8),
IPv6 = true,
MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
MaxConnectionPoolSize = 10,
MinConnectionPoolSize = 5,
ReplicaSetName = "rs",
LocalThreshold = TimeSpan.FromMilliseconds(20),
Servers = servers,
ServerSelectionTimeout = TimeSpan.FromSeconds(5),
SocketTimeout = TimeSpan.FromSeconds(4),
SslSettings = sslSettings,
UseSsl = true,
VerifySslCertificate = true,
WaitQueueSize = 20,
WaitQueueTimeout = TimeSpan.FromSeconds(6)
};
var subject = new ClusterRegistry();
using (var cluster = subject.GetOrCreateCluster(clientSettings.ToClusterKey()))
{
var endPoints = 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(ClusterConnectionMode.ReplicaSet);
cluster.Settings.EndPoints.Equals(endPoints);
cluster.Settings.ReplicaSetName.Should().Be("rs");
cluster.Settings.ServerSelectionTimeout.Should().Be(clientSettings.ServerSelectionTimeout);
cluster.Settings.PostServerSelector.Should().NotBeNull().And.Subject.Should().BeOfType<LatencyLimitingServerSelector>();
cluster.Settings.MaxServerSelectionWaitQueueSize.Should().Be(20);
cluster.Description.Servers.Select(s => s.EndPoint).Should().Contain(endPoints);
// TODO: don't know how to test the rest of the settings because they are all private to the cluster
}
}
示例2: CreateSubject
private ClusterKey CreateSubject(string notEqualFieldName = null)
{
var connectionMode = ConnectionMode.Direct;
var connectTimeout = TimeSpan.FromSeconds(1);
var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
var guidRepresentation = GuidRepresentation.Standard;
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 replicaSetName = "abc";
var servers = new[] { new MongoServerAddress("localhost") };
var serverSelectionTimeout = TimeSpan.FromSeconds(6);
var socketTimeout = TimeSpan.FromSeconds(4);
var sslSettings = new SslSettings
{
CheckCertificateRevocation = true,
EnabledSslProtocols = SslProtocols.Ssl3
};
var useSsl = false;
var verifySslCertificate = false;
var waitQueueSize = 20;
var waitQueueTimeout = TimeSpan.FromSeconds(5);
switch (notEqualFieldName)
{
case "ConnectionMode": connectionMode = ConnectionMode.ReplicaSet; break;
case "ConnectTimeout": connectTimeout = TimeSpan.FromSeconds(99); break;
case "Credentials": credentials = new[] { MongoCredential.CreateMongoCRCredential("different", "different", "different") }; 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 "ReplicaSetName": replicaSetName = "different"; 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;
}
var clientSettings = new MongoClientSettings
{
ConnectionMode = connectionMode,
ConnectTimeout = connectTimeout,
Credentials = credentials,
GuidRepresentation = guidRepresentation,
IPv6 = ipv6,
MaxConnectionIdleTime = maxConnectionIdleTime,
MaxConnectionLifeTime = maxConnectionLifeTime,
MaxConnectionPoolSize = maxConnectionPoolSize,
MinConnectionPoolSize = minConnectionPoolSize,
ReplicaSetName = replicaSetName,
LocalThreshold = localThreshold,
Servers = servers,
ServerSelectionTimeout = serverSelectionTimeout,
SocketTimeout = socketTimeout,
SslSettings = sslSettings,
UseSsl = useSsl,
VerifySslCertificate = verifySslCertificate,
WaitQueueSize = waitQueueSize,
WaitQueueTimeout = waitQueueTimeout
};
return clientSettings.ToClusterKey();
}
示例3: MongoClient
/// <summary>
/// Initializes a new instance of the MongoClient class.
/// </summary>
/// <param name="settings">The settings.</param>
public MongoClient(MongoClientSettings settings)
{
_settings = Ensure.IsNotNull(settings, nameof(settings)).FrozenCopy();
_cluster = ClusterRegistry.Instance.GetOrCreateCluster(_settings.ToClusterKey());
_operationExecutor = new OperationExecutor();
}
示例4: GetOrCreateCluster_should_return_a_different_cluster_if_client_settings_are_not_equal
public void GetOrCreateCluster_should_return_a_different_cluster_if_client_settings_are_not_equal()
{
var clientSettings1 = new MongoClientSettings();
var clientSettings2 = new MongoClientSettings() { IPv6 = true };
var subject = new ClusterRegistry();
using (var cluster1 = subject.GetOrCreateCluster(clientSettings1.ToClusterKey()))
using (var cluster2 = subject.GetOrCreateCluster(clientSettings2.ToClusterKey()))
{
cluster2.Should().NotBeSameAs(cluster1);
}
}
示例5: GetOrCreateCluster_should_return_the_same_cluster_if_client_settings_are_equal
public void GetOrCreateCluster_should_return_the_same_cluster_if_client_settings_are_equal()
{
var clientSettings1 = new MongoClientSettings();
var clientSettings2 = new MongoClientSettings();
var subject = new ClusterRegistry();
using (var cluster1 = subject.GetOrCreateCluster(clientSettings1.ToClusterKey()))
using (var cluster2 = subject.GetOrCreateCluster(clientSettings2.ToClusterKey()))
{
cluster2.Should().BeSameAs(cluster1);
}
}
示例6: MongoClient
/// <summary>
/// Initializes a new instance of the MongoClient class.
/// </summary>
/// <param name="settings">The settings.</param>
public MongoClient(MongoClientSettings settings)
{
_settings = settings.FrozenCopy();
_cluster = ClusterRegistry.Instance.GetOrCreateCluster(_settings.ToClusterKey());
_operationExecutor = new OperationExecutor();
}
示例7: UnregisterAndDisposeCluster_should_unregister_and_dispose_the_cluster
public void UnregisterAndDisposeCluster_should_unregister_and_dispose_the_cluster()
{
var subject = new ClusterRegistry();
var settings = new MongoClientSettings();
var clusterKey = settings.ToClusterKey();
var cluster = subject.GetOrCreateCluster(clusterKey);
subject.UnregisterAndDisposeCluster(cluster);
subject._registry().Count.Should().Be(0);
cluster._state().Should().Be(2);
}