Exemple #1
0
        public void Invoke()
        {
            var endpoint = new EndpointId("id");

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

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

            var data         = "a";
            var responseData = "b";
            KeepAliveResponseCustomDataBuilder customData =
                o =>
            {
                Assert.AreSame(data, o);
                return(responseData);
            };

            var action = new ConnectionVerificationProcessAction(endpoint, sendAction, systemDiagnostics, customData);

            var id  = new EndpointId("id");
            var msg = new ConnectionVerificationMessage(id, data);

            action.Invoke(msg);

            var responseMessage = storedMsg as ConnectionVerificationResponseMessage;

            Assert.IsNotNull(responseMessage);
            Assert.AreEqual(msg.Id, responseMessage.InResponseTo);
            Assert.AreSame(responseData, responseMessage.ResponseData);
        }
Exemple #2
0
        /// <summary>
        /// Verifies that the connection to the given endpoint can be used.
        /// </summary>
        /// <param name="id">The endpoint ID of the endpoint to which the connection should be verified.</param>
        /// <param name="timeout">The maximum amount of time the response operation is allowed to take.</param>
        /// <param name="verificationData">The data that should be send to the endpoint for verification of the connection.</param>
        /// <returns>
        /// A task that contains the response to the verification data value, or <see langword="null" /> if no
        /// verification data was provided.
        /// </returns>
        public Task <object> VerifyConnectionIsActive(EndpointId id, TimeSpan timeout, object verificationData = null)
        {
            var source   = new CancellationTokenSource();
            var msg      = new ConnectionVerificationMessage(Id, verificationData);
            var response = SendMessageAndWaitForResponse(
                id,
                msg,
                CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending,
                timeout);

            return(response.ContinueWith(
                       t =>
            {
                if (t.IsCanceled)
                {
                    source.Cancel();
                    source.Token.ThrowIfCancellationRequested();
                    return null;
                }

                if ((t.Exception != null) || t.IsFaulted)
                {
                    var exception = t.Exception;
                    throw new AggregateException(exception.InnerExceptions);
                }

                var responseMessage = t.Result as ConnectionVerificationResponseMessage;
                if (responseMessage == null)
                {
                    Debug.Assert(false, "The response message should be of type ConnectionVerificationResponseMessage.");
                    return null;
                }

                return responseMessage.ResponseData;
            },
                       source.Token,
                       TaskContinuationOptions.ExecuteSynchronously,
                       TaskScheduler.Current));
        }
        public void FromMessageWithNullCustomData()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            {
                serializers.Setup(s => s.HasSerializerFor(It.IsAny <Type>()))
                .Returns(true);
                serializers.Setup(s => s.SerializerFor(It.IsAny <Type>()))
                .Returns(new NonTransformingObjectSerializer());
            }

            var translator = new ConnectionVerificationConverter(serializers.Object);

            var msg  = new ConnectionVerificationMessage(new EndpointId("a"));
            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(ConnectionVerificationData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(typeof(object).FullName, ((ConnectionVerificationData)data).DataType.FullName);
            Assert.AreEqual(typeof(object).Assembly.GetName().Name, ((ConnectionVerificationData)data).DataType.AssemblyName);
            Assert.IsNull(((ConnectionVerificationData)data).CustomData);
        }