예제 #1
0
        public void ActOnArrivalWithHandshakeMessage()
        {
            ICommunicationMessage storedMessage = null;
            var processAction = new Mock <IMessageProcessAction>();
            {
                processAction.Setup(p => p.Invoke(It.IsAny <ICommunicationMessage>()))
                .Callback <ICommunicationMessage>(m => { storedMessage = m; });
            }

            var store = new Mock <IStoreInformationAboutEndpoints>();
            {
                store.Setup(s => s.CanCommunicateWithEndpoint(It.IsAny <EndpointId>()))
                .Returns(false);
            }

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var handler           = new MessageHandler(store.Object, systemDiagnostics);

            handler.ActOnArrival(new MessageKindFilter(typeof(EndpointConnectMessage)), processAction.Object);

            var endpoint = new EndpointId("sendingEndpoint");
            var msg      = new EndpointConnectMessage(
                endpoint,
                new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")),
                new ProtocolInformation(
                    new Version(),
                    new Uri(@"net.pipe://localhost/test"),
                    new Uri(@"net.pipe://localhost/test/data")),
                new ProtocolDescription(new List <CommunicationSubject>()));

            handler.ProcessMessage(msg);

            Assert.AreSame(msg, storedMessage);
        }
예제 #2
0
        public void FromMessage()
        {
            var translator = new EndpointConnectConverter();

            var msg = new EndpointConnectMessage(
                new EndpointId("a"),
                new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")),
                new ProtocolInformation(
                    new Version(1, 0),
                    new Uri("http://localhost/protocol/invalid")),
                new ProtocolDescription(
                    new[]
            {
                new CommunicationSubject("b"),
            }));
            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(EndpointConnectData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreSame(msg.DiscoveryInformation.Address, ((EndpointConnectData)data).DiscoveryAddress);
            Assert.AreSame(msg.ProtocolInformation.Version, ((EndpointConnectData)data).ProtocolVersion);
            Assert.AreSame(msg.ProtocolInformation.MessageAddress, ((EndpointConnectData)data).MessageAddress);
            Assert.AreSame(msg.ProtocolInformation.DataAddress, ((EndpointConnectData)data).DataAddress);
            Assert.AreSame(msg.Information, ((EndpointConnectData)data).Information);
        }
예제 #3
0
        /// <summary>
        /// Initiates the handshake process between the current endpoint and the specified endpoint.
        /// </summary>
        /// <param name="information">The connection information for the endpoint.</param>
        private void InitiateHandshakeWith(EndpointInformation information)
        {
            var template       = information.ProtocolInformation.MessageAddress.ToChannelTemplate();
            var connectionInfo = m_Layer.LocalConnectionFor(information.ProtocolInformation.Version, template);

            if (connectionInfo != null)
            {
                lock (m_Lock)
                {
                    Debug.Assert(m_EndpointApprovalState.ContainsKey(information.Id), "The endpoint tick list is not stored.");
                    var tickList = m_EndpointApprovalState[information.Id];

                    if (!tickList.HaveSendConnect && !m_PotentialEndpoints.CanCommunicateWithEndpoint(information.Id))
                    {
                        tickList.HaveSendConnect = true;

                        var message = new EndpointConnectMessage(
                            m_Layer.Id,
                            new DiscoveryInformation(m_DiscoveryChannel.EntryChannel(template)),
                            new ProtocolInformation(
                                information.ProtocolInformation.Version,
                                connectionInfo.Item2,
                                connectionInfo.Item3),
                            m_Descriptions.ToStorage());
                        var task = m_Layer.SendMessageToUnregisteredEndpointAndWaitForResponse(
                            information,
                            message,
                            CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending,
                            m_SendTimeout);
                        task.ContinueWith(HandleResponseToConnectMessage, TaskContinuationOptions.ExecuteSynchronously);
                    }
                }
            }
        }
        public void Invoke()
        {
            EndpointInformation processedChannel     = null;
            ProtocolDescription processedDescription = null;
            MessageId           processedMessageId   = null;
            var sink = new Mock <IHandleProtocolHandshakes>();
            {
                sink.Setup(s => s.ContinueHandshakeWith(
                               It.IsAny <EndpointInformation>(),
                               It.IsAny <ProtocolDescription>(),
                               It.IsAny <MessageId>()))
                .Callback <EndpointInformation, ProtocolDescription, MessageId>((e, t, u) =>
                {
                    processedChannel     = e;
                    processedDescription = t;
                    processedMessageId   = u;
                });
            }

            var channelTypes = new[]
            {
                ChannelTemplate.TcpIP
            };
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var action = new EndpointConnectProcessAction(sink.Object, channelTypes, systemDiagnostics);

            var id        = new EndpointId("id");
            var discovery = new DiscoveryInformation(new Uri("http://localhost/discovery/invalid"));
            var protocol  = new ProtocolInformation(
                new Version(1, 0),
                new Uri("http://localhost/protocol/message/invalid"),
                new Uri("http://localhost/protocol/data/invalid"));
            var description = new ProtocolDescription(new List <CommunicationSubject>());
            var msg         = new EndpointConnectMessage(id, discovery, protocol, description);

            action.Invoke(msg);

            Assert.AreEqual(msg.Id, processedMessageId);
            Assert.AreEqual(id, processedChannel.Id);
            Assert.AreSame(discovery, processedChannel.DiscoveryInformation);
            Assert.AreSame(protocol, processedChannel.ProtocolInformation);
            Assert.AreSame(description, processedDescription);
        }
예제 #5
0
        public void ActOnArrivalWithLastChanceHandler()
        {
            var localEndpoint = new EndpointId("id");

            ICommunicationMessage storedMsg  = null;
            SendMessage           sendAction =
                (e, m, r) =>
            {
                storedMsg = m;
            };

            var store = new Mock <IStoreInformationAboutEndpoints>();
            {
                store.Setup(s => s.CanCommunicateWithEndpoint(It.IsAny <EndpointId>()))
                .Returns(false);
            }

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var processAction = new UnknownMessageTypeProcessAction(localEndpoint, sendAction, systemDiagnostics);
            var handler       = new MessageHandler(store.Object, systemDiagnostics);

            handler.ActOnArrival(new MessageKindFilter(processAction.MessageTypeToProcess), processAction);

            var endpoint = new EndpointId("sendingEndpoint");
            var msg      = new EndpointConnectMessage(
                endpoint,
                new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")),
                new ProtocolInformation(
                    new Version(),
                    new Uri(@"net.pipe://localhost/test"),
                    new Uri(@"net.pipe://localhost/test/data")),
                new ProtocolDescription(new List <CommunicationSubject>()));

            handler.ProcessMessage(msg);

            Assert.IsInstanceOf <FailureMessage>(storedMsg);
        }