private void HandleCommandExecutionFailure(CommandInvokedMessage msg, Exception e) { try { m_Diagnostics.Log( LevelToLog.Error, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Error while invoking command {0}. Exception is: {1}", msg.Invocation.Command, e)); m_SendMessage( msg.Sender, new FailureMessage(m_Current, msg.Id), CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending); } catch (Exception errorSendingException) { m_Diagnostics.Log( LevelToLog.Error, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Error while trying to send process failure. Exception is: {0}", errorSendingException)); } }
private SendCommandData CommandSendingFunctionFor(EndpointId endpoint) { SendCommandData func = (methodInvocation, retryCount, timeout) => { var msg = new CommandInvokedMessage(m_Local, methodInvocation); return(m_SendWithResponse(endpoint, msg, retryCount, timeout)); }; return(func); }
public void FromMessage() { 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 CommandInvocationConverter(serializers.Object); var id = CommandId.Create(typeof(int).GetMethod("CompareTo", new[] { typeof(object) })); var msg = new CommandInvokedMessage( new EndpointId("a"), new CommandInvokedData( id, new[] { new CommandParameterValueMap( new CommandParameterDefinition(typeof(object), "other", CommandParameterOrigin.FromCommand), 1), })); var data = translator.FromMessage(msg); Assert.IsInstanceOf(typeof(CommandInvocationData), data); Assert.AreSame(msg.Id, data.Id); Assert.AreSame(msg.Sender, data.Sender); Assert.AreSame(msg.InResponseTo, data.InResponseTo); Assert.AreEqual(CommandIdExtensions.Serialize(id), ((CommandInvocationData)data).CommandId); Assert.AreEqual(msg.Invocation.Parameters.Length, ((CommandInvocationData)data).ParameterTypes.Length); Assert.AreEqual( msg.Invocation.Parameters[0].Parameter.Type.FullName, ((CommandInvocationData)data).ParameterTypes[0].FullName); Assert.AreEqual( msg.Invocation.Parameters[0].Parameter.Type.Assembly.GetName().Name, ((CommandInvocationData)data).ParameterTypes[0].AssemblyName); Assert.AreEqual(msg.Invocation.Parameters.Length, ((CommandInvocationData)data).ParameterNames.Length); Assert.AreEqual( msg.Invocation.Parameters[0].Parameter.Name, ((CommandInvocationData)data).ParameterNames[0]); Assert.AreEqual(msg.Invocation.Parameters.Length, ((CommandInvocationData)data).ParameterValues.Length); Assert.AreEqual( msg.Invocation.Parameters[0].Value, ((CommandInvocationData)data).ParameterValues[0]); }
public void ProxyConnectingToMethodWithRetryCount() { var remoteEndpoint = new EndpointId("other"); var local = new EndpointId("local"); var retryCount = -1; var timeout = TimeSpan.MinValue; CommandInvokedMessage intermediateMsg = null; SendMessageAndWaitForResponse sender = (e, m, r, t) => { retryCount = r; timeout = t; intermediateMsg = m as CommandInvokedMessage; return(Task <ICommunicationMessage> .Factory.StartNew( () => new SuccessMessage(remoteEndpoint, new MessageId()), new CancellationToken(), TaskCreationOptions.None, new CurrentThreadTaskScheduler())); }; var configuration = new Mock <IConfiguration>(); { configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>())) .Returns(false); } var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var builder = new CommandProxyBuilder(local, sender, configuration.Object, systemDiagnostics); var proxy = builder.ProxyConnectingTo <InteractionExtensionsTest.IMockCommandSetWithTaskReturn>(remoteEndpoint); var result = proxy.MyRetryMethod(10); result.Wait(); Assert.IsTrue(result.IsCompleted); Assert.IsFalse(result.IsCanceled); Assert.IsFalse(result.IsFaulted); Assert.AreEqual( CommandId.Create(typeof(InteractionExtensionsTest.IMockCommandSetWithTaskReturn).GetMethod("MyRetryMethod")), intermediateMsg.Invocation.Command); Assert.AreEqual(0, intermediateMsg.Invocation.Parameters.Length); Assert.AreEqual(10, retryCount); Assert.AreEqual(TimeSpan.FromMilliseconds(CommunicationConstants.DefaultWaitForResponseTimeoutInMilliSeconds), timeout); }
public void ProxyConnectingToMethodWithTypedTaskReturnWithFailedExecution() { var remoteEndpoint = new EndpointId("other"); var local = new EndpointId("local"); CommandInvokedMessage intermediateMsg = null; SendMessageAndWaitForResponse sender = (e, m, r, t) => { intermediateMsg = m as CommandInvokedMessage; return(Task <ICommunicationMessage> .Factory.StartNew( () => new FailureMessage(remoteEndpoint, new MessageId()), new CancellationToken(), TaskCreationOptions.None, new CurrentThreadTaskScheduler())); }; var configuration = new Mock <IConfiguration>(); { configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>())) .Returns(false); } var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var builder = new CommandProxyBuilder(local, sender, configuration.Object, systemDiagnostics); var proxy = builder.ProxyConnectingTo <InteractionExtensionsTest.IMockCommandSetWithTypedTaskReturn>(remoteEndpoint); var result = proxy.MyMethod(10); Assert.Throws <AggregateException>(result.Wait); Assert.IsTrue(result.IsCompleted); Assert.IsFalse(result.IsCanceled); Assert.IsTrue(result.IsFaulted); Assert.IsAssignableFrom(typeof(CommandInvocationFailedException), result.Exception.InnerExceptions[0]); Assert.AreEqual( CommandId.Create(typeof(InteractionExtensionsTest.IMockCommandSetWithTypedTaskReturn).GetMethod("MyMethod")), intermediateMsg.Invocation.Command); Assert.AreEqual(1, intermediateMsg.Invocation.Parameters.Length); Assert.AreEqual(typeof(int), intermediateMsg.Invocation.Parameters[0].Parameter.Type); Assert.AreEqual("input", intermediateMsg.Invocation.Parameters[0].Parameter.Name); Assert.AreEqual(10, intermediateMsg.Invocation.Parameters[0].Value); }