public void Equals_should_return_expected_result( int port1, int localValue1, int serverValue1, int port2, int localValue2, int serverValue2, bool expectedEqualsResult, bool expectedStructurallyEqualsResult) { var clusterId = new ClusterId(); var serverId1 = new ServerId(clusterId, new DnsEndPoint("localhost", port1)); var serverId2 = new ServerId(clusterId, new DnsEndPoint("localhost", port2)); var subject1 = new ConnectionId(serverId1, localValue1).WithServerValue(serverValue1); var subject2 = new ConnectionId(serverId2, localValue2).WithServerValue(serverValue2); // note: Equals ignores the server values and StructurallyEquals compares all fields var equalsResult1 = subject1.Equals(subject2); var equalsResult2 = subject2.Equals(subject1); var structurallyEqualsResult1 = subject1.StructurallyEquals(subject2); var structurallyEqualsResult2 = subject2.StructurallyEquals(subject1); var hashCode1 = subject1.GetHashCode(); var hashCode2 = subject2.GetHashCode(); equalsResult1.Should().Be(expectedEqualsResult); equalsResult2.Should().Be(expectedEqualsResult); structurallyEqualsResult1.Should().Be(expectedStructurallyEqualsResult); structurallyEqualsResult2.Should().Be(expectedStructurallyEqualsResult); (hashCode1 == hashCode2).Should().Be(expectedEqualsResult); }
public void Equals_should_return_true_if_all_fiels_are_equal() { var subject1 = new ClusterId(1); var subject2 = new ClusterId(1); subject1.Equals(subject2).Should().BeTrue(); subject1.Equals((object)subject2).Should().BeTrue(); subject1.GetHashCode().Should().Be(subject2.GetHashCode()); }
public void Equals_should_return_false_if_any_field_is_not_equal() { var subject1 = new ClusterId(1); var subject2 = new ClusterId(2); subject1.Equals(subject2).Should().BeFalse(); subject1.Equals((object)subject2).Should().BeFalse(); subject1.GetHashCode().Should().NotBe(subject2.GetHashCode()); }
public ServerFactoryTests() { _clusterId = new ClusterId(); _clusterConnectionMode = ClusterConnectionMode.Standalone; _connectionPoolFactory = new Mock<IConnectionPoolFactory>().Object; _endPoint = new DnsEndPoint("localhost", 27017); _serverMonitorFactory = new Mock<IServerMonitorFactory>().Object; _eventSubscriber = new Mock<IEventSubscriber>().Object; _settings = new ServerSettings(); }
public void Setup() { _clusterId = new ClusterId(); _clusterConnectionMode = ClusterConnectionMode.Standalone; _connectionPoolFactory = Substitute.For<IConnectionPoolFactory>(); _endPoint = new DnsEndPoint("localhost", 27017); _heartbeatConnectionFactory = Substitute.For<IConnectionFactory>(); _eventSubscriber = Substitute.For<IEventSubscriber>(); _settings = new ServerSettings(); }
public void TestFixtureSetup() { var clusterId = new ClusterId(1); var clusterType = ClusterType.Standalone; var endPoint = new DnsEndPoint("localhost", 27017); var serverId = new ServerId(clusterId, endPoint); var server = new ServerDescription(serverId, endPoint); var servers = new[] { server }; _clusterDescription = new ClusterDescription(clusterId, clusterType, servers); }
public void OneTimeSetUp() { var clusterId = new ClusterId(1); var connectionMode = ClusterConnectionMode.Standalone; var clusterType = ClusterType.Standalone; var endPoint = new DnsEndPoint("localhost", 27017); var serverId = new ServerId(clusterId, endPoint); var server = new ServerDescription(serverId, endPoint); var servers = new[] { server }; _clusterDescription = new ClusterDescription(clusterId, connectionMode, clusterType, servers); }
// constructors protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener) { _settings = Ensure.IsNotNull(settings, "settings"); _serverFactory = Ensure.IsNotNull(serverFactory, "serverFactory"); _listener = listener; _state = new InterlockedInt32(State.Initial); _clusterId = new ClusterId(); _description = ClusterDescription.CreateInitial(_clusterId, _settings.ConnectionMode.ToClusterType()); _descriptionChangedTaskCompletionSource = new TaskCompletionSource<bool>(); }
// static constructor static ClusterDescriptionTests() { __clusterId = new ClusterId(); __endPoint1 = new DnsEndPoint("localhost", 27017); __endPoint2 = new DnsEndPoint("localhost", 27018); __serverId1 = new ServerId(__clusterId, __endPoint1); __serverId2 = new ServerId(__clusterId, __endPoint2); __serverDescription1 = new ServerDescription(__serverId1, __endPoint1); __serverDescription2 = new ServerDescription(__serverId2, __endPoint2); }
public static ServerDescription Connected(ClusterId clusterId, EndPoint endPoint = null, ServerType serverType = ServerType.Standalone, TagSet tags = null, TimeSpan? averageRoundTripTime = null, Range<int> wireVersionRange = null) { return Disconnected(clusterId, endPoint) .WithHeartbeatInfo( averageRoundTripTime ?? TimeSpan.FromMilliseconds(1), null, tags, serverType, new SemanticVersion(2, 6, 3), wireVersionRange ?? new Range<int>(0, 2)); }
public static ServerDescription Connected(ClusterId clusterId, EndPoint endPoint = null, ServerType serverType = ServerType.Standalone, TagSet tags = null, TimeSpan? averageRoundTripTime = null, Range<int> wireVersionRange = null) { return Disconnected(clusterId, endPoint).With( averageRoundTripTime: averageRoundTripTime ?? TimeSpan.FromMilliseconds(1), replicaSetConfig: null, state: ServerState.Connected, tags: tags, type: serverType, version: new SemanticVersion(2, 6, 3), wireVersionRange: wireVersionRange ?? new Range<int>(0, 2)); }
public MongoIncompatibleDriverExceptionTests() { var clusterId = new ClusterId(1); var connectionMode = ClusterConnectionMode.Standalone; var clusterType = ClusterType.Standalone; var endPoint = new DnsEndPoint("localhost", 27017); var serverId = new ServerId(clusterId, endPoint); var server = new ServerDescription(serverId, endPoint); var servers = new[] { server }; _clusterDescription = new ClusterDescription(clusterId, connectionMode, clusterType, servers); }
public void Setup() { var clusterId = new ClusterId(); _primary = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), ServerType.ReplicaSetPrimary, new TagSet(new [] { new Tag("a", "1") })); _secondary1 = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), ServerType.ReplicaSetSecondary, new TagSet(new [] { new Tag("a", "1") })); _secondary2 = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), ServerType.ReplicaSetSecondary, new TagSet(new[] { new Tag("a", "2") })); _description = new ClusterDescription( clusterId, ClusterType.ReplicaSet, new[] { _primary, _secondary1, _secondary2 }); }
public void Setup() { var clusterId = new ClusterId(); _description = new ClusterDescription( clusterId, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), averageRoundTripTime: TimeSpan.FromMilliseconds(10)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), averageRoundTripTime: TimeSpan.FromMilliseconds(30)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), averageRoundTripTime: TimeSpan.FromMilliseconds(20)) }); }
public void Setup() { var clusterId = new ClusterId(); _description = new ClusterDescription( clusterId, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019)), }); }
private ServerId CreateSubject(string notEqualField = null) { var clusterId = new ClusterId(1); var endPoint = new DnsEndPoint("localhost", 27017); switch (notEqualField) { case "ClusterId": clusterId = new ClusterId(2); break; case "EndPoint": endPoint = new DnsEndPoint("localhost", 27018); break; } return new ServerId(clusterId, endPoint); }
public EndPointServerSelectorTests() { var clusterId = new ClusterId(); _description = new ClusterDescription( clusterId, ClusterConnectionMode.Automatic, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019)), }); }
public void Setup() { var clusterId = new ClusterId(); _description = new ClusterDescription( clusterId, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019)), }); }
public void WithConnectionId_should_return_new_instance_even_when_only_the_serverValue_differs() { var clusterId = new ClusterId(); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 1)); var connectionId1 = new ConnectionId(serverId, 1); var connectionId2 = new ConnectionId(serverId, 1).WithServerValue(2); var helloResult = new HelloResult(new BsonDocument("maxWireVersion", WireVersion.Server36)); var subject = new ConnectionDescription(connectionId1, helloResult); var result = subject.WithConnectionId(connectionId2); result.Should().NotBeSameAs(subject); result.ConnectionId.Should().BeSameAs(connectionId2); }
public override bool Equals(object obj) { var clusterToMassTagMap = (ClusterToMassTagMap)obj; if (clusterToMassTagMap == null) { return(false); } if (!ClusterId.Equals(clusterToMassTagMap.ClusterId)) { return(false); } return(MassTagId.Equals(clusterToMassTagMap.MassTagId)); }
// static constructor static ServerDescriptionTests() { __clusterId = new ClusterId(); __endPoint = new DnsEndPoint("localhost", 27017); __serverId = new ServerId(__clusterId, __endPoint); __subject = new ServerDescription( __serverId, __endPoint, state: ServerState.Connected, type: ServerType.Standalone, averageRoundTripTime: TimeSpan.FromSeconds(1), version: new SemanticVersion(2, 6, 3), wireVersionRange: new Range<int>(0, 2)); }
private ServerId CreateSubject(string notEqualField = null) { var clusterId = new ClusterId(1); var endPoint = new DnsEndPoint("localhost", 27017); switch (notEqualField) { case "ClusterId": clusterId = new ClusterId(2); break; case "EndPoint": endPoint = new DnsEndPoint("localhost", 27018); break; } return(new ServerId(clusterId, endPoint)); }
// methods /// <inheritdoc/> public IClusterableServer CreateServer(ClusterId clusterId, IClusterClock clusterClock, EndPoint endPoint) { return(new Server( clusterId, clusterClock, _clusterConnectionMode, _connectionModeSwitch, _directConnection, _settings, endPoint, _connectionPoolFactory, _serverMonitorFactory, _eventSubscriber)); }
public void Setup() { var clusterId = new ClusterId(); _description = new ClusterDescription( clusterId, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), averageRoundTripTime: TimeSpan.FromMilliseconds(10)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), averageRoundTripTime: TimeSpan.FromMilliseconds(30)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), averageRoundTripTime: TimeSpan.FromMilliseconds(20)) }); }
public LatencyLimitingServerSelectorTests() { var clusterId = new ClusterId(); _description = new ClusterDescription( clusterId, ClusterConnectionMode.Automatic, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), averageRoundTripTime: TimeSpan.FromMilliseconds(10)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), averageRoundTripTime: TimeSpan.FromMilliseconds(30)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), averageRoundTripTime: TimeSpan.FromMilliseconds(20)) }); }
public IClusterableServer CreateServer(ClusterId clusterId, EndPoint endPoint) { IClusterableServer result; if(!_servers.TryGetValue(endPoint, out result)) { var description = new ServerDescription(new ServerId(clusterId, endPoint), endPoint); _servers[endPoint] = result = Substitute.For<IClusterableServer>(); result.Description.Returns(description); result.EndPoint.Returns(endPoint); result.ServerId.Returns(new ServerId(clusterId, endPoint)); } return result; }
public static Exception CreateException(Type exceptionType) { switch (exceptionType.Name) { case "IOException": return(new IOException("Fake IOException.")); case "MongoConnectionException": { var clusterId = new ClusterId(1); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 27017)); var connectionId = new ConnectionId(serverId, 1); var message = "Fake MongoConnectionException"; var innerException = new Exception(); return(new MongoConnectionException(connectionId, message, innerException)); } case "MongoCursorNotFoundException": { var clusterId = new ClusterId(1); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 27017)); var connectionId = new ConnectionId(serverId, 1); var cursorId = 1L; var query = new BsonDocument(); return(new MongoCursorNotFoundException(connectionId, cursorId, query)); } case "MongoNodeIsRecoveringException": { var clusterId = new ClusterId(1); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 27017)); var connectionId = new ConnectionId(serverId, 1); var result = new BsonDocument(); return(new MongoNodeIsRecoveringException(connectionId, result)); } case "MongoNotPrimaryException": { var clusterId = new ClusterId(1); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 27017)); var connectionId = new ConnectionId(serverId, 1); var result = new BsonDocument(); return(new MongoNotPrimaryException(connectionId, result)); } default: throw new ArgumentException($"Unexpected exception type: {exceptionType.Name}.", nameof(exceptionType)); } }
public EndPointServerSelectorTests() { var clusterId = new ClusterId(); _description = new ClusterDescription( clusterId, ClusterConnectionMode.Automatic, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019)), }); }
private ConnectionDescription CreateConnectionDescriptionSupportingSession(int maxWireVersion = WireVersion.Server36) { var clusterId = new ClusterId(1); var endPoint = new DnsEndPoint("localhost", 27017); var serverId = new ServerId(clusterId, endPoint); var connectionId = new ConnectionId(serverId, 1); var helloDocument = new BsonDocument { { "logicalSessionTimeoutMinutes", 30 }, { "maxWireVersion", maxWireVersion } }; var helloResult = new HelloResult(helloDocument); return(new ConnectionDescription(connectionId, helloResult)); }
public LatencyLimitingServerSelectorTests() { var clusterId = new ClusterId(); _description = new ClusterDescription( clusterId, ClusterConnectionMode.Automatic, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), averageRoundTripTime: TimeSpan.FromMilliseconds(10)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), averageRoundTripTime: TimeSpan.FromMilliseconds(30)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), averageRoundTripTime: TimeSpan.FromMilliseconds(20)) }); }
public static ConnectionDescription CreateConnectionDescription(SemanticVersion version = null, ServerType serverType = ServerType.Standalone, bool supportsSessions = true) { if (version == null) { version = new SemanticVersion(3, 6, 0); } var clusterId = new ClusterId(); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 27017)); var connectionId = new ConnectionId(serverId); var buildInfoResult = new BuildInfoResult(new BsonDocument("ok", 1).Add("version", version.ToString())); var isMasterResult = CreateIsMasterResult(version, serverType, supportsSessions); return(new ConnectionDescription(connectionId, isMasterResult, buildInfoResult)); }
public void WithConnectionId_should_return_new_instance_even_when_only_the_serverValue_differs() { var clusterId = new ClusterId(); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 1)); var connectionId1 = new ConnectionId(serverId, 1); var connectionId2 = new ConnectionId(serverId, 1).WithServerValue(2); var isMasterResult = new IsMasterResult(new BsonDocument()); var buildInfoResult = new BuildInfoResult(new BsonDocument("version", "2.6.0")); var subject = new ConnectionDescription(connectionId1, isMasterResult, buildInfoResult); var result = subject.WithConnectionId(connectionId2); result.Should().NotBeSameAs(subject); result.ConnectionId.Should().BeSameAs(connectionId2); }
private ICluster CreateMockReplicaSetCluster() { var clusterId = new ClusterId(1); var endPoint = new DnsEndPoint("localhost", 27017); var serverId = new ServerId(clusterId, endPoint); var maxWireVersion = Feature.Transactions.FirstSupportedWireVersion; var servers = new[] { new ServerDescription(serverId, endPoint, state: ServerState.Connected, type: ServerType.ReplicaSetPrimary, version: WireVersion.ToServerVersion(maxWireVersion), wireVersionRange: new Range <int>(0, maxWireVersion)) }; #pragma warning disable CS0618 // Type or member is obsolete var clusterDescription = new ClusterDescription(clusterId, ClusterConnectionMode.Automatic, ClusterType.ReplicaSet, servers); #pragma warning restore CS0618 // Type or member is obsolete var mockCluster = new Mock <ICluster>(); mockCluster.SetupGet(m => m.Description).Returns(clusterDescription); return(mockCluster.Object); }
public IClusterableServer CreateServer(ClusterId clusterId, EndPoint endPoint) { IClusterableServer result; if (!_servers.TryGetValue(endPoint, out result)) { var description = new ServerDescription(new ServerId(clusterId, endPoint), endPoint); _servers[endPoint] = result = Substitute.For <IClusterableServer>(); result.Description.Returns(description); result.EndPoint.Returns(endPoint); result.ServerId.Returns(new ServerId(clusterId, endPoint)); } return(result); }
// constructors public ClusterableServer(ClusterId clusterId, ClusterConnectionMode clusterConnectionMode, ServerSettings settings, EndPoint endPoint, IConnectionPoolFactory connectionPoolFactory, IConnectionFactory heartbeatConnectionFactory, IServerListener listener) { Ensure.IsNotNull(clusterId, "clusterId"); _clusterConnectionMode = clusterConnectionMode; _settings = Ensure.IsNotNull(settings, "settings");; _endPoint = Ensure.IsNotNull(endPoint, "endPoint"); Ensure.IsNotNull(connectionPoolFactory, "connectionPoolFactory"); _heartbeatConnectionFactory = Ensure.IsNotNull(heartbeatConnectionFactory, "heartbeatConnectionFactory"); _listener = listener; _serverId = new ServerId(clusterId, endPoint); _baseDescription = _currentDescription = new ServerDescription(_serverId, endPoint); _connectionPool = connectionPoolFactory.CreateConnectionPool(_serverId, endPoint); _state = new InterlockedInt32(State.Initial); }
// private methods private ClusterDescription CreateClusterDescription( ClusterId clusterId = null, #pragma warning disable CS0618 // Type or member is obsolete ClusterConnectionMode connectionMode = ClusterConnectionMode.Automatic, #pragma warning restore CS0618 // Type or member is obsolete ClusterType type = ClusterType.Unknown, IEnumerable <ServerDescription> servers = null) { clusterId = clusterId ?? new ClusterId(1); servers = servers ?? new ServerDescription[0]; #pragma warning disable CS0618 // Type or member is obsolete return(new ClusterDescription(clusterId, connectionMode, type, servers)); #pragma warning restore CS0618 // Type or member is obsolete }
public ReadPreferenceServerSelectorTests() { var clusterId = new ClusterId(); _primary = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), ServerType.ReplicaSetPrimary, new TagSet(new[] { new Tag("a", "1") })); _secondary1 = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), ServerType.ReplicaSetSecondary, new TagSet(new[] { new Tag("a", "1") })); _secondary2 = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), ServerType.ReplicaSetSecondary, new TagSet(new[] { new Tag("a", "2") })); #pragma warning disable CS0618 // Type or member is obsolete _description = new ClusterDescription( clusterId, ClusterConnectionMode.ReplicaSet, ClusterType.ReplicaSet, new[] { _primary, _secondary1, _secondary2 }); #pragma warning restore CS0618 // Type or member is obsolete }
public ServerFactoryTests() { _clusterId = new ClusterId(); _clusterConnectionMode = ClusterConnectionMode.Standalone; _connectionPoolFactory = new Mock <IConnectionPoolFactory>().Object; _endPoint = new DnsEndPoint("localhost", 27017); var mockServerMonitor = new Mock <IServerMonitor>(); mockServerMonitor.Setup(m => m.Description).Returns(new ServerDescription(new ServerId(_clusterId, _endPoint), _endPoint)); var mockServerMonitorFactory = new Mock <IServerMonitorFactory>(); mockServerMonitorFactory.Setup(f => f.Create(It.IsAny <ServerId>(), _endPoint)).Returns(mockServerMonitor.Object); _serverMonitorFactory = mockServerMonitorFactory.Object; _eventSubscriber = new Mock <IEventSubscriber>().Object; _settings = new ServerSettings(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldMarshalNullClusterId() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldMarshalNullClusterId() { // given MemoryStream outputStream = new MemoryStream(); // when OutputStreamWritableChannel writableChannel = new OutputStreamWritableChannel(outputStream); _marshal.marshal(null, writableChannel); InputStreamReadableChannel readableChannel = new InputStreamReadableChannel(new MemoryStream(outputStream.toByteArray())); ClusterId result = _marshal.unmarshal(readableChannel); // then assertNull(result); }
// static constructor static ServerDescriptionTests() { __clusterId = new ClusterId(); __endPoint = new DnsEndPoint("localhost", 27017); __serverId = new ServerId(__clusterId, __endPoint); __subject = new ServerDescription( __serverId, __endPoint, ServerState.Connected, ServerType.Standalone, TimeSpan.FromSeconds(1), null, null, new SemanticVersion(2, 6, 3), new Range<int>(0, 2)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public synchronized void encode(io.netty.channel.ChannelHandlerContext ctx, org.neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage decoratedMessage, io.netty.buffer.ByteBuf out) throws Exception public override void Encode(ChannelHandlerContext ctx, Org.Neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage decoratedMessage, ByteBuf @out) { lock (this) { Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage message = decoratedMessage.message(); ClusterId clusterId = decoratedMessage.clusterId(); MemberId.Marshal memberMarshal = new MemberId.Marshal(); NetworkWritableChannel channel = new NetworkWritableChannel(@out); ClusterId.Marshal.INSTANCE.marshal(clusterId, channel); channel.PutInt(message.Type().ordinal()); memberMarshal.MarshalConflict(message.From(), channel); message.Dispatch(new Handler(_marshal, memberMarshal, channel)); } }
public MongoIncompatibleDriverExceptionTests() { var clusterId = new ClusterId(1); #pragma warning disable CS0618 // Type or member is obsolete var connectionMode = ClusterConnectionMode.Standalone; #pragma warning restore CS0618 // Type or member is obsolete var clusterType = ClusterType.Standalone; var endPoint = new DnsEndPoint("localhost", 27017); var serverId = new ServerId(clusterId, endPoint); var server = new ServerDescription(serverId, endPoint, wireVersionRange: new Range <int>(0, 0), type: ServerType.Standalone); var servers = new[] { server }; #pragma warning disable CS0618 // Type or member is obsolete _clusterDescription = new ClusterDescription(clusterId, connectionMode, clusterType, servers); #pragma warning restore CS0618 // Type or member is obsolete }
// static constructor static ServerDescriptionTests() { __clusterId = new ClusterId(); __endPoint = new DnsEndPoint("localhost", 27017); __serverId = new ServerId(__clusterId, __endPoint); __subject = new ServerDescription( __serverId, __endPoint, ServerState.Connected, ServerType.Standalone, TimeSpan.FromSeconds(1), null, null, new SemanticVersion(2, 6, 3), new Range <int>(0, 2)); }
public CompositeServerSelectorTests() { var clusterId = new ClusterId(); #pragma warning disable CS0618 // Type or member is obsolete _description = new ClusterDescription( clusterId, ClusterConnectionMode.Automatic, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019)), }); #pragma warning restore CS0618 // Type or member is obsolete }
public static ServerDescription Parse(BsonDocument args) { var clusterId = new ClusterId(args.GetValue("clusterId", 1).ToInt32()); var endPoint = ParseEndPoint(args.GetValue("endPoint", "localhost:27017").AsString); var serverId = new ServerId(clusterId, endPoint); var logicalSessionTimeoutMinutes = args.GetValue("logicalSessionTimeoutMinutes", BsonNull.Value); var logicalSessionTimeout = logicalSessionTimeoutMinutes.IsBsonNull ? (TimeSpan?)null : TimeSpan.FromMinutes(logicalSessionTimeoutMinutes.ToInt32()); var state = (ServerState)Enum.Parse(typeof(ServerState), args["state"].AsString); var serverType = (ServerType)Enum.Parse(typeof(ServerType), args["type"].AsString); return(new ServerDescription( serverId, endPoint, logicalSessionTimeout: logicalSessionTimeout, state: state, type: serverType)); }
public void Should_select_nothing_when_attempting_to_match_tags_and_servers_do_not_have_tags() { var clusterId = new ClusterId(); var primary = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), ServerType.ReplicaSetPrimary); var secondary = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), ServerType.ReplicaSetSecondary); var description = new ClusterDescription( clusterId, ClusterType.ReplicaSet, new[] { primary, secondary }); var subject = new ReadPreferenceServerSelector(new ReadPreference(ReadPreferenceMode.Secondary, new[] { new TagSet(new[] { new Tag("a", "1") }) })); var result = subject.SelectServers(description, description.Servers).ToList(); result.Should().BeEmpty(); }
public void ReadPreference_should_be_ignored_when_directly_connected_with_a_server() { var subject = new ReadPreferenceServerSelector(new ReadPreference(ReadPreferenceMode.Primary)); var clusterId = new ClusterId(); var server = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), ServerType.ReplicaSetSecondary); var description = new ClusterDescription( clusterId, ClusterConnectionMode.Direct, ClusterType.ReplicaSet, new[] { server }); var result = subject.SelectServers(description, description.Servers).ToList(); result.Should().BeEquivalentTo(new[] { server }); }
public static MongoCommandException CreateMongoWriteConcernException(BsonDocument writeConcernResultDocument, string label = null) { var clusterId = new ClusterId(1); var endPoint = new DnsEndPoint("localhost", 27017); var serverId = new ServerId(clusterId, endPoint); var connectionId = new ConnectionId(serverId); var message = "Fake MongoWriteConcernException"; var writeConcernResult = new WriteConcernResult(writeConcernResultDocument); var writeConcernException = new MongoWriteConcernException(connectionId, message, writeConcernResult); if (label != null) { writeConcernException.AddErrorLabel(label); } return(writeConcernException); }
internal void ShouldInvalidateServer_should_return_expected_result_for_exceptionType(string exceptionTypeName, bool expectedResult) { _subject.Initialize(); Exception exception; var clusterId = new ClusterId(1); var serverId = new ServerId(clusterId, new DnsEndPoint("localhost", 27017)); var connectionId = new ConnectionId(serverId); var command = new BsonDocument("command", 1); var notWritablePrimaryResult = new BsonDocument { { "code", ServerErrorCode.NotWritablePrimary } }; var nodeIsRecoveringResult = new BsonDocument("code", ServerErrorCode.InterruptedAtShutdown); switch (exceptionTypeName) { case nameof(EndOfStreamException): exception = new EndOfStreamException(); break; case nameof(Exception): exception = new Exception(); break; case nameof(IOException): exception = new IOException(); break; case nameof(MongoConnectionException): exception = new MongoConnectionException(connectionId, "message"); break; case nameof(MongoNodeIsRecoveringException): exception = new MongoNodeIsRecoveringException(connectionId, command, notWritablePrimaryResult); break; case nameof(MongoNotPrimaryException): exception = new MongoNotPrimaryException(connectionId, command, nodeIsRecoveringResult); break; case nameof(SocketException): exception = new SocketException(); break; case "MongoConnectionExceptionWithSocketTimeout": var innermostException = new SocketException((int)SocketError.TimedOut); var innerException = new IOException("Execute Order 66", innermostException); exception = new MongoConnectionException(connectionId, "Yes, Lord Sidious", innerException); break; case nameof(TimeoutException): exception = new TimeoutException(); break; case nameof(MongoExecutionTimeoutException): exception = new MongoExecutionTimeoutException(connectionId, "message"); break; default: throw new Exception($"Invalid exceptionTypeName: {exceptionTypeName}."); } var result = _subject.ShouldInvalidateServer(Mock.Of <IConnection>(), exception, new ServerDescription(_subject.ServerId, _subject.EndPoint), out _); result.Should().Be(expectedResult); }
public DelegateServerSelectorTests() { var clusterId = new ClusterId(); #pragma warning disable CS0618 // Type or member is obsolete _description = new ClusterDescription( clusterId, ClusterConnectionMode.Automatic, ClusterType.Unknown, new[] { ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), averageRoundTripTime: TimeSpan.FromMilliseconds(10)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), averageRoundTripTime: TimeSpan.FromMilliseconds(30)), ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), averageRoundTripTime: TimeSpan.FromMilliseconds(20)) }); #pragma warning restore CS0618 // Type or member is obsolete }
internal static CoreTopology FakeCoreTopology(params MemberId[] memberIds) { Debug.Assert(memberIds.Length > 0); ClusterId clusterId = new ClusterId(System.Guid.randomUUID()); IDictionary <MemberId, CoreServerInfo> coreMembers = new Dictionary <MemberId, CoreServerInfo>(); int offset = 0; foreach (MemberId memberId in memberIds) { coreMembers[memberId] = TestTopology.addressesForCore(offset, false); offset++; } return(new CoreTopology(clusterId, false, coreMembers)); }
// constructors protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IEventSubscriber eventSubscriber) { _settings = Ensure.IsNotNull(settings, "settings"); _serverFactory = Ensure.IsNotNull(serverFactory, "serverFactory"); Ensure.IsNotNull(eventSubscriber, "eventSubscriber"); _state = new InterlockedInt32(State.Initial); _clusterId = new ClusterId(); _description = ClusterDescription.CreateInitial(_clusterId, _settings.ConnectionMode); _descriptionChangedTaskCompletionSource = new TaskCompletionSource<bool>(); _rapidHeartbeatTimer = new Timer(RapidHeartbeatTimerCallback, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); eventSubscriber.TryGetEventHandler(out _descriptionChangedEventHandler); eventSubscriber.TryGetEventHandler(out _selectingServerEventHandler); eventSubscriber.TryGetEventHandler(out _selectedServerEventHandler); eventSubscriber.TryGetEventHandler(out _selectingServerFailedEventHandler); }
public IClusterableServer CreateServer(ClusterId clusterId, EndPoint endPoint) { ServerTuple result; if (!_servers.TryGetValue(endPoint, out result)) { var description = new ServerDescription(new ServerId(clusterId, endPoint), endPoint); if (_eventSubscriber == null) { var server = Substitute.For<IClusterableServer>(); server.Description.Returns(description); server.EndPoint.Returns(endPoint); server.ServerId.Returns(new ServerId(clusterId, endPoint)); result = new ServerTuple { Server = server }; } else { var monitorFactory = Substitute.For<IServerMonitorFactory>(); var monitor = Substitute.For<IServerMonitor>(); monitorFactory.Create(null, null).ReturnsForAnyArgs(monitor); monitor.Description.Returns(description); result = new ServerTuple { Server = new Server( clusterId, ClusterConnectionMode.Automatic, new ServerSettings(), endPoint, Substitute.For<IConnectionPoolFactory>(), monitorFactory, _eventSubscriber), Monitor = monitor }; } _servers[endPoint] = result; } return result.Server; }
public IClusterableServer CreateServer(ClusterId clusterId, EndPoint endPoint) { ServerTuple result; if (!_servers.TryGetValue(endPoint, out result)) { var description = new ServerDescription(new ServerId(clusterId, endPoint), endPoint); if (_eventSubscriber == null) { var mockServer = new Mock<IClusterableServer>() { DefaultValue = DefaultValue.Mock }; mockServer.SetupGet(s => s.Description).Returns(description); mockServer.SetupGet(s => s.EndPoint).Returns(endPoint); mockServer.SetupGet(s => s.ServerId).Returns(new ServerId(clusterId, endPoint)); result = new ServerTuple { Server = mockServer.Object }; } else { var mockMonitorFactory = new Mock<IServerMonitorFactory>(); var mockMonitor = new Mock<IServerMonitor>() { DefaultValue = DefaultValue.Mock }; mockMonitorFactory.Setup(f => f.Create(It.IsAny<ServerId>(), It.IsAny<EndPoint>())).Returns(mockMonitor.Object); mockMonitor.SetupGet(m => m.Description).Returns(description); result = new ServerTuple { Server = new Server( clusterId, ClusterConnectionMode.Automatic, new ServerSettings(), endPoint, (new Mock<IConnectionPoolFactory> { DefaultValue = DefaultValue.Mock }).Object, mockMonitorFactory.Object, _eventSubscriber), Monitor = mockMonitor.Object }; } _servers[endPoint] = result; } return result.Server; }
public void Setup() { _clusterId = new ClusterId(); _clusterConnectionMode = ClusterConnectionMode.Standalone; _connectionPool = Substitute.For<IConnectionPool>(); _connectionPoolFactory = Substitute.For<IConnectionPoolFactory>(); _connectionPoolFactory.CreateConnectionPool(null, null) .ReturnsForAnyArgs(_connectionPool); _endPoint = new DnsEndPoint("localhost", 27017); _heartbeatConnection = new MockConnection(); _heartbeatConnectionFactory = Substitute.For<IConnectionFactory>(); _heartbeatConnectionFactory.CreateConnection(null, null) .ReturnsForAnyArgs(_heartbeatConnection); _capturedEvents = new EventCapturer(); _settings = new ServerSettings(heartbeatInterval: Timeout.InfiniteTimeSpan); _subject = new ClusterableServer(_clusterId, _clusterConnectionMode, _settings, _endPoint, _connectionPoolFactory, _heartbeatConnectionFactory, _capturedEvents); }
public ServerTests() { _clusterId = new ClusterId(); _endPoint = new DnsEndPoint("localhost", 27017); _clusterConnectionMode = ClusterConnectionMode.Standalone; _mockConnectionPool = new Mock<IConnectionPool>(); _mockConnectionPool.Setup(p => p.AcquireConnection(It.IsAny<CancellationToken>())).Returns(new Mock<IConnectionHandle>().Object); _mockConnectionPool.Setup(p => p.AcquireConnectionAsync(It.IsAny<CancellationToken>())).Returns(Task.FromResult(new Mock<IConnectionHandle>().Object)); _mockConnectionPoolFactory = new Mock<IConnectionPoolFactory>(); _mockConnectionPoolFactory .Setup(f => f.CreateConnectionPool(It.IsAny<ServerId>(), _endPoint)) .Returns(_mockConnectionPool.Object); _mockServerMonitor = new Mock<IServerMonitor>(); _mockServerMonitorFactory = new Mock<IServerMonitorFactory>(); _mockServerMonitorFactory.Setup(f => f.Create(It.IsAny<ServerId>(), _endPoint)).Returns(_mockServerMonitor.Object); _capturedEvents = new EventCapturer(); _settings = new ServerSettings(heartbeatInterval: Timeout.InfiniteTimeSpan); _subject = new Server(_clusterId, _clusterConnectionMode, _settings, _endPoint, _mockConnectionPoolFactory.Object, _mockServerMonitorFactory.Object, _capturedEvents); }
public void Setup() { _clusterId = new ClusterId(); _connectionPoolFactory = Substitute.For<IConnectionPoolFactory>(); _endPoint = new DnsEndPoint("localhost", 27017); _heartbeatConnectionFactory = Substitute.For<IConnectionFactory>(); _listener = Substitute.For<IServerListener>(); _settings = new ServerSettings(); }
private ClusterDescription CreateSubject(string notEqualField = null) { var clusterId = new ClusterId(1); var connectionMode = ClusterConnectionMode.ReplicaSet; var type = ClusterType.ReplicaSet; var servers = new[] { __serverDescription1, __serverDescription2 }; switch (notEqualField) { case "ClusterId": clusterId = new ClusterId(2); break; case "ConnectionMode": connectionMode = ClusterConnectionMode.Standalone; break; case "Type": type = ClusterType.Unknown; break; case "Servers": servers = new[] { __serverDescription1 }; break; } return new ClusterDescription(clusterId, connectionMode, type, servers); }
public static ServerDescription Disconnected(ClusterId clusterId, EndPoint endPoint = null) { endPoint = endPoint ?? new DnsEndPoint("localhost", 27017); return new ServerDescription(new ServerId(clusterId, endPoint), endPoint); }
/// <summary> /// Initializes a new instance of the <see cref="ClusterOpenedEvent"/> struct. /// </summary> /// <param name="clusterId">The cluster identifier.</param> /// <param name="clusterSettings">The cluster settings.</param> /// <param name="duration">The duration of time it took to open the cluster.</param> public ClusterOpenedEvent(ClusterId clusterId, ClusterSettings clusterSettings, TimeSpan duration) { _clusterId = clusterId; _clusterSettings = clusterSettings; _duration = duration; }