public void Sends_response_to_the_client_only() { Handle(); A.CallTo(() => sender.Send(A <IMessage> .Ignored, client.GetStream())) .MustHaveHappened(Repeated.Exactly.Once); }
public void Sends_the_nodes_using_batched_messages() { Handle(); A.CallTo(() => sender.Send((IReadOnlyList <IMessage>)null, null)) .WithAnyArguments().MustHaveHappened(Repeated.Exactly.Once); }
public void When_sending_single_message_The_message_gets_serialized() { var msg = A.Fake <IMessage>(); sender.Send(msg, stream); A.CallTo(() => serializer.Serialize(msg)).MustHaveHappened(); }
public void Handle(NodeRegistered notification) { //check if current node is primary CS if (notification.Message.Type == Constants.NodeTypes.CommunicationsServer && !communicationServerStorage.IsBackup) { logger.Info("New backup server has been registered, sending him all availble info."); using (var client = clientFactory()) { try { client.Connect(notification.MessageSource.Address, notification.MessageSource.Port); IEnumerable <IMessage> regMsgs = GetRegisterMessages(); IEnumerable <IMessage> problemMsgs = GetProblemMessages(); sender.Send(regMsgs.Concat(problemMsgs).ToList(), client.GetStream()); } catch (Exception ex) { logger.Error($"Newly registered node {notification.Message.Id} stopped responding, marking as dead", ex); mediator.Publish(new NodeDead(notification.Message.Id)); } } } }
public void Send(IMessage message) { var followingNodes = backupServers.GetFollowingNodes(); if (followingNodes.Count == 0) { logger.Debug($"There is no backup servers. Discarding message: {message}"); } else { foreach (var node in followingNodes) { logger.Debug($"Trying to send to {node.Address}:{node.Port}."); try { using (var client = clientFactory()) { client.Connect(node.Address, node.Port); sender.Send(message, client.GetStream()); } // We only want to send a message to the next alive backup server break; } catch (Exception ex) { logger.Error($"Cannot send message to {node.Address}:{node.Port}, assuming the backup CS is dead.", ex); mediator.Publish(new NodeDead(node.Id)); } } } }
public void Respond(IMessagesSender sender, IMessage response) { using (Client) { sender.Send(response, Client.GetStream()); } }
public void Sends_response_with_newly_generated_id_and_server_configuration() { Handle(); A.CallTo(() => sender.Send(A <RegisterResponse> .That.Matches(r => r.Id == NodeId && r.Timeout == Timeout ), client.GetStream()) ).MustHaveHappened(Repeated.Exactly.Once); }
private void TrySend(IMessage msg, INetworkStream stream) { try { sender.Send(new[] { msg }, stream); } catch (Exception ex) { logger.Error("Sending failed, re-throwing CannotSendMessageException.", ex); throw new CannotSendMessageException("Cannot send message to the server.", ex); } }
public void Correctly_sends_the_message() { sender.Send(message); var node = BackupNodes[0]; var order = A.SequentialCallContext(); A.CallTo(() => client.Connect(node.Address, node.Port)) .MustHaveHappened(Repeated.Exactly.Once).InOrder(order); A.CallTo(() => messagesSender.Send(message, client.GetStream())) .MustHaveHappened(Repeated.Exactly.Once).InOrder(order); A.CallTo(() => client.Dispose()) .MustHaveHappened(Repeated.Exactly.Once).InOrder(order); }