public void should_send_MessageProcessingFailed_if_unable_to_deserialize_message() { SetupPeersHandlingMessage<MessageProcessingFailed>(_peerUp); _bus.Start(); var command = new FakeCommand(123); _messageSerializer.AddSerializationExceptionFor(command.TypeId(), "Serialization error"); using (SystemDateTime.PauseTime()) using (MessageId.PauseIdGeneration()) { var transportMessage = command.ToTransportMessage(); var messageProcessingFailedBytes = new MessageProcessingFailed(null, null, null, DateTime.UtcNow, null).ToTransportMessage().MessageBytes; _messageSerializer.AddSerializationFuncFor<MessageProcessingFailed>(x => { x.FailingMessage.ShouldEqual(transportMessage); x.ExceptionUtcTime.ShouldEqual(SystemDateTime.UtcNow); x.ExceptionMessage.ShouldContain("Unable to deserialize message"); return messageProcessingFailedBytes; }); _transport.RaiseMessageReceived(transportMessage); var processingFailedTransportMessage = new TransportMessage(MessageUtil.TypeId<MessageProcessingFailed>(), messageProcessingFailedBytes, _self); _transport.ExpectExactly(new TransportMessageSent(processingFailedTransportMessage, _peerUp)); } }
public void should_ack_transport_when_handling_undeserializable_message() { var command = new FakeCommand(123); _messageSerializer.AddSerializationExceptionFor(command.TypeId()); var transportMessage = command.ToTransportMessage(); _transport.RaiseMessageReceived(transportMessage); _transport.AckedMessages.ShouldContain(transportMessage); }
public void should_dispatch_received_message() { var command = new FakeCommand(123); var invokerCalled = false; SetupDispatch(command, _ => invokerCalled = true); var transportMessageReceived = command.ToTransportMessage(_peerUp); _transport.RaiseMessageReceived(transportMessageReceived); invokerCalled.ShouldBeTrue(); }
public void should_not_consider_if_peer_is_up_to_send_commands([Values(true, false)]bool isTargetPeerUp) { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(456); SetupPeersHandlingMessage<FakeCommand>(isTargetPeerUp ? _peerUp : _peerDown); _bus.Start(); _bus.Send(command); _transport.ExpectExactly(new TransportMessageSent(command.ToTransportMessage(_self), new[] { isTargetPeerUp ? _peerUp : _peerDown })); } }
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)); } }
public void should_send_message() { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(456); SetupPeersHandlingMessage<FakeCommand>(_peerUp); _bus.Start(); _bus.Send(command); var sentMessage = _transport.Messages.Single(); var expectedTransportMessage = command.ToTransportMessage(_self); sentMessage.TransportMessage.ShouldHaveSamePropertiesAs(expectedTransportMessage); var destination = sentMessage.Targets.Single(); destination.ShouldHaveSamePropertiesAs(_peerUp); } }
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); } }
public void should_not_handle_command_locally_when_local_dispatch_is_disabled() { var command = new FakeCommand(1); var handled = false; SetupDispatch(command, _ => handled = true); SetupPeersHandlingMessage<FakeCommand>(_self); _bus.Start(); using (LocalDispatch.Disable()) using (MessageId.PauseIdGeneration()) { var completed = _bus.Send(command).Wait(5); handled.ShouldBeFalse(); completed.ShouldBeFalse(); _transport.ExpectExactly(new TransportMessageSent(command.ToTransportMessage(_self), _self)); } }
public void should_send_a_MessageProcessingFailed_on_unknown_command_error() { SetupPeersHandlingMessage<MessageProcessingFailed>(_peerUp); using (SystemDateTime.PauseTime()) using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123); var commandJson = JsonConvert.SerializeObject(command); var exception = new Exception("Exception message"); SetupDispatch(command, error: exception); var transportMessageReceived = command.ToTransportMessage(_peerUp); _transport.RaiseMessageReceived(transportMessageReceived); var expectedTransportMessage = new MessageProcessingFailed(transportMessageReceived, commandJson, exception.ToString(), SystemDateTime.UtcNow, new [] { typeof(FakeMessageHandler).FullName }).ToTransportMessage(_self); _transport.Expect(new TransportMessageSent(expectedTransportMessage, _peerUp)); } }
public void handlers_reply_with_an_object() { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123); var commandResult = new FakeCommandResult("CommandResult", 45); var transportMessageReceived = command.ToTransportMessage(_peerUp); SetupDispatch(command, _ => _bus.Reply(commandResult)); var expectedExecutionCompleted = MessageExecutionCompleted.Success(transportMessageReceived.Id, commandResult, _messageSerializer); var expectedTransportMessage = expectedExecutionCompleted.ToTransportMessage(_self); _transport.RaiseMessageReceived(transportMessageReceived); var sentMessage = _transport.Messages.Single(); expectedTransportMessage.ShouldHaveSamePropertiesAs(sentMessage.TransportMessage); var destination = sentMessage.Targets.Single(); destination.ShouldHaveSamePropertiesAs(_peerUp); } }
public void should_not_send_acknowledgement_when_message_handled() { var command = new FakeCommand(123); var dispatch = _bus.CreateMessageDispatch(command.ToTransportMessage()); dispatch.SetHandlerCount(1); dispatch.SetHandled(null, null); _transport.ExpectNothing(); }
public void should_create_message_dispatch() { var command = new FakeCommand(123); var dispatch = _bus.CreateMessageDispatch(command.ToTransportMessage()); dispatch.Message.ShouldEqualDeeply(command); }
public void should_ack_transport_when_dispatch_done() { var command = new FakeCommand(123); SetupDispatch(command); SetupPeersHandlingMessage<FakeCommand>(_peerUp); _bus.Start(); var task = _bus.Send(command); var transportMessage = command.ToTransportMessage(); _transport.RaiseMessageReceived(transportMessage); task.Wait(10); _transport.AckedMessages.Count.ShouldEqual(1); _transport.AckedMessages[0].Id.ShouldEqual(transportMessage.Id); }
public void should_dump_incoming_message_if_unable_to_deserialize_it() { var command = new FakeCommand(123); _messageSerializer.AddSerializationExceptionFor(command.TypeId()); var transportMessage = command.ToTransportMessage(); _transport.RaiseMessageReceived(transportMessage); var dumpFileName = System.IO.Directory.GetFiles(_expectedDumpDirectory).ExpectedSingle(); dumpFileName.ShouldContain("Abc.Zebus.Tests.Messages.FakeCommand"); File.ReadAllBytes(dumpFileName).Length.ShouldEqual(2); }