Example #1
0
        public void LogReceiveMessageAck(MessageExecutionCompleted messageAck)
        {
            if (!TryGetLogHelperForDebug(messageAck, out _))
            {
                return;
            }

            _logger.Debug($"RECV ACK {{{messageAck}}}");
        }
        public void shoud_send_a_completion_message_with_error_code_on_exception()
        {
            using (MessageId.PauseIdGeneration())
            {
                var command = new FakeCommand(123);
                SetupDispatch(command, error: new Exception());
                var transportMessageReceived = command.ToTransportMessage(_peerUp);

                _transport.RaiseMessageReceived(transportMessageReceived);

                var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, 1, null).ToTransportMessage(_self);
                _transport.Expect(new TransportMessageSent(expectedTransportMessage, _peerUp));
            }
        }
        public void shoud_send_a_completion_message_without_error_code()
        {
            using (MessageId.PauseIdGeneration())
            {
                var command = new FakeCommand(123);
                SetupDispatch(command);

                var transportMessageReceived = command.ToTransportMessage(_peerUp);
                _transport.RaiseMessageReceived(transportMessageReceived);

                var messageExecutionCompleted = new MessageExecutionCompleted(transportMessageReceived.Id, 0, null).ToTransportMessage(_self);
                _transport.ExpectExactly(new TransportMessageSent(messageExecutionCompleted, _peerUp));
            }
        }
        public void shoud_send_a_completion_message_with_domain_exception_error_code()
        {
            using (MessageId.PauseIdGeneration())
            {
                const int domainExceptionValue = 5000;
                var command = new FakeCommand(123);
                SetupDispatch(command, error: new DomainException(domainExceptionValue, "Domain Exception"));
                var transportMessageReceived = command.ToTransportMessage(_peerUp);

                _transport.RaiseMessageReceived(transportMessageReceived);

                var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, domainExceptionValue).ToTransportMessage(_self);
                _transport.ExpectExactly(new TransportMessageSent(expectedTransportMessage, _peerUp));
            }
        }
Example #5
0
        private Action <MessageDispatch, DispatchResult> GetOnRemoteMessageDispatchedContinuation(TransportMessage transportMessage)
        {
            return((dispatch, dispatchResult) =>
            {
                HandleDispatchErrors(dispatch, dispatchResult, transportMessage);

                if (dispatch.Message is ICommand && !(dispatch.Message is PersistMessageCommand))
                {
                    var messageExecutionCompleted = MessageExecutionCompleted.Create(dispatch.Context, dispatchResult, _serializer);
                    var shouldLogMessageExecutionCompleted = _messageLogger.IsInfoEnabled(dispatch.Message);
                    SendTransportMessage(null, messageExecutionCompleted, dispatch.Context.GetSender(), shouldLogMessageExecutionCompleted);
                }

                AckTransportMessage(transportMessage);
            });
        }
Example #6
0
        public void handlers_reply_with_an_int()
        {
            using (MessageId.PauseIdGeneration())
            {
                const int commandReply = 456;
                var command = new FakeCommand(123);
                SetupDispatch(command, _ => _bus.Reply(commandReply));

                var transportMessageReceived = command.ToTransportMessage(_peerUp);
                var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, commandReply, null).ToTransportMessage(_self);

                _transport.RaiseMessageReceived(transportMessageReceived);

                var sentMessage = _transport.Messages.Single();
                expectedTransportMessage.ShouldHaveSamePropertiesAs(sentMessage.TransportMessage);
                var destination = sentMessage.Targets.Single();
                destination.ShouldHaveSamePropertiesAs(_peerUp);
            }
        }
Example #7
0
        protected virtual void HandleMessageExecutionCompleted(TransportMessage transportMessage, MessageExecutionCompleted message)
        {
            _messageLogger.DebugFormat("RECV: {0}", message);

            TaskCompletionSource <CommandResult> taskCompletionSource;

            if (!_messageIdToTaskCompletionSources.TryRemove(message.SourceCommandId, out taskCompletionSource))
            {
                return;
            }

            var response = message.PayloadTypeId != null?ToMessage(message.PayloadTypeId.Value, new MemoryStream(message.Payload), transportMessage) : null;

            var commandResult = new CommandResult(message.ErrorCode, message.ResponseMessage, response);

            Task.Run(() => taskCompletionSource.SetResult(commandResult));
        }
        public void should_release_task_when_completion_message_is_sent()
        {
            using (MessageId.PauseIdGeneration())
            {
                var command = new FakeCommand(123);
                SetupPeersHandlingMessage<FakeCommand>(_peerUp);
                _bus.Start();

                var task = _bus.Send(command);
                var commandCompleted = new MessageExecutionCompleted(MessageId.NextId(), 1, "Error message");
                _transport.RaiseMessageReceived(commandCompleted.ToTransportMessage());

                var receivedAck = task.Wait(10);

                receivedAck.ShouldBeTrue();
                task.Result.ErrorCode.ShouldEqual(1);
                task.Result.ResponseMessage.ShouldEqual("Error message");
            }
        }
        public void should_not_continue_execution_after_awaiting_a_send_in_the_MessageReceived_thread()
        {
            using (MessageId.PauseIdGeneration())
            {
                var command = new FakeCommand(456);
                SetupPeersHandlingMessage<FakeCommand>(_peerUp);
                _bus.Start();

                var task = _bus.Send(command);
                var commandCompleted = new MessageExecutionCompleted(MessageId.NextId(), 0, null);
                int backgroundThreadId = 0;

                BackgroundThread.Start(() =>
                    {
                        backgroundThreadId = Thread.CurrentThread.ManagedThreadId;
                        _transport.RaiseMessageReceived(commandCompleted.ToTransportMessage());
                    });

                var getThreadIdTask = GetThreadIfAfterAwaitingCommandResult(task);

                getThreadIdTask.Result.ShouldNotEqual(backgroundThreadId);
            }
        }
Example #10
0
File: Bus.cs Project: Bourl/Zebus
        protected virtual void HandleMessageExecutionCompleted(TransportMessage transportMessage, MessageExecutionCompleted message)
        {
            _messageLogger.DebugFormat("RECV: {0}", message);

            TaskCompletionSource <CommandResult> taskCompletionSource;

            if (!_messageIdToTaskCompletionSources.TryRemove(message.SourceCommandId, out taskCompletionSource))
            {
                return;
            }

            var response = message.PayloadTypeId != null?ToMessage(message.PayloadTypeId, message.Payload, transportMessage) : null;

            var commandResult = new CommandResult(message.ErrorCode, response);

            var task = new Task(() => taskCompletionSource.SetResult(commandResult));

            task.Start(_completionResultTaskScheduler);
        }
Example #11
0
        public void should_handle_execution_completion_received()
        {
            var messageExecutionCompletedTransportMessage = new MessageExecutionCompleted(MessageId.NextId(), 0).ToTransportMessage();

            InnerTransport.RaiseMessageReceived(messageExecutionCompletedTransportMessage);

            var forwardedMessage = MessagesForwardedToBus.Single(x => x.MessageTypeId == MessageExecutionCompleted.TypeId);
            forwardedMessage.ShouldEqualDeeply(messageExecutionCompletedTransportMessage);
        }